2022-09-26 12:04:37 +03:00
|
|
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
|
|
|
import { asJson } from "utils/proxy/api-helpers";
|
2022-09-25 10:13:31 -07:00
|
|
|
|
|
|
|
const widget = {
|
|
|
|
api: "{url}/api/v3/{endpoint}?apikey={key}",
|
|
|
|
proxyHandler: genericProxyHandler,
|
|
|
|
|
|
|
|
mappings: {
|
2022-09-26 00:35:54 +03:00
|
|
|
series: {
|
2022-09-25 10:13:31 -07:00
|
|
|
endpoint: "series",
|
2023-06-02 14:57:27 +02:00
|
|
|
map: (data) => asJson(data).map((entry) => ({
|
|
|
|
title: entry.title,
|
|
|
|
id: entry.id
|
|
|
|
}))
|
2022-09-25 10:13:31 -07:00
|
|
|
},
|
2022-09-26 00:35:54 +03:00
|
|
|
queue: {
|
2022-09-25 10:13:31 -07:00
|
|
|
endpoint: "queue",
|
2022-10-22 23:11:08 -07:00
|
|
|
validate: [
|
|
|
|
"totalRecords"
|
|
|
|
]
|
2022-09-25 10:13:31 -07:00
|
|
|
},
|
|
|
|
"wanted/missing": {
|
2022-09-26 00:35:54 +03:00
|
|
|
endpoint: "wanted/missing",
|
2022-10-22 23:11:08 -07:00
|
|
|
validate: [
|
|
|
|
"totalRecords"
|
|
|
|
]
|
2022-09-25 10:13:31 -07:00
|
|
|
},
|
2023-06-02 14:57:27 +02:00
|
|
|
"queue/details": {
|
|
|
|
endpoint: "queue/details",
|
|
|
|
map: (data) => asJson(data).map((entry) => ({
|
|
|
|
trackedDownloadState: entry.trackedDownloadState,
|
|
|
|
trackedDownloadStatus: entry.trackedDownloadStatus,
|
|
|
|
timeLeft: entry.timeleft,
|
|
|
|
size: entry.size,
|
|
|
|
sizeLeft: entry.sizeleft,
|
|
|
|
seriesId: entry.seriesId,
|
|
|
|
episodeTitle: entry.episode?.title,
|
|
|
|
episodeId: entry.episodeId
|
|
|
|
})).sort((a, b) => {
|
|
|
|
const downloadingA = a.trackedDownloadState === "downloading"
|
|
|
|
const downloadingB = b.trackedDownloadState === "downloading"
|
|
|
|
if (downloadingA && !downloadingB) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (downloadingB && !downloadingA) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const percentA = a.sizeLeft / a.size;
|
|
|
|
const percentB = b.sizeLeft / b.size;
|
|
|
|
if (percentA < percentB) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (percentA > percentB) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
}
|
2022-09-26 00:35:54 +03:00
|
|
|
},
|
2022-09-25 10:13:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
export default widget;
|