Support video files in viewer

This commit is contained in:
2021-10-03 15:49:58 +02:00
parent 86a9e55b43
commit 785e4f57c4
4 changed files with 18 additions and 5 deletions

View File

@@ -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":

View File

@@ -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();

View File

@@ -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");

View File

@@ -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>