feat: add user profile views and library management
Some checks failed
CI / UI / Build (push) Failing after 11s
CI / Scraper / Lint (pull_request) Failing after 15s
CI / UI / Docker Push (push) Has been skipped
CI / Scraper / Test (pull_request) Successful in 20s
CI / Scraper / Docker Push (pull_request) Has been skipped
CI / UI / Build (pull_request) Failing after 17s
CI / UI / Docker Push (pull_request) Has been skipped
iOS CI / Build (push) Successful in 3m40s
iOS CI / Build (pull_request) Successful in 1m49s
iOS CI / Test (push) Successful in 4m24s
iOS CI / Test (pull_request) Successful in 4m46s

- Add UserProfileView and UserProfileViewModel for iOS
- Implement user library API endpoint (/api/users/[username]/library)
- Add DELETE /api/progress/[slug] endpoint for removing books from library
- Integrate subscription feed in home API
- Update Xcode project with new profile components
This commit is contained in:
Admin
2026-03-11 15:45:04 +05:00
parent b5bc6ff3de
commit 3e4b1c0484
21 changed files with 1111 additions and 74 deletions

View File

@@ -127,6 +127,14 @@ async function pbPatch(path: string, body: unknown): Promise<Response> {
});
}
async function pbDelete(path: string): Promise<Response> {
const token = await getToken();
return fetch(`${PB_URL}${path}`, {
method: 'DELETE',
headers: { Authorization: `Bearer ${token}` }
});
}
interface PBList<T> {
items: T[];
totalItems: number;
@@ -286,10 +294,41 @@ export async function setProgress(
if (!res.ok) {
const body = await res.text().catch(() => '');
log.error('pocketbase', 'setProgress POST failed', { slug, chapter, status: res.status, body });
}
}
}
/**
* Delete progress entry for a specific book (removes from library/continue reading).
*/
export async function deleteProgress(
sessionId: string,
slug: string,
userId?: string
): Promise<void> {
const existing = await listOne<Progress & { id: string }>(
'progress',
progressFilter(sessionId, slug, userId)
);
if (!existing) {
log.debug('pocketbase', 'deleteProgress: no record found', { sessionId, slug, userId });
return;
}
const res = await pbDelete(`/api/collections/progress/records/${existing.id}`);
if (!res.ok) {
const body = await res.text().catch(() => '');
log.error('pocketbase', 'deleteProgress failed', {
slug,
id: existing.id,
status: res.status,
body
});
throw new Error(`Failed to delete progress: ${res.status}`);
}
log.info('pocketbase', 'deleteProgress success', { slug, id: existing.id });
}
/**
* Merge anonymous session progress into a user account on login/register.
*

View File

@@ -1,12 +1,19 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { listBooks, recentlyAddedBooks, allProgress, getHomeStats } from '$lib/server/pocketbase';
import {
listBooks,
recentlyAddedBooks,
allProgress,
getHomeStats,
getSubscriptionFeed
} from '$lib/server/pocketbase';
import { log } from '$lib/server/logger';
import type { Book, Progress } from '$lib/server/pocketbase';
/**
* GET /api/home
* Returns home screen data: continue-reading list, recently updated books, and stats.
* Returns home screen data: continue-reading list, recently updated books, stats,
* and subscription feed (books recently read by followed users).
* Requires authentication (enforced by layout guard).
*/
export const GET: RequestHandler = async ({ locals }) => {
@@ -36,6 +43,12 @@ export const GET: RequestHandler = async ({ locals }) => {
const inProgressSlugs = new Set(continueReading.map((c) => c.book.slug));
const recentlyUpdated = recentBooks.filter((b) => !inProgressSlugs.has(b.slug)).slice(0, 6);
// Subscription feed — only available for logged-in users with following
let subscriptionFeed: Array<{ book: Book; readerUsername: string }> = [];
if (locals.user?.id) {
subscriptionFeed = await getSubscriptionFeed(locals.user.id).catch(() => []);
}
return json({
continue_reading: continueReading,
recently_updated: recentlyUpdated,
@@ -43,6 +56,10 @@ export const GET: RequestHandler = async ({ locals }) => {
totalBooks: stats.totalBooks,
totalChapters: stats.totalChapters,
booksInProgress: continueReading.length
}
},
subscription_feed: subscriptionFeed.map((item) => ({
book: item.book,
readerUsername: item.readerUsername
}))
});
};

View File

@@ -1,6 +1,6 @@
import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { setProgress } from '$lib/server/pocketbase';
import { setProgress, deleteProgress } from '$lib/server/pocketbase';
import { log } from '$lib/server/logger';
/**
@@ -32,3 +32,23 @@ export const POST: RequestHandler = async ({ params, request, locals }) => {
return json({ ok: true });
};
/**
* DELETE /api/progress/[slug]
* Removes reading progress for a specific book (removes from library/continue reading).
*/
export const DELETE: RequestHandler = async ({ params, locals }) => {
const { slug } = params;
try {
await deleteProgress(locals.sessionId, slug, locals.user?.id);
} catch (e) {
log.error('api/progress/[slug]', 'deleteProgress failed', {
slug,
err: String(e)
});
error(500, 'Failed to delete progress');
}
return json({ ok: true });
};

View File

@@ -0,0 +1,43 @@
import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import {
getUserByUsername,
getUserPublicLibrary,
getUserCurrentlyReading
} from '$lib/server/pocketbase';
import { log } from '$lib/server/logger';
/**
* GET /api/users/[username]/library
* Returns the public library + currently-reading list for a user.
* Does not require authentication — all data is public.
*/
export const GET: RequestHandler = async ({ params }) => {
const { username } = params;
const user = await getUserByUsername(username).catch(() => null);
if (!user) error(404, `User "${username}" not found`);
try {
const [currentlyReading, library] = await Promise.all([
getUserCurrentlyReading(user.id),
getUserPublicLibrary(user.id)
]);
return json({
currently_reading: currentlyReading.map((item) => ({
book: item.book,
last_chapter: item.chapter,
saved: false
})),
library: library.map((item) => ({
book: item.book,
last_chapter: item.chapter,
saved: item.saved
}))
});
} catch (e) {
log.error('api/users/library', 'failed to load library', { username, err: String(e) });
error(500, 'Failed to load library');
}
};