mktcms 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -9,16 +9,19 @@ export default defineEventHandler(async (event) => {
|
|
|
9
9
|
const { mktcms: { s3Prefix } } = useRuntimeConfig();
|
|
10
10
|
const fullPath = s3Prefix + ":" + path;
|
|
11
11
|
const isImage = path.match(/\.(png|jpg|jpeg|gif|svg|webp)$/i);
|
|
12
|
+
const isPdf = path.endsWith(".pdf");
|
|
12
13
|
if (isImage) {
|
|
13
14
|
event.node.res.setHeader("Content-Type", "image/" + path.split(".").pop()?.toLowerCase());
|
|
15
|
+
} else if (isPdf) {
|
|
16
|
+
event.node.res.setHeader("Content-Type", "application/pdf");
|
|
14
17
|
} else {
|
|
15
18
|
event.node.res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
16
19
|
}
|
|
17
20
|
const storage = useStorage("content");
|
|
18
|
-
const file = isImage ? await storage.getItemRaw(fullPath) : await storage.getItem(fullPath);
|
|
21
|
+
const file = isImage || isPdf ? await storage.getItemRaw(fullPath) : await storage.getItem(fullPath);
|
|
19
22
|
if (!file) {
|
|
20
23
|
const fallbackStorage = useStorage("fallback");
|
|
21
|
-
const fallbackFile = isImage ? await fallbackStorage.getItemRaw(fullPath) : await fallbackStorage.getItem(fullPath);
|
|
24
|
+
const fallbackFile = isImage || isPdf ? await fallbackStorage.getItemRaw(fullPath) : await fallbackStorage.getItem(fullPath);
|
|
22
25
|
if (fallbackFile) {
|
|
23
26
|
return fallbackFile;
|
|
24
27
|
}
|
|
@@ -49,14 +49,19 @@ export default defineEventHandler(async (event) => {
|
|
|
49
49
|
const { mktcms: { s3Prefix } } = useRuntimeConfig();
|
|
50
50
|
const fullPath = s3Prefix + ":" + path;
|
|
51
51
|
const isImage = path.match(/\.(png|jpg|jpeg|gif|svg|webp)$/i);
|
|
52
|
+
const isPdf = path.endsWith(".pdf");
|
|
52
53
|
if (isImage) {
|
|
53
54
|
event.node.res.setHeader("Content-Type", "image/" + path.split(".").pop()?.toLowerCase());
|
|
55
|
+
} else if (isPdf) {
|
|
56
|
+
event.node.res.setHeader("Content-Type", "application/pdf");
|
|
57
|
+
} else {
|
|
58
|
+
event.node.res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
54
59
|
}
|
|
55
60
|
const storage = useStorage("content");
|
|
56
|
-
const file = isImage ? await storage.getItemRaw(fullPath) : await storage.getItem(fullPath);
|
|
61
|
+
const file = isImage || isPdf ? await storage.getItemRaw(fullPath) : await storage.getItem(fullPath);
|
|
57
62
|
if (!file) {
|
|
58
63
|
const fallbackStorage = useStorage("fallback");
|
|
59
|
-
const fallbackFile = isImage ? await fallbackStorage.getItemRaw(fullPath) : await fallbackStorage.getItem(fullPath);
|
|
64
|
+
const fallbackFile = isImage || isPdf ? await fallbackStorage.getItemRaw(fullPath) : await fallbackStorage.getItem(fullPath);
|
|
60
65
|
if (fallbackFile) {
|
|
61
66
|
return parsedFile(fullPath, fallbackFile);
|
|
62
67
|
}
|