@monkeyplus/flow 6.0.20 → 6.0.21
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.
|
@@ -8,16 +8,14 @@ const baseUrl = "/api/repos/local/";
|
|
|
8
8
|
export default defineEventHandler(async (event) => {
|
|
9
9
|
const pathname = event.url.pathname.replace(baseUrl, "");
|
|
10
10
|
const config = useRuntimeConfig()?.flow?.cms;
|
|
11
|
-
|
|
11
|
+
const BASE = config.base || "/";
|
|
12
12
|
const [_repo, command, ...rest] = pathname.split("/");
|
|
13
13
|
if (command === "blobs") {
|
|
14
14
|
const query = getQuery(event);
|
|
15
15
|
if (query.update) {
|
|
16
16
|
const body = await readBody(event);
|
|
17
17
|
const data = Buffer.from(body?.content || "", "base64").toString("utf-8");
|
|
18
|
-
|
|
19
|
-
const filePath = path.relative(config.base, decodeURIComponent(query.update).trim());
|
|
20
|
-
console.log("updatePath", filePath);
|
|
18
|
+
const filePath = path.relative(BASE, decodeURIComponent(query.update).trim());
|
|
21
19
|
await fs.writeFile(filePath, data, "utf-8");
|
|
22
20
|
return {
|
|
23
21
|
sha: ""
|
|
@@ -30,7 +28,7 @@ export default defineEventHandler(async (event) => {
|
|
|
30
28
|
data = data.toString("utf-8");
|
|
31
29
|
}
|
|
32
30
|
const createPath = decodeURIComponent(query.create);
|
|
33
|
-
const filePath = path.relative(
|
|
31
|
+
const filePath = path.relative(BASE, createPath);
|
|
34
32
|
fs.ensureFileSync(filePath);
|
|
35
33
|
await fs.writeFile(filePath, data, "utf-8");
|
|
36
34
|
return {
|
|
@@ -66,15 +64,15 @@ export default defineEventHandler(async (event) => {
|
|
|
66
64
|
if (command === "files") {
|
|
67
65
|
const { folder, file } = getQuery(event);
|
|
68
66
|
if (file) {
|
|
69
|
-
const filePath = path.relative(
|
|
70
|
-
console.log("file", file,
|
|
67
|
+
const filePath = path.relative(BASE, decodeURIComponent(file));
|
|
68
|
+
console.log("file", file, BASE, filePath);
|
|
71
69
|
const content = await fs.readFile(filePath, "utf-8");
|
|
72
70
|
return {
|
|
73
71
|
content: JSON.parse(content),
|
|
74
72
|
encoding: "json"
|
|
75
73
|
};
|
|
76
74
|
}
|
|
77
|
-
const folderPath = path.relative(
|
|
75
|
+
const folderPath = path.relative(BASE, folder);
|
|
78
76
|
const files = await listFiles(folderPath, "", 1);
|
|
79
77
|
return { files: files.map((f) => {
|
|
80
78
|
return {
|