list-fetch
Advanced tools
Comparing version 27.0.1 to 27.0.2
25
index.js
@@ -14,3 +14,2 @@ module.exports = async function makeBTFetch (opts = {}) { | ||
const checkAddress = /^[a-fA-F0-9]{64}$/ | ||
const checkTitle = /^[a-zA-Z0-9]{16}$/ | ||
// const SUPPORTED_METHODS = ['GET', 'POST', 'DELETE', 'HEAD'] | ||
@@ -112,4 +111,2 @@ const hostType = '_' | ||
mainId.infohash = mainHost | ||
} else if(checkTitle.test(mainHost)){ | ||
mainId.title = mainHost | ||
} else { | ||
@@ -173,3 +170,3 @@ throw new Error('identifier is invalid') | ||
sendTheData(signal, {status: 200, headers: {'X-Link': `bt://${mid.mainHost}${mid.mainPath}`, 'Link': `<bt://${mid.mainHost}${mid.mainPath}>; rel="canonical"`,'Content-Length': String(checkLength)}, body: ''}) | ||
} else { | ||
} else if(torrentData.createReadStream){ | ||
const useHeaders = {} | ||
@@ -184,2 +181,4 @@ useHeaders['Content-Type'] = getMimeType(torrentData.path) | ||
return sendTheData(signal, {status: 200, headers: useHeaders, body: ''}) | ||
} else { | ||
return sendTheData(signal, { status: 400, headers: { 'X-Error': 'did not find any data' }, body: '' }) | ||
} | ||
@@ -213,3 +212,3 @@ } else { | ||
const torrentData = await app.authorData() | ||
return sendTheData(signal, {status: 200, headers: {'Content-Type': mainRes}, body: mainReq ? `<html><head><title>${mid.mainLink}</title></head><body><div>${torrentData.length ? torrentData.map((data) => {if(data.address){data.link = `<a href='bt://${data.address}/'>${data.address}</a>`} else if(data.title){data.link = `<a href='bt://${data.infohash}/'>${data.infohash}</a>`} return `<p>${JSON.stringify(data)}</p>`;}) : '<p>there are no data</p>'}</div></body></html>` : JSON.stringify(torrentData.map((data) => {if(data.address){data.link = `bt://${data.address}/`} else if(data.title){data.link = `bt://${data.infohash}/`} return data;}))}) | ||
return sendTheData(signal, {status: 200, headers: {'Content-Type': mainRes}, body: mainReq ? `<html><head><title>${mid.mainLink}</title></head><body><div>${torrentData.length ? torrentData.map((data) => {if(data.address){data.link = `<a href='bt://${data.address}/'>${data.address}</a>`} else {data.link = `<a href='bt://${data.infohash}/'>${data.infohash}</a>`} return `<p>${JSON.stringify(data)}</p>`;}) : '<p>there are no data</p>'}</div></body></html>` : JSON.stringify(torrentData.map((data) => {if(data.address){data.link = `bt://${data.address}/`} else {data.link = `bt://${data.infohash}/`} return data;}))}) | ||
} | ||
@@ -226,3 +225,3 @@ } else { | ||
return sendTheData(signal, {status: 200, headers: {'X-Link': `bt://${mid.mainHost}${mid.mainPath}`, 'Link': `<bt://${mid.mainHost}${mid.mainPath}>; rel="canonical"`, 'Content-Type': mainRes, 'Content-Length': String(checkLength)}, body: mainReq ? `<html><head><title>${mid.mainLink}</title></head><body><div><h1>Directory</h1><p><a href='../'>..</a></p>${torrentData.map(file => { return `<p><a href='${file.urlPath}'>${file.name}</a></p>` })}</div></body></html>` : JSON.stringify(torrentData.map(file => { return file.urlPath }))}) | ||
} else { | ||
} else if(torrentData.createReadStream){ | ||
const mainRange = reqHeaders.has('Range') || reqHeaders.has('range') | ||
@@ -242,2 +241,4 @@ if (mainRange) { | ||
} | ||
} else { | ||
return sendTheData(signal, { status: 400, headers: { 'Content-Type': mainRes }, body: mainReq ? `<html><head><title>${mid.mainLink}</title></head><body><div><p>could not find the data</p></div></body></html>` : JSON.stringify('could not find the data') }) | ||
} | ||
@@ -272,4 +273,4 @@ } else { | ||
const useHeaders = {} | ||
for (const test of ['sequence', 'title', 'infohash', 'dir', 'secret', 'address']) { | ||
if (torrentData[test]) { | ||
for (const test of ['sequence', 'name', 'infohash', 'dir', 'pair', 'secret', 'address']) { | ||
if (torrentData[test] || typeof(torrentData[test]) === 'number') { | ||
useHeaders[test] = torrentData[test] | ||
@@ -287,4 +288,4 @@ } | ||
const useHeaders = {} | ||
for (const test of ['sequence', 'title', 'infohash', 'dir', 'secret', 'address']) { | ||
if (torrentData[test]) { | ||
for (const test of ['sequence', 'name', 'infohash', 'dir', 'pair', 'secret', 'address']) { | ||
if (torrentData[test] || typeof(torrentData[test]) === 'number') { | ||
useHeaders[test] = torrentData[test] | ||
@@ -297,3 +298,3 @@ } | ||
async function handleDelete(request) { | ||
async function handleDelete(request) { | ||
const { url, method, headers: reqHeaders, body, signal } = request | ||
@@ -317,3 +318,3 @@ | ||
const useHead = {} | ||
for (const test of ['id', 'path', 'infohash', 'title', 'address']) { | ||
for (const test of ['id', 'path', 'infohash', 'dir', 'name', 'sequence', 'pair', 'address']) { | ||
if (torrentData[test]) { | ||
@@ -320,0 +321,0 @@ useHead[test] = torrentData[test] |
{ | ||
"name": "list-fetch", | ||
"version": "27.0.1", | ||
"version": "27.0.2", | ||
"description": "coming soon", | ||
@@ -24,3 +24,3 @@ "main": "index.js", | ||
"range-parser": "^1.2.1", | ||
"torrentz": "^9.0.2" | ||
"torrentz": "^9.0.3" | ||
}, | ||
@@ -27,0 +27,0 @@ "devDependencies": { |
21297
322
Updatedtorrentz@^9.0.3