feat: Docker部署与CI/CD集成, 搜索栏修复, 上传目录改为data

This commit is contained in:
xiner
2025-11-28 18:42:30 +08:00
commit 8351d6bbfc
243 changed files with 13192 additions and 0 deletions

30
pages/api/v1/users/me.ts Normal file
View File

@@ -0,0 +1,30 @@
import { NextApiResponse } from 'next';
import { AuthenticatedRequest, requireAuth } from '../../../../lib/middleware/authMiddleware';
import { UserService } from '../../../../backend/services/userService';
export default async function handler(req: AuthenticatedRequest, res: NextApiResponse) {
if (req.method !== 'PATCH') {
return res.status(405).json({ success: false, error: 'Method not allowed' });
}
// Require authentication
const isAuthenticated = await requireAuth(req, res);
if (!isAuthenticated) {
return;
}
try {
const { username, avatarUrl } = req.body;
// Update user
const updatedUser = await UserService.updateUser(req.user!.id, {
username,
avatarUrl
});
return res.status(200).json({ success: true, data: updatedUser });
} catch (error) {
console.error('Error updating user:', error);
return res.status(500).json({ success: false, error: 'Failed to update user' });
}
}

View File

@@ -0,0 +1,23 @@
import { NextApiResponse } from 'next';
import { AuthenticatedRequest, requireAuth } from '@/lib/middleware/authMiddleware';
import { MaterialService } from '@/backend/services/materialService';
export default async function handler(req: AuthenticatedRequest, res: NextApiResponse) {
if (req.method !== 'GET') {
return res.status(405).json({ success: false, error: 'Method not allowed' });
}
try {
const isAuthenticated = await requireAuth(req, res);
if (!isAuthenticated) return;
const page = parseInt((req.query.page as string) || '1', 10) || 1;
const limit = parseInt((req.query.limit as string) || '20', 10) || 20;
const { items, total } = await MaterialService.getFavoritedMaterialsByUser(req.user!.id, page, limit);
const hasNext = page * limit < total;
return res.status(200).json({ success: true, data: { items, total, page, limit, hasNext }, timestamp: new Date().toISOString() });
} catch (error: any) {
console.error('Get user favorites error:', error);
return res.status(500).json({ success: false, error: error.message || 'Failed to get favorites' });
}
}

View File

@@ -0,0 +1,24 @@
import { NextApiResponse } from 'next';
import { AuthenticatedRequest, requireAuth } from '@/lib/middleware/authMiddleware';
import { MaterialService } from '@/backend/services/materialService';
export default async function handler(req: AuthenticatedRequest, res: NextApiResponse) {
if (req.method !== 'GET') {
return res.status(405).json({ success: false, error: 'Method not allowed' });
}
try {
const isAuthenticated = await requireAuth(req, res);
if (!isAuthenticated) return;
const { user } = req;
const page = parseInt((req.query.page as string) || '1', 10) || 1;
const limit = parseInt((req.query.limit as string) || '20', 10) || 20;
const { items, total } = await MaterialService.getMaterialsByAuthor(user!.id, page, limit);
const hasNext = page * limit < total;
return res.status(200).json({ success: true, data: { items, total, page, limit, hasNext }, timestamp: new Date().toISOString() });
} catch (error: any) {
console.error('Get user materials error:', error);
return res.status(500).json({ success: false, error: error.message || 'Failed to get materials' });
}
}