Destroy downloaded

This commit is contained in:
2021-12-31 00:20:07 +03:00
parent 942d341636
commit 0187518712
3 changed files with 822 additions and 8 deletions

813
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -14,6 +14,7 @@
"@koa/cors": "^3.1.0",
"@types/mongoose": "^5.11.97",
"dotenv": "^10.0.0",
"handbrake-js": "^6.0.0",
"koa": "^2.13.4",
"koa-bodyparser": "^4.3.0",
"koa-json": "^2.0.2",

View File

@@ -35,6 +35,7 @@ router.post('/room', async (ctx) => {
const doc = new RoomModel(room);
torrent.on('done', function () {
torrent.destroy();
processDownloaded(torrent, room.id);
});
@@ -77,6 +78,12 @@ router.get('/status', async (ctx) => {
const room = await RoomModel.findOne({ id: ctx.request.query.id }).exec();
if (room) {
if (room.downloaded) {
ctx.body = {
progress: 1,
downloaded: room.downloaded,
};
} else {
const torrent = tCli.get(room.magnet);
if (torrent) {
ctx.body = {
@@ -86,6 +93,7 @@ router.get('/status', async (ctx) => {
} else {
({ status: ctx.status, body: ctx.body } = errorResponse('status-00', 'No torrent found'));
}
}
} else {
({ status: ctx.status, body: ctx.body } = errorResponse('status-01', 'No room found'));
}