- 新增 Dockerfile 和 .dockerignore 文件 - 添加 Gitea 持续集成工作流,用于构建和推送 Docker 镜像 - 新增 .gitignore 文件,忽略构建和配置文件 - 添加项目结构和规范文档,包括 TypeScript、模块化、API、数据库等规范 - 新增前端和后端的基础代码结构
89 lines
1.9 KiB
TypeScript
89 lines
1.9 KiB
TypeScript
import { createRoute, OpenAPIHono } from '@hono/zod-openapi'
|
|
import { z } from 'zod'
|
|
import { AppDataSource } from '../data-source'
|
|
import { HTTPException } from 'hono/http-exception';
|
|
import { authMiddleware } from '../middleware/auth.middleware';
|
|
import { AuthContext } from '../types/context';
|
|
|
|
interface Migration {
|
|
name: string;
|
|
timestamp: number;
|
|
}
|
|
|
|
const app = new OpenAPIHono<AuthContext>()
|
|
|
|
const MigrationResponseSchema = z.object({
|
|
success: z.boolean(),
|
|
message: z.string(),
|
|
migrations: z.array(z.string()).optional()
|
|
})
|
|
|
|
const runMigrationRoute = createRoute({
|
|
method: 'post',
|
|
path: '/migrations/run',
|
|
middleware: authMiddleware,
|
|
responses: {
|
|
200: {
|
|
content: {
|
|
'application/json': {
|
|
schema: MigrationResponseSchema
|
|
}
|
|
},
|
|
description: 'Migrations executed successfully'
|
|
},
|
|
500: {
|
|
description: 'Migration failed'
|
|
}
|
|
}
|
|
})
|
|
|
|
const revertMigrationRoute = createRoute({
|
|
method: 'post',
|
|
path: '/migrations/revert',
|
|
middleware: authMiddleware,
|
|
responses: {
|
|
200: {
|
|
content: {
|
|
'application/json': {
|
|
schema: MigrationResponseSchema
|
|
}
|
|
},
|
|
description: 'Migration reverted successfully'
|
|
},
|
|
500: {
|
|
description: 'Revert failed'
|
|
}
|
|
}
|
|
})
|
|
|
|
app.openapi(runMigrationRoute, async (c) => {
|
|
try {
|
|
const migrations = await AppDataSource.runMigrations()
|
|
return c.json({
|
|
success: true,
|
|
message: 'Migrations executed successfully',
|
|
migrations: migrations.map((m: Migration) => m.name)
|
|
})
|
|
} catch (error) {
|
|
throw error
|
|
}
|
|
})
|
|
|
|
app.openapi(revertMigrationRoute, async (c) => {
|
|
try {
|
|
await AppDataSource.undoLastMigration()
|
|
const migrations = await AppDataSource.showMigrations()
|
|
return c.json({
|
|
success: true,
|
|
message: 'Migration reverted successfully',
|
|
migrations: migrations
|
|
})
|
|
} catch (error) {
|
|
throw error
|
|
}
|
|
})
|
|
|
|
|
|
|
|
export default app
|
|
export type AppType = typeof app |