feat: port user profile feature from upstream
- GET /api/users?username= filter (admin) - GET /api/posts?user_id= filter - Add UserProfile page (profile card + user's posts), reachable via ?user=<username> - Clickable usernames on feed, post detail, replies
This commit is contained in:
1 parent
e6ba5507ae
commit
5ef8d4b1ff
9 files changed
+166
-17
No files matched your search
+13
-4
@@ -1,4 +1,4 @@
|
||||
// GET /api/users (admin)
|
||||
// GET /api/users (admin) — 支持 ?username= 按用户名查询
|
||||
import pool from '@/lib/db';
|
||||
import { getUser, requireAdmin } from '@/lib/auth';
|
||||
|
||||
@@ -6,10 +6,19 @@ export async function GET(req) {
|
||||
const user = getUser(req);
|
||||
const forbidden = await requireAdmin(user);
|
||||
if (forbidden) return forbidden;
|
||||
|
||||
const url = new URL(req.url);
|
||||
const username = url.searchParams.get('username');
|
||||
|
||||
try {
|
||||
const r = await pool.query(
|
||||
'SELECT id, username, avatar_url, bio, role, created_at FROM users ORDER BY created_at DESC'
|
||||
);
|
||||
let query = 'SELECT id, username, avatar_url, bio, role, created_at FROM users';
|
||||
const params = [];
|
||||
if (username) {
|
||||
query += ' WHERE username = $1';
|
||||
params.push(username);
|
||||
}
|
||||
query += ' ORDER BY created_at DESC';
|
||||
const r = await pool.query(query, params);
|
||||
return Response.json(r.rows);
|
||||
} catch {
|
||||
return Response.json({ error: '服务器错误' }, { status: 500 });
|
||||
|
||||
Reference in new issue
Block a user