Repository navigation
feat: let clients set a book's genres #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
itsthisjustin
merged 3 commits into
crosspoint-reader:main
from
eszter007:feat/manual-genres
Oct 24, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- Genres set through PUT /api/v1/documents/:document/info stick over Hardcover lookups. | ||
| ALTER TABLE documents ADD COLUMN genres_manual INTEGER NOT NULL DEFAULT 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { beforeEach, describe, expect, it } from 'vitest'; | ||
| import type { HttpTransport } from '../src/connectors/types.js'; | ||
| import { documentInfo } from '../src/models/cover.js'; | ||
| import { resetHardcoverThrottle } from '../src/models/hardcover-catalog.js'; | ||
| import { DOC, makeTestApp, registerUser } from './helpers.js'; | ||
|
|
||
| // Hardcover finds the book with its own genres; the free cover sources find nothing. | ||
| const hardcover: HttpTransport = async (url) => { | ||
| const hit = { id: '41398', slug: 'foundryside', title: 'Foundryside', author_names: ['Robert Jackson Bennett'], genres: ['Fantasy', 'Magic'] }; | ||
| const body = url.includes('hardcover') ? { data: { search: { results: { hits: [{ document: hit }] } } } } : {}; | ||
| return { status: 200, text: async () => JSON.stringify(body), json: async () => body }; | ||
| }; | ||
|
|
||
| beforeEach(() => resetHardcoverThrottle()); | ||
|
|
||
| describe('manual genres', () => { | ||
| it('sticks over Hardcover lookups and clears back to them', async () => { | ||
| const { app, db } = makeTestApp(); | ||
| const { username, headers } = await registerUser(app); | ||
| await app.request('/syncs/progress', { | ||
| method: 'PUT', | ||
| headers, | ||
| body: JSON.stringify({ document: DOC, progress: '/body/DocFragment[2]', percentage: 0.2, device: 'X4', device_id: 'x4', | ||
| metadata: { title: 'Foundryside', authors: 'Robert Jackson Bennett' } }), | ||
| }); | ||
| const { id } = db.prepare('SELECT id FROM users WHERE username = ?').get(username) as { id: number }; | ||
| const put = (body: unknown) => app.request(`/api/v1/documents/${DOC}/info`, { method: 'PUT', headers, body: JSON.stringify(body) }); | ||
| const listed = async () => ((await (await app.request('/api/v1/progress', { headers })).json()) as { items: { genres: string[] }[] }).items[0].genres; | ||
| const enrich = () => documentInfo(db, id, DOC, hardcover, { HARDCOVER_API_KEY: 'k' }, { hardcover: true }); | ||
|
|
||
| expect((await put({ genres: 'Fantasy' })).status).toBe(403); | ||
| expect((await put({ genres: [''] })).status).toBe(403); | ||
| expect((await put({ genres: ['x'.repeat(65)] })).status).toBe(403); | ||
| expect((await put({ genres: Array.from({ length: 11 }, (_, i) => `g${i}`) })).status).toBe(403); | ||
|
|
||
| // Trimmed and de-duplicated, and back in the book list. | ||
| expect(await (await put({ genres: [' Heist ', 'Heist', 'Fantasy'] })).json()).toMatchObject({ genres: ['Heist', 'Fantasy'] }); | ||
| expect(await listed()).toEqual(['Heist', 'Fantasy']); | ||
|
|
||
| // Hardcover's lookup fills the other details but leaves the genres alone. | ||
| await enrich(); | ||
| expect(await listed()).toEqual(['Heist', 'Fantasy']); | ||
| expect(db.prepare('SELECT hc_slug FROM documents WHERE document = ?').get(DOC)).toEqual({ hc_slug: 'foundryside' }); | ||
|
|
||
| // null hands them back: the next lookup brings Hardcover's genres. | ||
| expect(await (await put({ genres: null })).json()).toMatchObject({ genres: [] }); | ||
| await enrich(); | ||
| expect(await listed()).toEqual(['Fantasy', 'Magic']); | ||
|
|
||
| // Other info edits don't touch manual genres. | ||
| await put({ genres: ['Heist'] }); | ||
| await put({ page_count: 500 }); | ||
| expect(await listed()).toEqual(['Heist']); | ||
| }); | ||
|
|
||
| it('keeps manual genres through a merge, over Hardcover\'s', async () => { | ||
| const { app, db } = makeTestApp(); | ||
| const { headers } = await registerUser(app); | ||
| const OTHER = 'ffffffffffffffffffffffffffffffff'; | ||
| for (const document of [DOC, OTHER]) { | ||
| await app.request('/syncs/progress', { | ||
| method: 'PUT', | ||
| headers, | ||
| body: JSON.stringify({ document, progress: '/body/DocFragment[2]', percentage: 0.2, device: 'X4', device_id: 'x4', | ||
| metadata: { title: 'Foundryside', authors: 'Robert Jackson Bennett' } }), | ||
| }); | ||
| } | ||
| // The kept book only has Hardcover's genres; the merged-away one has some set by hand. | ||
| db.prepare('UPDATE documents SET genres = ? WHERE document = ?').run('["Fantasy"]', DOC); | ||
| await app.request(`/api/v1/documents/${OTHER}/info`, { method: 'PUT', headers, body: JSON.stringify({ genres: ['Heist'] }) }); | ||
|
|
||
| const merge = await app.request('/api/v1/documents/merge', { method: 'POST', headers, body: JSON.stringify({ document: OTHER, into: DOC }) }); | ||
| expect(merge.status).toBe(200); | ||
| expect(db.prepare('SELECT genres, genres_manual FROM documents WHERE document = ?').get(DOC)).toEqual({ genres: '["Heist"]', genres_manual: 1 }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.