feat: use portainer hook instead of pushing image to gitea package repository
This commit is contained in:
31
server/api/files/[name]/index.patch.ts
Normal file
31
server/api/files/[name]/index.patch.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { rename } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import { z } from "zod";
|
||||
|
||||
const paramsSchema = z.object({
|
||||
name: z.string().min(1).regex(/^[^/\\]+$/, "Invalid filename"),
|
||||
});
|
||||
|
||||
const bodySchema = z.object({
|
||||
name: z.string().min(1).regex(/^[^/\\]+$/, "Invalid filename"),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const params = await getValidatedRouterParams(event, paramsSchema.parse);
|
||||
const body = await readValidatedBody(event, bodySchema.parse);
|
||||
|
||||
const dir = resolve(process.cwd(), "public/files");
|
||||
const oldPath = resolve(dir, params.name);
|
||||
const newPath = resolve(dir, body.name);
|
||||
|
||||
if (!oldPath.startsWith(dir + "/") || !newPath.startsWith(dir + "/")) {
|
||||
throw createError({ statusCode: 400, message: "Invalid filename" });
|
||||
}
|
||||
|
||||
try {
|
||||
await rename(oldPath, newPath);
|
||||
return { name: body.name };
|
||||
} catch {
|
||||
throw createError({ statusCode: 404, message: "File not found" });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user