- 实现用户登录、登出、密码修改等认证功能 - 添加会话管理和权限控制中间件 - 创建图片批注组件和相关API路由 - 实现批注的增删改查功能 - 添加Docker和Git忽略配置文件 - 创建系统架构文档和开发约定说明 - 集成认证模块到前端应用路由中
19 lines
1.0 KiB
TypeScript
19 lines
1.0 KiB
TypeScript
import { Router, type Response } from 'express';
|
|
import { annotationsRepository } from '../repositories/annotationsRepository.js';
|
|
import { canWriteProject, requireWriter, type AuthRequest } from '../auth.js';
|
|
import { database } from '../database.js';
|
|
|
|
const router = Router();
|
|
|
|
router.delete('/:annotationId', requireWriter, async (req: AuthRequest, res: Response) => {
|
|
const id = Number(req.params.annotationId);
|
|
if (!Number.isFinite(id)) { res.status(400).json({ error: '无效的批注 ID' }); return; }
|
|
const context = await database.one<{ project_id: number }>('SELECT c.project_id FROM annotations a JOIN images i ON i.id = a.image_id JOIN notes n ON n.id = i.note_id JOIN collections c ON c.id = n.collection_id WHERE a.id = ?', [id]);
|
|
if (!context) { res.status(404).json({ error: '批注不存在' }); return; }
|
|
if (!await canWriteProject(req, context.project_id)) { res.status(403).json({ error: '无权操作该批注' }); return; }
|
|
await annotationsRepository.remove(id);
|
|
res.status(204).end();
|
|
});
|
|
|
|
export default router;
|