feat(synology): files par fichier + getFiles() comme qbittorrent
This commit is contained in:
1 parent
98ed3c7199
commit
c6c52a1ae7
1 file changed
+45
-1
@@ -161,13 +161,14 @@ const DS: TorrentClientDriver = {
|
|||||||
async list(config, category) {
|
async list(config, category) {
|
||||||
const sid = await dsLogin(config)
|
const sid = await dsLogin(config)
|
||||||
const data = await dsRequest(config, 'SYNO.DownloadStation.Task', 'list', '1',
|
const data = await dsRequest(config, 'SYNO.DownloadStation.Task', 'list', '1',
|
||||||
{ additional: 'transfer,detail' }, sid)
|
{ additional: 'transfer,detail,file' }, sid)
|
||||||
|
|
||||||
const tasks: any[] = data?.tasks ?? []
|
const tasks: any[] = data?.tasks ?? []
|
||||||
|
|
||||||
return tasks.map(t => {
|
return tasks.map(t => {
|
||||||
const transfer = t.additional?.transfer ?? {}
|
const transfer = t.additional?.transfer ?? {}
|
||||||
const detail = t.additional?.detail ?? {}
|
const detail = t.additional?.detail ?? {}
|
||||||
|
const fileList: any[] = t.additional?.file ?? []
|
||||||
const size = t.size ?? 0
|
const size = t.size ?? 0
|
||||||
const dl = transfer.size_downloaded ?? 0
|
const dl = transfer.size_downloaded ?? 0
|
||||||
|
|
||||||
@@ -177,6 +178,19 @@ const DS: TorrentClientDriver = {
|
|||||||
String(t.id ?? ''),
|
String(t.id ?? ''),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const files = fileList.length > 0
|
||||||
|
? fileList.map((f: any, i: number) => {
|
||||||
|
const fSize = typeof f.size === 'number' ? f.size : 0
|
||||||
|
const fDl = typeof f.size_downloaded === 'number' ? f.size_downloaded : 0
|
||||||
|
return {
|
||||||
|
index : i,
|
||||||
|
name : String(f.filename ?? ''),
|
||||||
|
progress: fSize > 0 ? fDl / fSize : 0,
|
||||||
|
priority: String(f.priority ?? 'normal') === 'skip' ? 0 : 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
: undefined
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hash,
|
hash,
|
||||||
name : t.title,
|
name : t.title,
|
||||||
@@ -191,6 +205,7 @@ const DS: TorrentClientDriver = {
|
|||||||
eta : -1,
|
eta : -1,
|
||||||
save_path : detail.destination ?? '',
|
save_path : detail.destination ?? '',
|
||||||
category : category ?? '',
|
category : category ?? '',
|
||||||
|
files,
|
||||||
} satisfies TorrentInfo
|
} satisfies TorrentInfo
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -241,6 +256,35 @@ const DS: TorrentClientDriver = {
|
|||||||
logger.info('synology-ds', `Torrent ajouté avec succès${config.savePath ? ` (dossier: ${config.savePath})` : ''}`)
|
logger.info('synology-ds', `Torrent ajouté avec succès${config.savePath ? ` (dossier: ${config.savePath})` : ''}`)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getFiles(config, hash) {
|
||||||
|
const sid = await dsLogin(config)
|
||||||
|
const data = await dsRequest(config, 'SYNO.DownloadStation.Task', 'list', '1',
|
||||||
|
{ additional: 'detail,file' }, sid)
|
||||||
|
const tasks: any[] = data?.tasks ?? []
|
||||||
|
|
||||||
|
const h = hash.toLowerCase()
|
||||||
|
const task = tasks.find((t: any) => {
|
||||||
|
const detailHash = String(t.additional?.detail?.hash ?? '').toLowerCase()
|
||||||
|
const detailUri = String(t.additional?.detail?.uri ?? '').toLowerCase()
|
||||||
|
const synoId = String(t.id ?? '').toLowerCase()
|
||||||
|
const cached = _uriToHash.get(detailUri) ?? ''
|
||||||
|
return detailHash === h || synoId === h || cached === h
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!task) return []
|
||||||
|
const fileList: any[] = task.additional?.file ?? []
|
||||||
|
return fileList.map((f: any, i: number) => {
|
||||||
|
const fSize = typeof f.size === 'number' ? f.size : 0
|
||||||
|
const fDl = typeof f.size_downloaded === 'number' ? f.size_downloaded : 0
|
||||||
|
return {
|
||||||
|
index : i,
|
||||||
|
name : String(f.filename ?? ''),
|
||||||
|
progress: fSize > 0 ? fDl / fSize : 0,
|
||||||
|
priority: String(f.priority ?? 'normal') === 'skip' ? 0 : 1,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
async remove(config, hash, _deleteFiles?) {
|
async remove(config, hash, _deleteFiles?) {
|
||||||
const sid = await dsLogin(config)
|
const sid = await dsLogin(config)
|
||||||
const data = await dsRequest(config, 'SYNO.DownloadStation.Task', 'list', '1', { additional: 'detail' }, sid)
|
const data = await dsRequest(config, 'SYNO.DownloadStation.Task', 'list', '1', { additional: 'detail' }, sid)
|
||||||
|
|||||||
Reference in new issue
Block a user