Socket
Socket
Sign inDemoInstall

list-fetch

Package Overview
Dependencies
Maintainers
1
Versions
169
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

list-fetch - npm Package Compare versions

Comparing version 29.0.1 to 29.0.2

78

index.js
module.exports = async function makeBTFetch (opts = {}) {
const {makeRoutedFetch} = await import('make-fetch')
const {Readable} = require('stream')
const {fetch, router} = makeRoutedFetch({onNotFound: handleEmpty, onError: handleError})

@@ -124,8 +125,39 @@ // const streamToIterator = require('stream-async-iterator')

if (mid.mainQuery) {
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}`, 'X-Count': `${torrentData.count}`}, body: ''})
if(mid.mainPath === '/'){
if(reqHeaders.has('x-data') || searchParams.has('x-data')){
const parseTheData = JSON.parse(reqHeaders.get('x-data') || searchParams.get('x-data'))
const torrentData = await app.torrentData(parseTheData)
const useHeaders = {}
const useCount = torrentData.length
let useLength = 0
for(const test of torrentData){
if(test.length){
useLength = useLength + test.length
}
}
useHeaders['X-Count'] = useCount
if(useLength){
useHeaders['X-Length'] = useLength
}
return sendTheData(signal, {status: 200, headers: useHeaders, body: ''})
} else {
const torrentData = await app.authorData()
const useHeaders = {}
const useCount = torrentData.length
let useLength = 0
for(const test of torrentData){
useLength = useLength + test.length
}
useHeaders['X-Count'] = useCount
useHeaders['X-Length'] = useLength
return sendTheData(signal, {status: 200, headers: useHeaders, body: ''})
}
} else {
const torrentData = await app.authorData()
return sendTheData(signal, {status: 200, headers: {'X-Length': `${torrentData.length}`, 'X-Count': `${torrentData.count}`}, body: ''})
const checkMain = await app.checkUserData(mid.mainPath)
const useHeaders = {}
if(checkMain.stat.type === 'folder'){
useHeaders['X-Count'] = checkMain.folder.length
}
useHeaders['X-Length'] = checkMain.stat.size
return sendTheData(signal, {status: 200, headers: useHeaders, body: ''})
}

@@ -141,3 +173,3 @@ } else {

if (Array.isArray(torrentData)) {
const useHeaders = { 'Content-Length': 0, 'Accept-Ranges': 'bytes', 'X-Downloaded': 0, 'X-Link': `bt://${mid.mainHost}${mid.mainPath}` }
const useHeaders = { 'Content-Length': 0, 'X-Downloaded': 0, 'X-Link': `bt://${mid.mainHost}${mid.mainPath}` }
useHeaders['Link'] = `<${useHeaders['X-Link']}>; rel="canonical"`

@@ -170,3 +202,3 @@ torrentData.forEach((data) => {

async function handleGet(request) {
async function handleGet(request) {
const { url, method, headers: reqHeaders, body, signal } = request

@@ -186,8 +218,27 @@

if (mid.mainQuery) {
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.map(htmlIden)}</div></body></html>` : JSON.stringify(torrentData.map(jsonIden))})
if(mid.mainPath === '/'){
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.map(htmlIden)}</div></body></html>` : JSON.stringify(torrentData.map(jsonIden))})
} 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.map(htmlIden)}</div></body></html>` : JSON.stringify(torrentData.map(jsonIden))})
}
} 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.map(htmlIden)}</div></body></html>` : JSON.stringify(torrentData.map(jsonIden))})
const checkMain = await app.checkUserData(mid.mainPath)
const useHeaders = {}
if(checkMain.stat.type === 'folder'){
useHeaders['X-length'] = checkMain.stat.size
useHeaders['X-Count'] = checkMain.folder.length
return sendTheData(signal, {status: 200, headers: useHeaders, body: mainReq ? `<html><head><title>${mid.mainLink}</title></head><body><div><h1>Directory</h1><p><a href='../'>..</a></p>${checkMain.folder.map((data) => {return `<p>${data}</p>`})}</div></body></html>` : JSON.stringify(checkMain.folder)})
} else if(checkMain.stat.type === 'file'){
useHeaders['X-length'] = checkMain.stat.size
useHeaders['Content-Type'] = getMimeType(mid.mainPath)
useHeaders['X-Link'] = `bt://${mid.mainHost}${mid.mainPath}`
useHeaders['Link'] = `<bt://${mid.mainHost}${mid.mainPath}>; rel="canonical"`
useHeaders['Content-Length'] = useHeaders['X-length']
return sendTheData(signal, {status: 200, headers: useHeaders, body: Readable.from(checkMain.file)})
} else {
return sendTheData(signal, {status: 400, headers: 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')})
}
}

@@ -301,3 +352,4 @@ } else {

if (mid.mainQuery) {
return sendTheData(signal, { status: 400, headers: { 'Content-Type': mainRes }, body: mainReq ? `<html><head><title>${mid.mainLink}</title></head><body><div><p>must not use underscore</p></div></body></html>` : JSON.stringify('must not use underscore') })
const torrentData = await app.trashUserData(mid.mainPath)
return sendTheData(signal, { status: 200, headers: { 'Content-Type': mainRes }, body: mainReq ? `<html><head><title>${mid.mainLink}</title></head><body><div><p>${torrentData}</p></div></body></html>` : JSON.stringify(torrentData) })
} else {

@@ -304,0 +356,0 @@ const torrentData = await app.shredTorrent(mid.mainId, mid.mainPath, {})

2

package.json
{
"name": "list-fetch",
"version": "29.0.1",
"version": "29.0.2",
"description": "coming soon",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,3 +0,59 @@

# Bittorrent-Fetch
# list-Fetch
coming soon
method: `HEAD` - does not return a body, only returns headers
hostname:
* `_` - user's own data
path:
* `/` - if path is `/` then it returns data about the current torrents, if no headers, then it returns the byte size and count of all of the authored torrents
headers:
* `X-Data` - `true` | `false` - if true, it returns the byte size and count of all the torrents, if false, it returns only the count of all the torrents
* `/path/to/dir/or/file` - if path is not `/` then it returns data in the headers about the user directory that is local and not publically shared
* `address` | `infohash` - a torrent you want to load
path:
* `/any/path/to/dir/or/file` - it can be any path including `/`, if no headers, it returns the byte size, link, and other data in the headers
headers:
* `X-Copy` - `true` | `false` - if true, copies a file and saves it to the user directory(with the address or infohash as the directory name, it is publically shared) on the local disk, if false, copies a file and saves it to the user directory(it is publically shared) on the local disk
method: `GET` - return a body
hostname:
* `_` - user's own data
path:
* `/` - if path is `/` then it is same as `HEAD`, in addition, it also sends a body
headers:
* `X-Data` - `true` | `false` - if true, it returns the byte size and count of all the torrents, if false, it returns only the count of all the torrents
* `/path/to/dir/or/file` - if path is not `/` then it is the same as `HEAD`, in addition, it also sends a body
* `address` | `infohash` - a torrent you want to load
path:
* `/any/path/to/dir/or/file` - it can be any path including `/`, if no headers, it returns the byte size, link, and other data in the headers
headers:
* `Range` - if path is a file, it returns the data from a file that fits this range
method: `POST` - return a body
hostname:
* `_` - make a new torrent
path:
* `/path/to/dir/or/file` - any path, this is where the files will go for the torrent
body:
* `FormData` | `String` - either FormData which will hold the files or some string for a single file
headers:
* `X-Update` - `true` | `false` - if true, a mutable BEP46 torrent, if false, a immutable regular torrent
* `X-Version` - `String` - what sequence to use for the torrent
* `address` | `infohash` - an already existing torrent that you want to modify
path:
* `/path/to/dir/or/file` - any path, this is where the files will go for the torrent
body:
* `FormData` | `String` - either FormData which will hold the files or some string for a single file
headers:
* `X-Version` - `String` - what sequence to use for the torrent
method: `DELETE` - returns a body
hostname:
* `_` - delete user directory data
path:
* `/path/to/dir/or/file` - any path, this is where the files will go for the torrent
headers:
* `X-Update` - `true` | `false` - if true, a mutable BEP46 torrent, if false, a immutable regular torrent
* `X-Version` - `String` - what sequence to use for the torrent
* `address` | `infohash` - an already existing torrent to delete entirely or modify
path:
* `/path/to/dir/or/file` - any path, if `/` then entire torrent is delete, if not `/`, then only the path is deleted and a new torrent is made
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc