Rebuild: NZBs from the chunk store, and a catalog search
lib/nzb (buildNzb, parseNzb) from the current app; NzbService builds a release's NZB from its chunks; GET /api/v1/releases?q= (every word of the name) and GET /api/v1/releases/:id/nzb behind the api guard. A test stores a batch, finds the release and reads its NZB back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e9592dfd33
commit
fde1e6cc90
15 files changed
+446
-2
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { test } from '@japa/runner'
|
||||
import { buildNzb } from '#lib/nzb/index'
|
||||
|
||||
test.group('nzb / buildNzb', () => {
|
||||
test('writes files, groups and ordered segments', ({ assert }) => {
|
||||
const xml = buildNzb(
|
||||
[
|
||||
{
|
||||
name: 'Some.Show.S01E01.mkv',
|
||||
poster: 'poster@example.invalid',
|
||||
date: 1_790_000_000_000,
|
||||
groups: ['alt.binaries.test'],
|
||||
segments: [{ number: 2, id: 'b@x', size: 700 }, { number: 1, id: 'a@x', size: 800 }],
|
||||
},
|
||||
],
|
||||
{ title: 'Some.Show.S01E01' }
|
||||
)
|
||||
assert.include(xml, '<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.1//EN"')
|
||||
assert.include(xml, '<meta type="name">Some.Show.S01E01</meta>')
|
||||
assert.include(xml, 'subject=""Some.Show.S01E01.mkv" yEnc (1/2)"')
|
||||
assert.include(xml, 'date="1790000000"')
|
||||
assert.include(xml, '<group>alt.binaries.test</group>')
|
||||
assert.isBelow(xml.indexOf('>a@x<'), xml.indexOf('>b@x<'))
|
||||
assert.include(xml, '<segment bytes="800" number="1">a@x</segment>')
|
||||
})
|
||||
})
|
||||
|
||||
test.group('nzb / parseNzb', () => {
|
||||
test('reads meta, files, groups and segments, decoding entities', async ({ assert }) => {
|
||||
const { parseNzb } = await import('#lib/nzb/index')
|
||||
const xml = `<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 0.9//EN" "http://www.newzbin.com/DTD/nzb/nzb-0.9.dtd">
|
||||
<nzb xmlns="http://www.newzbin.com/DTD/2003/nzb">
|
||||
<head><meta type="name">Some.Show.S01E01</meta><meta type="password">s3cr&t</meta></head>
|
||||
<file poster="Yenc@power-post.org (Cosmo71)" date="1790598923" subject="Wond40 "Nachbe" x.part1.rar" yEnc (0001/2)">
|
||||
<groups><group>alt.binaries.bloaf</group></groups>
|
||||
<segments>
|
||||
<segment bytes="1000" number="2">b@x.local</segment>
|
||||
<segment bytes="2000" number="1"><a@x.local></segment>
|
||||
</segments>
|
||||
</file>
|
||||
<file poster="p" date="1" subject="empty"><groups/><segments></segments></file>
|
||||
</nzb>`
|
||||
const nzb = parseNzb(xml)!
|
||||
assert.deepEqual(nzb.meta, { name: 'Some.Show.S01E01', password: 's3cr&t' })
|
||||
assert.lengthOf(nzb.files, 1)
|
||||
assert.equal(nzb.files[0].subject, 'Wond40 "Nachbe" x.part1.rar" yEnc (0001/2)')
|
||||
assert.deepEqual(nzb.files[0].groups, ['alt.binaries.bloaf'])
|
||||
assert.deepEqual(nzb.files[0].segments, [
|
||||
{ number: 1, bytes: 2000, id: 'a@x.local' },
|
||||
{ number: 2, bytes: 1000, id: 'b@x.local' },
|
||||
])
|
||||
assert.isNull(parseNzb('<html>not an nzb</html>'))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user