feat: prisma schema, groups API, deploy workflow
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { requireAuth } from '~/server/utils/auth'
|
||||
import { saveCanvasToGitea } from '~/server/utils/giteaApi'
|
||||
import { canvases, userGroups } from '~/server/utils/db'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const user = requireAuth(event)
|
||||
const body = await readBody(event)
|
||||
const { canvasId, type } = body
|
||||
|
||||
if (!canvasId || !type) {
|
||||
throw createError({ statusCode: 400, message: 'Canvas ID and repository type are required' })
|
||||
}
|
||||
|
||||
// Check if canvas exists and user has access
|
||||
const canvas = canvases.get(canvasId)
|
||||
if (!canvas) {
|
||||
throw createError({ statusCode: 404, message: 'Canvas not found' })
|
||||
}
|
||||
|
||||
if (canvas.ownerId !== user.id && !canvas.isPublic) {
|
||||
// Check group access
|
||||
if (canvas.groupId) {
|
||||
const membership = Array.from(userGroups.values()).find(
|
||||
m => m.userId === user.id && m.groupId === canvas.groupId
|
||||
)
|
||||
if (!membership) {
|
||||
throw createError({ statusCode: 403, message: 'Access denied' })
|
||||
}
|
||||
} else {
|
||||
throw createError({ statusCode: 403, message: 'Access denied' })
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Initial save to Gitea creates the canvas file in the repo
|
||||
const ok = await saveCanvasToGitea(canvasId, canvas, `Init canvas ${canvasId}`)
|
||||
return {
|
||||
success: ok,
|
||||
message: ok
|
||||
? `Canvas ${canvasId} initialized in Gitea`
|
||||
: `Failed to initialize canvas ${canvasId} in Gitea`
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize canvas in Gitea:', error)
|
||||
throw createError({ statusCode: 500, message: 'Failed to initialize canvas in Gitea' })
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user