mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update resource type checks (#2081)
This commit is contained in:
@ -5,3 +5,34 @@ export const getResourceUrl = (resource: Resource, withOrigin = true) => {
|
||||
|
||||
return `${withOrigin ? window.location.origin : ""}/o/r/${resource.id}`;
|
||||
};
|
||||
|
||||
export const getResourceType = (resource: Resource) => {
|
||||
if (resource.type.startsWith("image") && isImage(resource.type)) {
|
||||
return "image/*";
|
||||
} else if (resource.type.startsWith("video")) {
|
||||
return "video/*";
|
||||
} else if (resource.type.startsWith("audio")) {
|
||||
return "audio/*";
|
||||
} else if (resource.type.startsWith("text")) {
|
||||
return "text/*";
|
||||
} else if (resource.type.startsWith("application/epub+zip")) {
|
||||
return "application/epub+zip";
|
||||
} else if (resource.type.startsWith("application/pdf")) {
|
||||
return "application/pdf";
|
||||
} else if (resource.type.includes("word")) {
|
||||
return "application/msword";
|
||||
} else if (resource.type.includes("excel")) {
|
||||
return "application/msexcel";
|
||||
} else if (resource.type.startsWith("application/zip")) {
|
||||
return "application/zip";
|
||||
} else if (resource.type.startsWith("application/x-java-archive")) {
|
||||
return "application/x-java-archive";
|
||||
} else {
|
||||
return "application/octet-stream";
|
||||
}
|
||||
};
|
||||
|
||||
// isImage returns true if the given mime type is an image.
|
||||
export const isImage = (t: string) => {
|
||||
return t === "image/jpeg" || t === "image/png" || t === "image/gif" || t === "image/svg+xml" || t === "image/webp";
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user