Socket
Socket
Sign inDemoInstall

torrentz

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

torrentz - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

114

index.js

@@ -339,3 +339,3 @@ const WebTorrent = require('webtorrent')

}
async publishTorrent(id, pathToData, keys, headers, data, opts = {}){
async publishTorrent(id, pathToData, headers, data, opts = {}){
if(!opts){

@@ -345,4 +345,44 @@ opts = {}

const useTimeout = opts.timeout ? opts.timeout * 1000 : this._timeout
if(keys){
if (!id || !id.address || !id.secret) {
if(id.title){
if(this.checkId.has(id.title)){
this.checkId.delete(id.title)
}
const activeTorrent = this.findTheTorrent(id.title)
if(activeTorrent){
await this.stopTorrent(activeTorrent, {destroyStore: false})
}
const folderPath = path.join(this._storage, id.title)
await fs.ensureDir(folderPath)
const dataPath = path.join(folderPath, pathToData)
const descriptionPath = path.join(this._description, id.title)
const useOpts = await (async () => {if(opts.opt){await fs.writeFile(descriptionPath, JSON.stringify(opts.opt));return opts.opt;}else if(await fs.pathExists(descriptionPath)){const test = await fs.readFile(descriptionPath);return JSON.parse(test.toString());}else{return {};}})()
const additionalData = headers ? await this.handleFormData(dataPath, headers, data) : await this.handleRegData(dataPath, data)
if(additionalData.length){
await fs.writeFile(path.join(folderPath, id.title + '-data.txt'), `${additionalData.map(file => {return `${file.key}: ${file.value}\n`})}`, {flag: 'a'})
}
// const checkFolderPath = await fs.readdir(folderPath, { withFileTypes: false })
// if (!checkFolderPath.length) {
// await fs.remove(folderPath)
// throw new Error('data could not be written to new torrent')
// }
const checkTorrent = await Promise.race([
this.delayTimeOut(useTimeout, this.errName(new Error('torrent took too long, it timed out'), 'ErrorTimeout'), false),
this.startTorrent(folderPath, { ...useOpts, destroyStoreOnDestroy: false })
])
await fs.writeFile(path.join(this._author, id.title), JSON.stringify({infohash: checkTorrent.infoHash, title: id.title}))
const mainPath = path.join(checkTorrent.path, checkTorrent.name)
checkTorrent.folder = folderPath
checkTorrent.title = id.title
checkTorrent.address = null
checkTorrent.own = true
checkTorrent.infohash = checkTorrent.infoHash
checkTorrent.files.forEach(file => {file.urlPath = file.path.slice(mainPath.length).replace(/\\/, '/')})
this.checkId.set(id.title, checkTorrent)
return { infohash: checkTorrent.infohash, title: checkTorrent.title, name: checkTorrent.name, length: checkTorrent.length }
} else {
if (!id.address || !id.secret) {
id = this.createKeypair()

@@ -359,10 +399,8 @@ } else {

const folderPath = path.join(this._storage, id.address)
await fs.ensureDir(folderPath)
const dataPath = path.join(folderPath, pathToData)
const descriptionPath = path.join(this._description, id.address)
const useOpts = await (async () => {if(await fs.pathExists(descriptionPath)){const test = await fs.readFile(descriptionPath);return JSON.parse(test.toString());}else if(opts.opt){await fs.writeFile(descriptionPath, JSON.stringify(opts.opt));return opts.opt;}else{return {};}})()
if(opts.empty){
await fs.emptyDir(folderPath)
} else {
await fs.ensureDir(folderPath)
}
const additionalData = headers ? await this.handleFormData(dataPath, headers, data) : await this.handleRegData(dataPath, data)

@@ -398,46 +436,3 @@ if(additionalData.length){

this.checkId.set(id.address, checkTorrent)
return { torrent: checkTorrent, address: id.address, secret: id.secret, infohash: checkTorrent.infohash, sequence: checkTorrent.sequence }
} else {
if(this.checkId.has(id)){
this.checkId.delete(id)
}
const activeTorrent = this.findTheTorrent(id)
if(activeTorrent){
await this.stopTorrent(activeTorrent, {destroyStore: false})
}
const folderPath = path.join(this._storage, id)
const dataPath = path.join(folderPath, pathToData)
const descriptionPath = path.join(this._description, id.address)
const useOpts = await (async () => {if(await fs.pathExists(descriptionPath)){const test = await fs.readFile(descriptionPath);return JSON.parse(test.toString());}else if(opts.opt){await fs.writeFile(descriptionPath, JSON.stringify(opts.opt));return opts.opt;}else{return {};}})()
if(opts.empty){
await fs.emptyDir(folderPath)
} else {
await fs.ensureDir(folderPath)
}
const additionalData = headers ? await this.handleFormData(dataPath, headers, data) : await this.handleRegData(dataPath, data)
if(additionalData.length){
await fs.writeFile(path.join(folderPath, id + '-data.txt'), `${additionalData.map(file => {return `${file.key}: ${file.value}\n`})}`, {flag: 'a'})
}
// const checkFolderPath = await fs.readdir(folderPath, { withFileTypes: false })
// if (!checkFolderPath.length) {
// await fs.remove(folderPath)
// throw new Error('data could not be written to new torrent')
// }
const checkTorrent = await Promise.race([
this.delayTimeOut(useTimeout, this.errName(new Error('torrent took too long, it timed out'), 'ErrorTimeout'), false),
this.startTorrent(folderPath, { ...useOpts, destroyStoreOnDestroy: false })
])
await fs.writeFile(path.join(this._author, id), JSON.stringify({infohash: checkTorrent.infoHash, title: id}))
const mainPath = path.join(checkTorrent.path, checkTorrent.name)
checkTorrent.folder = folderPath
checkTorrent.title = id
checkTorrent.address = null
checkTorrent.own = true
checkTorrent.infohash = checkTorrent.infoHash
checkTorrent.files.forEach(file => {file.urlPath = file.path.slice(mainPath.length).replace(/\\/, '/')})
this.checkId.set(id, checkTorrent)
return { torrent: checkTorrent, infohash: checkTorrent.infohash, title: checkTorrent.title }
return { address: id.address, secret: id.secret, infohash: checkTorrent.infohash, sequence: checkTorrent.sequence, name: checkTorrent.name, length: checkTorrent.length}
}

@@ -463,10 +458,11 @@ }

const folderPath = path.join(this._storage, id)
const authorPath = path.join(this._author, id)
const descriptionPath = path.join(this._description, id)
if(!await fs.pathExists(folderPath)){
throw new Error('did not find any torrent data to delete')
}
if(pathToData === '/'){
if(!await fs.pathExists(folderPath)){
throw new Error('did not find any torrent data to delete')
}
await fs.remove(folderPath)
const authorPath = path.join(this._author, id)
const descriptionPath = path.join(this._description, id)

@@ -480,2 +476,3 @@ if(await fs.pathExists(authorPath)){

}
return {torrent: true, data: true}
} else {

@@ -486,5 +483,4 @@ const dataPath = path.join(folderPath, pathToData)

}
return {torrent: false, data: true}
}
return id
}

@@ -491,0 +487,0 @@ midTorrent(id, opts){

{
"name": "torrentz",
"version": "3.0.1",
"version": "3.0.2",
"description": "",

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

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