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
|
|
|
|
}
|
|
|
|
|
2022-08-12 23:33:50 +00:00
|
|
|
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))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-20 00:33:06 +00:00
|
|
|
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
|
|
|
|
}
|