Support video files in viewer
This commit is contained in:
@@ -3,7 +3,7 @@ package sh.rhiobet.lalafin.file;
|
||||
public class FileHelper {
|
||||
|
||||
public static String getMimeType(String filename) {
|
||||
String extension = filename.substring(filename.lastIndexOf('.') + 1);
|
||||
String extension = filename.substring(filename.lastIndexOf('.') + 1).toLowerCase();
|
||||
|
||||
switch (extension) {
|
||||
case "3gp":
|
||||
|
||||
@@ -89,7 +89,8 @@ public class ThumbnailService {
|
||||
try {
|
||||
Optional<Path> imgPath = Files.list(folderPath).sorted()
|
||||
.filter(p -> !Files.isDirectory(p)
|
||||
&& (p.toString().endsWith(".png") || p.toString().endsWith(".jpg")))
|
||||
&& (p.toString().toLowerCase().endsWith(".png")
|
||||
|| p.toString().toLowerCase().endsWith(".jpg")))
|
||||
.findFirst();
|
||||
if (imgPath.isPresent()) {
|
||||
thumbPath.getParent().toFile().mkdirs();
|
||||
|
||||
@@ -109,9 +109,15 @@ public class ViewerService {
|
||||
String viewUriBase = folderInfo.viewUrl.replaceAll("/[^/]*$", "/");
|
||||
|
||||
TemplateInstance viewTemplateInstance = viewTemplate.instance().data("info", requestedFile)
|
||||
.data("image", requestedFile.directUrl).data("currpage", page)
|
||||
.data("totpage", viewableFiles.size()).data("prevuri", viewUriBase + (page - 1))
|
||||
.data("nexturi", viewUriBase + (page + 1));
|
||||
.data("currpage", page).data("nexturi", viewUriBase + (page + 1));
|
||||
|
||||
String requestedFileMimeType = FileHelper.getMimeType(requestedFile.filename);
|
||||
if (requestedFileMimeType.startsWith("image/")) {
|
||||
viewTemplateInstance.data("image", requestedFile.directUrl);
|
||||
} else if (requestedFileMimeType.startsWith("video/")) {
|
||||
viewTemplateInstance.data("video", requestedFile.directUrl);
|
||||
}
|
||||
|
||||
ResponseBuilder response = Response.ok(viewTemplateInstance.render());
|
||||
response.header("Content-Type", "text/html");
|
||||
|
||||
@@ -15,7 +15,13 @@
|
||||
</tr>
|
||||
</table>
|
||||
<hr />
|
||||
{#if currpage < totpage}<a href="{nexturi}">{/if}<img style="position: absolute; left: 50%; transform: translate(-50%, 0);" src="{image}" />{#if currpage < totpage}</a>{/if}
|
||||
{#if currpage < totpage}<a href="{nexturi}">{/if}
|
||||
{#if image != null}
|
||||
<img style="position: absolute; left: 50%; transform: translate(-50%, 0);" src="{image}" />
|
||||
{#else if video != null}
|
||||
<video src="{video}" controls style="width: 100%"></video>
|
||||
{/if}
|
||||
{#if currpage < totpage}</a>{/if}
|
||||
<hr />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user