UNPKG

@spacepumpkin/modified-nyaapi

Version:

Non-official api for getting torrent links from Nyaa.si and Nyaa.pantsu.cat

48 lines (40 loc) 1.05 kB
/** * Resources explaining the choices * * https://github.com/gin-gonic/gin/issues/931 * https://github.com/axios/axios/issues/623 */ const fs = require('fs') const req = require('request-promise') const omit = require('lodash.omit') const URI = require('./url.json').url /** * Allows the uploading of torrent file to nyaa.pantsu.cat * * @param {Object} opts Options. * * @returns {promise} */ const upload = (opts = {}) => { return new Promise((resolve, reject) => { if ((!opts.magnet && !opts.torrent) || !opts.token || !opts.username) { reject(new Error('[Nyaapi]: No file/torrent, token or username were given.')) return } if (opts.torrent) { opts.torrent = fs.createReadStream(opts.torrent) } req.post({ url: `${URI}upload`, headers: { Authorization: opts.token }, formData: omit(opts, 'token') }) .then((data) => resolve(data)) .catch((err) => reject(err)) }) } module.exports = { upload }