nfp_sites/nfp_moe/api/file/util.mjs
Jonatan Nilsson 6565409e52 base: Added /health route.
nfp_moe: Complete re-thinking of all loading. Smarter loading and lighter site. Better user experience among other things.
2022-08-21 21:54:24 +00:00

33 lines
No EOL
949 B
JavaScript

export function parseFiles(files) {
for (let i = 0; i < files.length; i++) {
parseFile(files[i])
}
return files
}
export function combineFilesWithArticles(articles, files) {
let articleMap = new Map()
articles.forEach(article => {
article.files = []
articleMap.set(article.id, article)
})
files.forEach(file => {
articleMap.get(file.id).files.push(parseFile(file))
})
}
export function parseFile(file) {
file.path = '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('')
file.meta.torrent = { name: file.meta.torrent.name, files: file.meta.torrent.files }
}
return file
}