new selfhosted version

This commit is contained in:
antonio
2025-11-28 14:11:51 +01:00
parent afda29997d
commit 951860f67e
1046 changed files with 72586 additions and 574750 deletions

View File

@@ -1,36 +1,32 @@
import { ProjectModel } from "@schema/project/ProjectSchema";
import { ProjectSnapshotModel } from "@schema/project/ProjectSnapshot";
import { z } from "zod";
const ZCreateSnapshotBody = z.object({
name: z.string().trim().min(2).max(22),
color: z.string().regex(/^#[0-9A-Fa-f]{6}$/, {
message: "Color must be a hex code starting with # followed by 6 hex digits"
}),
from: z.string(),
to: z.string()
})
export default defineEventHandler(async event => {
const data = await getRequestDataOld(event, { requireSchema: false, allowGuests: true, requireRange: false });
if (!data) return;
const ctx = await getRequestContext(event, 'pid', 'permission:member');
const { project_id } = ctx;
const body = await readBody(event);
const body = await readValidatedBody(event, ZCreateSnapshotBody.parse);
const { name: newSnapshotName, from, to, color: snapshotColor } = body;
if (!newSnapshotName) return setResponseStatus(event, 400, 'SnapshotName too short');
if (newSnapshotName.trim().length == 0) return setResponseStatus(event, 400, 'SnapshotName too short');
if (!from) return setResponseStatus(event, 400, 'from is required');
if (!to) return setResponseStatus(event, 400, 'to is required');
if (!snapshotColor) return setResponseStatus(event, 400, 'color is required');
const userData = getRequestUser(event);
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
const project = await ProjectModel.findById(data.project_id);
if (!project) return setResponseStatus(event, 400, 'Project not found');
const newSnapshot = await ProjectSnapshotModel.create({
name: newSnapshotName.trim(),
name: newSnapshotName,
from: new Date(from),
to: new Date(to),
color: snapshotColor,
project_id: data.project_id
project_id
});
return newSnapshot.id;