Books: read DRM-free MOBI, AZW and AZW3; refuse Kindle files with DRM
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UaC9HmtHMdRP8dAbN4wAKj
This commit is contained in:
7 files changed
+138
-21
No files matched your search
+6
-2
@@ -15,7 +15,11 @@ const hub = http.createServer((req, res) => users.runAs(req.headers['x-user'] ==
|
||||
r = await up('d.docx', docx); assert.equal(r.status, 200);
|
||||
assert.equal((await up('fake.pdf', Buffer.from('<html>not a pdf</html>'))).status, 400, 'a file must look like what its name says');
|
||||
assert.equal((await up('fake.epub', pdf)).status, 400); assert.equal((await up('x.exe', epub)).status, 400); assert.equal((await up('plain.docx', epub)).status, 400, 'an EPUB is not a DOCX');
|
||||
assert.equal((await call('/list')).status, 200); assert.equal((await (await call('/list')).json()).length, 3);
|
||||
const mobi = fs.readFileSync(path.join(fx, 'test.mobi')), drm = fs.readFileSync(path.join(fx, 'drm.mobi'));
|
||||
r = await up('k.azw3', mobi); assert.equal(r.status, 200); assert.equal((await r.json()).ext, 'azw3', 'DRM-free Kindle files are accepted');
|
||||
r = await up('locked.mobi', drm); assert.equal(r.status, 400); assert.match((await r.json()).error, /DRM/, 'books with DRM are refused with a clear reason');
|
||||
assert.equal((await up('fake.mobi', pdf)).status, 400, 'a MOBI must look like one');
|
||||
assert.equal((await call('/list')).status, 200); assert.equal((await (await call('/list')).json()).length, 4);
|
||||
assert.equal((await (await call('/list', { headers: { 'x-user': 'b' } })).json()).length, 0, 'each person has their own shelf');
|
||||
assert.equal((await call('/book/' + e.id + '/file', { headers: { 'x-user': 'b' } })).status, 404, "nobody can open another person's book");
|
||||
r = await call('/book/' + p.id + '/file', { headers: { range: 'bytes=0-4' } }); assert.equal(r.status, 206); assert.equal(await r.text(), '%PDF-'); assert.equal(r.headers.get('content-range'), `bytes 0-4/${pdf.length}`);
|
||||
@@ -34,7 +38,7 @@ const hub = http.createServer((req, res) => users.runAs(req.headers['x-user'] ==
|
||||
assert.deepEqual(ns.map(n => n.id).sort(), ['n1', 'n2'], 'two devices add notes without losing each other'); assert.equal(ns.find(n => n.id === 'n1').text, 'hello', 'an older edit does not win');
|
||||
ns = await note([{ id: 'n1', t: 20, del: true, loc: 'y' }]); assert.deepEqual(ns.map(n => n.id), ['n2'], 'deleted notes stay deleted');
|
||||
assert.equal((await (await call('/book/' + e.id + '/notes')).json()).length, 1);
|
||||
assert.equal((await call('/book/' + e.id, { method: 'DELETE' })).status, 200); assert.equal((await (await call('/list')).json()).length, 2);
|
||||
assert.equal((await call('/book/' + e.id, { method: 'DELETE' })).status, 200); assert.equal((await (await call('/list')).json()).length, 3);
|
||||
assert.equal((await call('/book/' + e.id + '/file')).status, 404);
|
||||
assert.equal((await call('/nope')).status, 404);
|
||||
console.log('books test ok');
|
||||
|
||||
Reference in new issue
Block a user