v3: added multiple stylesheets, improved user profiles

This commit is contained in:
khannurien
2026-04-06 15:36:04 +00:00
parent a69788c15b
commit 3b6980a8fc
24 changed files with 2182 additions and 714 deletions

View File

@@ -4,6 +4,7 @@ import {
type Dump,
type FollowStatus,
type Playlist,
type User,
} from "../model/interfaces.ts";
import {
notifyPlaylistOwnerNewFollower,
@@ -15,7 +16,9 @@ import {
isDumpRow,
isFollowRow,
isPlaylistRow,
isUserRow,
playlistRowToApi,
userRowToApi,
} from "../model/db.ts";
// Mirrors dump-service SELECT_COLS_ALIASED — kept local to avoid circular imports
@@ -256,3 +259,39 @@ export function getFollowedPlaylistsByUser(
}
return { items: rawRows.map(playlistRowToApi), total: totalRow?.count ?? 0 };
}
// ── Followed users (as user objects) ─────────────────────────────────────────
export function getFollowedUsersByUser(
userId: string,
page: number,
limit: number,
): { items: User[]; total: number } {
const offset = (page - 1) * limit;
const totalRow = db.prepare(
`SELECT COUNT(*) as count FROM follows WHERE follower_id = ? AND followed_user_id IS NOT NULL;`,
).get(userId) as { count: number } | undefined;
const rawRows = db.prepare(
`SELECT u.id, u.username, u.password_hash, u.is_admin, u.created_at, u.updated_at,
u.avatar_mime, u.description, u.invited_by, u.email,
i.username as invited_by_username
FROM users u
LEFT JOIN users i ON i.id = u.invited_by
INNER JOIN follows f ON f.followed_user_id = u.id
WHERE f.follower_id = ?
ORDER BY f.created_at DESC
LIMIT ? OFFSET ?;`,
).all(userId, limit, offset);
if (!rawRows.every(isUserRow)) {
throw new APIException(
APIErrorCode.SERVER_ERROR,
500,
"Malformed user data",
);
}
return { items: rawRows.map(userRowToApi), total: totalRow?.count ?? 0 };
}