mktcms 0.1.15 → 0.1.17
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 +1 -1
- package/dist/module.mjs +4 -0
- package/dist/runtime/app/components/content/index.vue +1 -1
- package/dist/runtime/server/api/admin/content/list.d.ts +2 -0
- package/dist/runtime/server/api/admin/content/list.js +20 -0
- package/dist/runtime/server/api/content/[path].js +23 -20
- package/dist/runtime/server/api/content/list.js +7 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -41,6 +41,10 @@ const module$1 = defineNuxtModule({
|
|
|
41
41
|
route: "/api/admin/logout",
|
|
42
42
|
handler: resolver.resolve("./runtime/server/api/admin/logout")
|
|
43
43
|
});
|
|
44
|
+
addServerHandler({
|
|
45
|
+
route: "/api/admin/content/list",
|
|
46
|
+
handler: resolver.resolve("./runtime/server/api/admin/content/list")
|
|
47
|
+
});
|
|
44
48
|
addServerHandler({
|
|
45
49
|
route: "/api/admin/content/:path",
|
|
46
50
|
method: "get",
|
|
@@ -3,7 +3,7 @@ import { useFetch, useRoute } from "#app";
|
|
|
3
3
|
import { computed } from "vue";
|
|
4
4
|
const path = useRoute().params.path || "";
|
|
5
5
|
const pathParts = path.split(":");
|
|
6
|
-
const { data: keys } = await useFetch("/api/content/list", {
|
|
6
|
+
const { data: keys } = await useFetch("/api/admin/content/list", {
|
|
7
7
|
query: { path }
|
|
8
8
|
});
|
|
9
9
|
const keysWithoutCurrentPath = computed(() => {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { useStorage, useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
import { defineEventHandler, getValidatedQuery } from "h3";
|
|
4
|
+
const querySchema = z.object({
|
|
5
|
+
path: z.string().optional()
|
|
6
|
+
});
|
|
7
|
+
export default defineEventHandler(async (event) => {
|
|
8
|
+
const { path } = await getValidatedQuery(event, (query) => querySchema.parse(query));
|
|
9
|
+
const { mktcms: { s3Prefix } } = useRuntimeConfig();
|
|
10
|
+
const storage = useStorage("content");
|
|
11
|
+
const keys = await storage.getKeys(s3Prefix + (path ? ":" + path : ""));
|
|
12
|
+
const fallbackStorage = useStorage("fallback");
|
|
13
|
+
const fallbackKeys = await fallbackStorage.getKeys(s3Prefix + (path ? ":" + path : ""));
|
|
14
|
+
for (const key of fallbackKeys) {
|
|
15
|
+
if (!keys.includes(key)) {
|
|
16
|
+
keys.push(key);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return keys.map((key) => key.replace(s3Prefix + ":", ""));
|
|
20
|
+
});
|
|
@@ -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
|
});
|
|
@@ -9,5 +9,12 @@ export default defineEventHandler(async (event) => {
|
|
|
9
9
|
const { mktcms: { s3Prefix } } = useRuntimeConfig();
|
|
10
10
|
const storage = useStorage("content");
|
|
11
11
|
const keys = await storage.getKeys(s3Prefix + (path ? ":" + path : ""));
|
|
12
|
+
const fallbackStorage = useStorage("fallback");
|
|
13
|
+
const fallbackKeys = await fallbackStorage.getKeys(s3Prefix + (path ? ":" + path : ""));
|
|
14
|
+
for (const key of fallbackKeys) {
|
|
15
|
+
if (!keys.includes(key)) {
|
|
16
|
+
keys.push(key);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
12
19
|
return keys.map((key) => key.replace(s3Prefix + ":", ""));
|
|
13
20
|
});
|