mktcms 0.1.15 → 0.1.16
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
|
@@ -3,26 +3,7 @@ import { createError, defineEventHandler, getValidatedRouterParams } from "h3";
|
|
|
3
3
|
import { useRuntimeConfig, useStorage } from "nitropack/runtime";
|
|
4
4
|
import { parse } from "csv-parse/sync";
|
|
5
5
|
import { marked } from "marked";
|
|
6
|
-
|
|
7
|
-
path: z.string().min(1)
|
|
8
|
-
});
|
|
9
|
-
export default defineEventHandler(async (event) => {
|
|
10
|
-
const { path } = await getValidatedRouterParams(event, (params) => paramsSchema.parse(params));
|
|
11
|
-
const { mktcms: { s3Prefix } } = useRuntimeConfig();
|
|
12
|
-
const fullPath = s3Prefix + ":" + path;
|
|
13
|
-
const storage = useStorage("content");
|
|
14
|
-
const file = await storage.getItem(fullPath);
|
|
15
|
-
if (!file) {
|
|
16
|
-
const fallbackStorage = useStorage("fallback");
|
|
17
|
-
const fallbackFile = await fallbackStorage.getItem(fullPath);
|
|
18
|
-
if (fallbackFile) {
|
|
19
|
-
return fallbackFile;
|
|
20
|
-
}
|
|
21
|
-
throw createError({
|
|
22
|
-
statusCode: 404,
|
|
23
|
-
statusMessage: "File not found"
|
|
24
|
-
});
|
|
25
|
-
}
|
|
6
|
+
function parsedFile(fullPath, file) {
|
|
26
7
|
if (fullPath.endsWith(".json") && typeof file === "string") {
|
|
27
8
|
try {
|
|
28
9
|
return JSON.parse(file);
|
|
@@ -59,4 +40,26 @@ export default defineEventHandler(async (event) => {
|
|
|
59
40
|
}
|
|
60
41
|
}
|
|
61
42
|
return file;
|
|
43
|
+
}
|
|
44
|
+
const paramsSchema = z.object({
|
|
45
|
+
path: z.string().min(1)
|
|
46
|
+
});
|
|
47
|
+
export default defineEventHandler(async (event) => {
|
|
48
|
+
const { path } = await getValidatedRouterParams(event, (params) => paramsSchema.parse(params));
|
|
49
|
+
const { mktcms: { s3Prefix } } = useRuntimeConfig();
|
|
50
|
+
const fullPath = s3Prefix + ":" + path;
|
|
51
|
+
const storage = useStorage("content");
|
|
52
|
+
const file = await storage.getItem(fullPath);
|
|
53
|
+
if (!file) {
|
|
54
|
+
const fallbackStorage = useStorage("fallback");
|
|
55
|
+
const fallbackFile = await fallbackStorage.getItem(fullPath);
|
|
56
|
+
if (fallbackFile) {
|
|
57
|
+
return parsedFile(fullPath, fallbackFile);
|
|
58
|
+
}
|
|
59
|
+
throw createError({
|
|
60
|
+
statusCode: 404,
|
|
61
|
+
statusMessage: "File not found"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return parsedFile(fullPath, file);
|
|
62
65
|
});
|