nfp_sites/api/file/util.mjs

20 lines
579 B
JavaScript
Raw Normal View History

2022-07-20 00:33:06 +00:00
export function parseFiles(files) {
for (let i = 0; i < files.length; i++) {
parseFile(files[i])
}
return files
}
export function parseFile(file) {
file.url = 'https://cdn.nfp.is' + file.path
file.magnet = null
file.meta = JSON.parse(file.meta || '{}') || {}
if (file.meta.torrent) {
file.magnet = 'magnet:?'
+ 'xl=' + file.size
+ '&dn=' + encodeURIComponent(file.meta.torrent.name)
+ '&xt=urn:btih:' + file.meta.torrent.hash
+ file.meta.torrent.announce.map(item => ('&tr=' + encodeURIComponent(item))).join('')
}
return file
}