-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
259 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
server/src/main/java/wallpaper/video/action/ListAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package wallpaper.video.action; | ||
|
||
import cn.hutool.core.bean.BeanUtil; | ||
import cn.hutool.core.collection.CollUtil; | ||
import cn.hutool.core.util.StrUtil; | ||
import cn.hutool.http.ContentType; | ||
import cn.hutool.http.server.HttpServerRequest; | ||
import cn.hutool.http.server.HttpServerResponse; | ||
import cn.hutool.http.server.action.Action; | ||
import wallpaper.video.entity.Project; | ||
import wallpaper.video.entity.ProjectVo; | ||
import wallpaper.video.entity.SearchDto; | ||
import wallpaper.video.util.JSON; | ||
import wallpaper.video.util.ProjectUtil; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ListAction implements Action { | ||
@Override | ||
public void doAction(HttpServerRequest req, HttpServerResponse res) throws IOException { | ||
List<Project> list = ProjectUtil.FILES; | ||
String body = req.getBody(); | ||
SearchDto dto = JSON.fromJson(body, SearchDto.class); | ||
|
||
String text = dto.getText(); | ||
|
||
if (StrUtil.isNotBlank(text)) { | ||
list = list.stream() | ||
.filter(item -> | ||
StrUtil.containsIgnoreCase(item.getId(), text) || | ||
StrUtil.containsIgnoreCase(item.getTitle(), text) || | ||
StrUtil.containsIgnoreCase(item.getDescription(), text) || | ||
StrUtil.containsIgnoreCase(item.getType(), text) || | ||
CollUtil.contains(item.getTags(), text) | ||
).collect(Collectors.toList()); | ||
} | ||
|
||
|
||
List<ProjectVo> projectVos = BeanUtil.copyToList(list, ProjectVo.class); | ||
res.write(JSON.toJson(projectVos), ContentType.JSON.getValue()); | ||
res.close(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
server/src/main/java/wallpaper/video/action/PlayAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package wallpaper.video.action; | ||
|
||
import cn.hutool.core.map.multi.ListValueMap; | ||
import cn.hutool.http.server.HttpServerRequest; | ||
import cn.hutool.http.server.HttpServerResponse; | ||
import cn.hutool.http.server.action.Action; | ||
import wallpaper.video.entity.Project; | ||
import wallpaper.video.util.ProjectUtil; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
public class PlayAction implements Action { | ||
@Override | ||
public void doAction(HttpServerRequest req, HttpServerResponse res) throws IOException { | ||
ListValueMap<String, String> params = req.getParams(); | ||
String id = params.get("id", 0); | ||
Optional<Project> first = ProjectUtil.FILES.stream().filter(item -> item.getId().equals(id)).findFirst(); | ||
if (first.isEmpty()) { | ||
return; | ||
} | ||
Project project = first.get(); | ||
String file = project.getPath() + File.separator + project.getFile(); | ||
|
||
res.setHeader("Accept-Ranges", "bytes"); | ||
res.setHeader("Content-Type", "video/mp4"); | ||
res.setHeader("Content-Disposition", "inline;filename=" + project.getFile()); | ||
res.setHeader("Content-Length", String.valueOf(new File(file).length())); | ||
|
||
res.write(new File(file)); | ||
res.close(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
server/src/main/java/wallpaper/video/action/PreviewAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package wallpaper.video.action; | ||
|
||
import cn.hutool.core.map.multi.ListValueMap; | ||
import cn.hutool.http.server.HttpServerRequest; | ||
import cn.hutool.http.server.HttpServerResponse; | ||
import cn.hutool.http.server.action.Action; | ||
import wallpaper.video.entity.Project; | ||
import wallpaper.video.util.ProjectUtil; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
public class PreviewAction implements Action { | ||
@Override | ||
public void doAction(HttpServerRequest req, HttpServerResponse res) throws IOException { | ||
ListValueMap<String, String> params = req.getParams(); | ||
String id = params.get("id", 0); | ||
Optional<Project> first = ProjectUtil.FILES.stream().filter(item -> item.getId().equals(id)).findFirst(); | ||
if (first.isEmpty()) { | ||
return; | ||
} | ||
Project project = first.get(); | ||
String file = project.getPath() + File.separator + project.getPreview(); | ||
|
||
res.setContentType("image/gif"); | ||
res.write(new File(file)); | ||
res.close(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...rc/main/java/wallpaper/video/Project.java → .../java/wallpaper/video/entity/Project.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../main/java/wallpaper/video/ProjectVo.java → ...ava/wallpaper/video/entity/ProjectVo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../main/java/wallpaper/video/SearchDto.java → ...ava/wallpaper/video/entity/SearchDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package wallpaper.video.util; | ||
|
||
import cn.hutool.core.collection.ListUtil; | ||
import cn.hutool.core.io.FileUtil; | ||
import cn.hutool.core.io.resource.ResourceUtil; | ||
import cn.hutool.core.util.URLUtil; | ||
import lombok.Cleanup; | ||
import lombok.SneakyThrows; | ||
|
||
import java.io.File; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.jar.JarEntry; | ||
import java.util.jar.JarFile; | ||
import java.util.zip.ZipEntry; | ||
|
||
public class DistUtil { | ||
@SneakyThrows | ||
public static File getDistFile() { | ||
URL dist = ResourceUtil.getResource("dist"); | ||
if (Objects.isNull(dist)) { | ||
return null; | ||
} | ||
File root = new File(dist.getFile()); | ||
String protocol = dist.getProtocol(); | ||
if (protocol.equals("jar")) { | ||
root = new File("").getAbsoluteFile(); | ||
|
||
File distFile = new File(root + File.separator + "dist"); | ||
|
||
if (distFile.exists()) { | ||
return distFile; | ||
} | ||
|
||
JarFile jarFile = URLUtil.getJarFile(dist); | ||
List<JarEntry> distList = ListUtil.toList(jarFile.entries()); | ||
for (ZipEntry jarEntry : distList) { | ||
String name = jarEntry.getName(); | ||
if (!name.startsWith("dist")) { | ||
continue; | ||
} | ||
if (jarEntry.isDirectory()) { | ||
FileUtil.mkdir(root + File.separator + name); | ||
continue; | ||
} | ||
@Cleanup | ||
InputStream inputStream = jarFile.getInputStream(jarEntry); | ||
System.out.println(new File(root + File.separator + name)); | ||
FileUtil.writeFromStream(inputStream, root + File.separator + name); | ||
} | ||
return distFile; | ||
} | ||
|
||
return root; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package wallpaper.video.util; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonSyntaxException; | ||
|
||
public class JSON { | ||
public final static Gson gson = new com.google.gson.Gson(); | ||
|
||
public static <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException { | ||
return gson.fromJson(json,classOfT); | ||
} | ||
|
||
public static String toJson(Object src) { | ||
return gson.toJson(src); | ||
} | ||
|
||
} |
Oops, something went wrong.