Skip to content

Commit

Permalink
Add view for video and image (#723)
Browse files Browse the repository at this point in the history
Co-authored-by: 杨赫然 <[email protected]>
  • Loading branch information
feiniks and 杨赫然 authored Dec 9, 2024
1 parent e8c0e81 commit 2ab66f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
21 changes: 21 additions & 0 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func parseContentType(fileName string) string {
parts := strings.Split(fileName, ".")
if len(parts) >= 2 {
suffix := parts[len(parts)-1]
suffix = strings.ToLower(suffix)
switch suffix {
case "txt":
contentType = "text/plain"
Expand All @@ -109,6 +110,12 @@ func parseContentType(fileName string) string {
contentType = "video/mpeg"
case "mp4":
contentType = "video/mp4"
case "ogv":
contentType = "video/ogg"
case "mov":
contentType = "video/mp4"
case "webm":
contentType = "video/webm"
case "jpeg", "JPEG", "jpg", "JPG":
contentType = "image/jpeg"
case "png", "PNG":
Expand All @@ -117,6 +124,20 @@ func parseContentType(fileName string) string {
contentType = "image/gif"
case "svg", "SVG":
contentType = "image/svg+xml"
case "heic":
contentType = "image/heic"
case "ico":
contentType = "image/x-icon"
case "bmp":
contentType = "image/bmp"
case "tif", "tiff":
contentType = "image/tiff"
case "psd":
contentType = "image/vnd.adobe.photoshop"
case "webp":
contentType = "image/webp"
case "jfif":
contentType = "image/jpeg"
}
}

Expand Down
18 changes: 17 additions & 1 deletion server/access-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ static struct file_type_map ftmap[] = {
{ "mp3", "audio/mp3" },
{ "mpeg", "video/mpeg" },
{ "mp4", "video/mp4" },
{ "ogv", "video/ogg" },
{ "mov", "video/mp4" },
{ "webm", "video/webm" },
{ "jpg", "image/jpeg" },
{ "JPG", "image/jpeg" },
{ "jpeg", "image/jpeg" },
Expand All @@ -142,6 +145,14 @@ static struct file_type_map ftmap[] = {
{ "GIF", "image/gif" },
{ "svg", "image/svg+xml" },
{ "SVG", "image/svg+xml" },
{ "heic", "image/heic" },
{ "ico", "image/x-icon" },
{ "bmp", "image/bmp" },
{ "tif", "image/tiff" },
{ "tiff", "image/tiff" },
{ "psd", "image/vnd.adobe.photoshop" },
{ "webp", "image/webp" },
{ "jfif", "image/jpeg" },
{ NULL, NULL },
};

Expand Down Expand Up @@ -509,11 +520,16 @@ parse_content_type(const char *filename)
return NULL;
p++;

char *lower = g_utf8_strdown (p, strlen(p));

for (i = 0; ftmap[i].suffix != NULL; i++) {
if (strcmp(p, ftmap[i].suffix) == 0)
if (strcmp(lower, ftmap[i].suffix) == 0) {
g_free (lower);
return ftmap[i].type;
}
}

g_free (lower);
return NULL;
}

Expand Down

0 comments on commit 2ab66f0

Please sign in to comment.