Socket
Socket
Sign inDemoInstall

list-fetch

Package Overview
Dependencies
220
Maintainers
1
Versions
169
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 26.0.2 to 26.0.3

118

index.js

@@ -15,3 +15,3 @@ module.exports = async function makeBTFetch (opts = {}) {

const checkTitle = /^[a-zA-Z0-9]{16}$/
const SUPPORTED_METHODS = ['GET', 'POST', 'DELETE', 'HEAD']
// const SUPPORTED_METHODS = ['GET', 'POST', 'DELETE', 'HEAD']
const hostType = '_'

@@ -23,2 +23,12 @@

function handleFormData(formdata) {
const arr = []
for (const [name, info] of formdata) {
if (name === 'file') {
arr.push(info)
}
}
return arr
}
function handleTorrent(torrent){

@@ -195,4 +205,4 @@ let test = '<div>'

if(reqHeaders.has('x-data') || searchParams.has('x-data')){
const torrentData = await app.torrentData(JSON.parse(reqHeaders.get('x-data') || searchParams.get('x-data')))
return sendTheData(signal, {status: 200, headers: {'X-Length': `${torrentData.length}`}, body: []})
const torrentData = await app.torrentData(JSON.parse(reqHeaders.get('x-data') || searchParams.get('x-data')))
return sendTheData(signal, {status: 200, headers: {'X-Length': `${torrentData.length}`}, body: []})
} else {

@@ -204,4 +214,8 @@ const torrentData = await app.authorData()

if (reqHeaders.has('x-copy') || searchParams.has('x-copy')) {
const torrentData = await app.userTorrent(mid.mainId, mid.mainPath, {id: JSON.parse(reqHeaders.get('x-copy') || searchParams.get('x-copy'))})
return sendTheData(signal, {status: 200, headers: {'X-Path': torrentData}, body: []})
try {
const torrentData = await app.userTorrent(mid.mainId, mid.mainPath, {id: JSON.parse(reqHeaders.get('x-copy') || searchParams.get('x-copy'))})
return sendTheData(signal, {status: 200, headers: {'X-Path': torrentData}, body: []})
} catch (error) {
return sendTheData(signal, {status: 400, headers: {'X-Error': error.name}, data: []})
}
} else {

@@ -216,2 +230,4 @@ const torrentData = await app.loadTorrent(mid.mainId, mid.mainPath, {timeout: (reqHeaders.has('x-timer') && reqHeaders.get('x-timer') !== '0') || (searchParams.has('x-timer') && searchParams.get('x-timer') !== '0') ? Number(reqHeaders.get('x-timer') || searchParams.get('x-timer')) : 0})

useHeaders['X-Downloaded'] = `${torrentData.downloaded}`
useHeaders['X-Link'] = `bt://${mid.mainHost}${mid.mainPath}`
useHeaders['Link'] = `<bt://${mid.mainHost}${mid.mainPath}>; rel="canonical"`

@@ -223,3 +239,3 @@ return sendTheData(signal, {status: 200, headers: useHeaders, body: []})

sendTheData(signal, {status: 200, headers: {'Content-Length': String(checkLength)}, body: []})
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 {

@@ -231,2 +247,4 @@ const useHeaders = {}

useHeaders['X-Downloaded'] = `${torrentData.downloaded}`
useHeaders['X-Link'] = `bt://${mid.mainHost}${mid.mainPath}`
useHeaders['Link'] = `<bt://${mid.mainHost}${mid.mainPath}>; rel="canonical"`

@@ -236,3 +254,3 @@ return sendTheData(signal, {status: 200, headers: useHeaders, body: []})

} else {
return sendTheData(signal, {status: 400, headers: {'Content-Length': '0'}, body: []})
return sendTheData(signal, {status: 400, headers: {'X-Error': 'did not find any data'}, body: []})
}

@@ -259,4 +277,4 @@ }

if(reqHeaders.has('x-data') || searchParams.has('x-data')){
const torrentData = await app.torrentData(JSON.parse(reqHeaders.get('x-data') || searchParams.get('x-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(htmlIden) : '<p>there are no data</p>'}</div></body></html>`] : [JSON.stringify(torrentData.map(jsonIden))]})
const torrentData = await app.torrentData(JSON.parse(reqHeaders.get('x-data') || searchParams.get('x-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(htmlIden) : '<p>there are no data</p>'}</div></body></html>`] : [JSON.stringify(torrentData.map(jsonIden))]})
} else {

@@ -267,26 +285,24 @@ const torrentData = await app.authorData()

} else {
const mainRange = reqHeaders.has('Range') || reqHeaders.has('range')
const torrentData = await app.loadTorrent(mid.mainId, mid.mainPath, {timeout: (reqHeaders.has('x-timer') && reqHeaders.get('x-timer') !== '0') || (searchParams.has('x-timer') && searchParams.get('x-timer') !== '0') ? Number(reqHeaders.get('x-timer') || searchParams.get('x-timer')) : 0})
if(torrentData){
if(torrentData.infoHash){
return sendTheData(signal, {status: 200, headers: {'Content-Type': mainRes, 'Content-Length': String(torrentData.length)}, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div><h1>${torrentData.infohash}</h1>${torrentData.files.map(file => { return `<p><a href='${file.urlPath}'>${file.name}</a></p>` })}</div></body></html>`] : [JSON.stringify(torrentData.files.map(file => { return file.urlPath }))]})
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(torrentData.length)}, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div><h1>${torrentData.infohash}</h1>${torrentData.files.map(file => { return `<p><a href='${file.urlPath}'>${file.name}</a></p>` })}</div></body></html>`] : [JSON.stringify(torrentData.files.map(file => { return file.urlPath }))]})
} else if (Array.isArray(torrentData)) {
let checkLength = 0
torrentData.forEach((data) => {checkLength = checkLength + data.length})
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 {
if(Array.isArray(torrentData)){
let checkLength = 0
torrentData.forEach((data) => {checkLength = checkLength + data.length})
return sendTheData(signal, {status: 200, headers: {'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 {
if (mainRange) {
const ranges = parseRange(torrentData.length, mainRange)
if (ranges && ranges.length && ranges.type === 'bytes') {
const [{ start, end }] = ranges
const length = (end - start + 1)
const mainRange = reqHeaders.has('Range') || reqHeaders.has('range')
if (mainRange) {
const ranges = parseRange(torrentData.length, mainRange)
if (ranges && ranges.length && ranges.type === 'bytes') {
const [{ start, end }] = ranges
const length = (end - start + 1)
return sendTheData(signal, {status: 206, headers: {'Content-Length': `${length}`, 'Content-Range': `bytes ${start}-${end}/${torrentData.length}`, 'Content-Type': getMimeType(torrentData.path)}, body: streamToIterator(torrentData.createReadStream({ start, end }))})
} else {
return sendTheData(signal, {status: 416, headers: {'Content-Type': getMimeType(torrentData.path), 'Content-Length': String(torrentData.length)}, body: ['range is not satisfiable']})
}
return sendTheData(signal, {status: 206, headers: {'X-Link': `bt://${mid.mainHost}${mid.mainPath}`, 'Link': `<bt://${mid.mainHost}${mid.mainPath}>; rel="canonical"`, 'Content-Length': `${length}`, 'Content-Range': `bytes ${start}-${end}/${torrentData.length}`, 'Content-Type': getMimeType(torrentData.path)}, body: streamToIterator(torrentData.createReadStream({ start, end }))})
} else {
return sendTheData(signal, {status: 200, headers: {'Content-Type': getMimeType(torrentData.path), 'Content-Length': String(torrentData.length)}, body: streamToIterator(torrentData.createReadStream())})
return sendTheData(signal, {status: 416, headers: {'Content-Type': mainRes, 'Content-Length': String(torrentData.length)}, body: mainReq ? ['<html><head><title>range</title></head><body><div><p>malformed or unsatisfiable range</p></div></body></html>'] : [JSON.stringify('malformed or unsatisfiable range')]})
}
} else {
return sendTheData(signal, {status: 200, headers: {'Content-Type': getMimeType(torrentData.path), 'X-Link': `bt://${mid.mainHost}${mid.mainPath}`, 'Link': `<bt://${mid.mainHost}${mid.mainPath}>; rel="canonical"`, 'Content-Length': String(torrentData.length)}, body: streamToIterator(torrentData.createReadStream())})
}

@@ -320,11 +336,11 @@ }

}
const formData = { form: reqHeaders.has('content-type') && reqHeaders.get('content-type').includes('multipart/form-data') }
formData.data = formData.form ? await request.formData() : body
if((reqHeaders.has('x-update') && JSON.parse(reqHeaders.get('x-update'))) || (searchParams.has('x-update') && JSON.parse(searchParams.get('x-update')))){
const torrentData = await app.publishTorrent({address: null, secret: null}, mid.mainPath, formData, useOpts)
return sendTheData(signal, {status: 200, headers: {'Content-Length': String(torrentData.length), 'Content-Type': mainRes, 'X-Id': torrentData.id, 'X-Sequence': torrentData.sequence, 'X-Title': torrentData.title, 'X-Secret': torrentData.secret, 'X-Address': torrentData.address, 'X-Infohash': torrentData.infohash}, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div>${JSON.stringify(torrentData.saved.map((data) => {return path.join('bt://', mid.mainPath, data).replace(/\\/g, "/")}))}</div></body></html>`] : [JSON.stringify(torrentData.saved.map((data) => {return path.join('bt://', mid.mainPath, data).replace(/\\/g, "/")}))]})
} else {
const torrentData = await app.publishTorrent({infohash: null}, mid.mainPath, formData, useOpts)
return sendTheData(signal, {status: 200, headers: {'Content-Length': String(torrentData.length), 'Content-Type': mainRes, 'X-Infohash': torrentData.infohash, 'X-Id': torrentData.id}, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div>${JSON.stringify(torrentData.saved.map(data => {return path.join('bt://', mid.mainPath, data).replace(/\\/g, "/")}))}</div></body></html>`] : [JSON.stringify(torrentData.saved.map(data => {return path.join('bt://', mid.mainPath, data).replace(/\\/g, "/")}))]})
const useBody = reqHeaders.has('content-type') && reqHeaders.get('content-type').includes('multipart/form-data') ? handleFormData(await request.formData()) : body
const torrentData = (reqHeaders.has('x-update') && JSON.parse(reqHeaders.get('x-update'))) || (searchParams.has('x-update') && JSON.parse(searchParams.get('x-update'))) ? await app.publishTorrent({ address: null, secret: null }, mid.mainPath, useBody, useOpts) : await app.publishTorrent({ infohash: null }, mid.mainPath, useBody, useOpts)
const useHeaders = {}
for (const test of ['sequence', 'title', 'infohash', 'dir', 'secret', 'address']) {
if (torrentData[test]) {
useHeaders[test] = torrentData[test]
}
}
return sendTheData(signal, {status: 200, headers: {'X-Link': `bt://${mid.mainHost}${mid.mainPath}`, 'Link': `<bt://${mid.mainHost}${mid.mainPath}>; rel="canonical"`, 'Content-Length': String(torrentData.length), 'Content-Type': mainRes, ...useHeaders}, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div>${JSON.stringify(torrentData.saved)}</div></body></html>`] : [JSON.stringify(torrentData.saved)]})
} else {

@@ -336,11 +352,11 @@ const useOpts = {

}
const formData = { form: reqHeaders.has('content-type') && reqHeaders.get('content-type').includes('multipart/form-data') }
formData.data = formData.form ? await request.formData() : body
if(reqHeaders.has('x-authentication') || searchParams.has('x-authentication')){
const torrentData = await app.publishTorrent(mid.mainId, mid.mainPath, formData, useOpts)
return sendTheData(signal, {status: 200, headers: {'Content-Length': String(torrentData.length), 'Content-Type': mainRes, 'X-Id': torrentData.id, 'X-Sequence': torrentData.sequence, 'X-Secret': torrentData.secret, 'X-Address': torrentData.address, 'X-Title': torrentData.title, 'X-Infohash': torrentData.infohash}, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div>${JSON.stringify(torrentData.saved.map(data => {return path.join('bt://', mid.mainPath, data).replace(/\\/g, "/")}))}</div></body></html>`] : [JSON.stringify(torrentData.saved.map(data => {return path.join('bt://', mid.mainPath, data).replace(/\\/g, "/")}))]})
} else {
const torrentData = await app.publishTorrent(mid.mainId, mid.mainPath, formData, useOpts)
return sendTheData(signal, {status: 200, headers: {'Content-Length': String(torrentData.length), 'Content-Type': mainRes, 'X-Infohash': torrentData.infohash, 'X-Id': torrentData.id}, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div>${JSON.stringify(torrentData.saved.map(data => {return path.join('bt://', mid.mainPath, data).replace(/\\/g, "/")}))}</div></body></html>`] : [JSON.stringify(torrentData.saved.map(data => {return path.join('bt://', mid.mainPath, data).replace(/\\/g, "/")}))]})
const useBody = reqHeaders.has('content-type') && reqHeaders.get('content-type').includes('multipart/form-data') ? handleFormData(await request.formData()) : body
const torrentData = await app.publishTorrent(mid.mainId, mid.mainPath, useBody, useOpts)
const useHeaders = {}
for (const test of ['sequence', 'title', 'infohash', 'dir', 'secret', 'address']) {
if (torrentData[test]) {
useHeaders[test] = torrentData[test]
}
}
return sendTheData(signal, { status: 200, headers: { 'X-Link': `bt://${mid.mainHost}${mid.mainPath}`, 'Link': `<bt://${mid.mainHost}${mid.mainPath}>; rel="canonical"`, 'Content-Length': String(torrentData.length), 'Content-Type': mainRes, ...useHeaders }, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div>${JSON.stringify(torrentData.saved)}</div></body></html>`] : [JSON.stringify(torrentData.saved)] })
}

@@ -368,17 +384,9 @@ }

const useHead = {}
if(torrentData.torrent.address){
useHead['X-Address'] = torrentData.torrent.address
for (const test of ['id', 'path', 'infohash', 'title', 'address']) {
if (torrentData[test]) {
useHead[test] = torrentData[test]
}
}
if(torrentData.torrent.secret){
useHead['X-Secret'] = torrentData.torrent.secret
}
if(torrentData.torrent.title){
useHead['X-Title'] = torrentData.torrent.title
}
if(torrentData.torrent.infohash){
useHead['X-Infohash'] = torrentData.torrent.infohash
}
const useData = useHead['X-Address'] || useHead['X-Infohash'] || torrentData.id
return sendTheData(signal, {status: 200, headers: {'Content-Type': mainRes, 'X-Id': torrentData.id, ...useHead}, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div>${JSON.stringify({tid: torrentData.id, path: torrentData.path, link: `bt://${useData}/`})}</div></body></html>`] : [JSON.stringify({tid: torrentData.id, path: torrentData.path, link: `bt://${useData}/`})]})
return sendTheData(signal, {status: 200, headers: {'Content-Type': mainRes, ...useHead}, body: mainReq ? [`<html><head><title>${mid.mainLink}</title></head><body><div>${JSON.stringify(torrentData)}</div></body></html>`] : [JSON.stringify(torrentData)]})
}

@@ -385,0 +393,0 @@ }

{
"name": "list-fetch",
"version": "26.0.2",
"version": "26.0.3",
"description": "coming soon",

@@ -25,3 +25,3 @@ "main": "index.js",

"stream-async-iterator": "^2.0.0",
"torrentz": "^8.0.3"
"torrentz": "^8.0.4"
},

@@ -28,0 +28,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc