-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorrentProcessor.js
68 lines (59 loc) · 2.19 KB
/
torrentProcessor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { handleAddedTorrent } from "./handleAddedTorrent.js";
import { handleFinishedTorrent } from "./handleFinishedTorrent.js";
import { logMessage } from "./sharedFunctions.js";
// Initialize logging
const now = new Date();
const currentDateTime = now.toISOString(); // Gets the date and time in ISO format
await logMessage("\n\n");
await logMessage("--------" + currentDateTime + "--------\n");
// Command line arguments
const args = Deno.args;
const torrentName = args[0];
const category = args[1];
const tags = args[2];
const contentPath = args[3];
const rootPath = args[4];
const savePath = args[5];
const numberOfFiles = args[6];
const torrentSize = args[7];
const currentTracker = args[8];
const v1hash = args[9];
const v2hash = args[10];
const torrentId = args[11];
const programStatus = args[12];
await logMessage("Starting torrent processing with the following parameters:");
await logMessage(`torrentName: ${torrentName}`);
await logMessage(`category: ${category}`);
await logMessage(`tags: ${tags}`);
await logMessage(`contentPath: ${contentPath}`);
await logMessage(`rootPath: ${rootPath}`);
await logMessage(`savePath: ${savePath}`);
await logMessage(`numberOfFiles: ${numberOfFiles}`);
await logMessage(`torrentSize: ${torrentSize}`);
await logMessage(`currentTracker: ${currentTracker}`);
await logMessage(`v1hash: ${v1hash}`);
await logMessage(`v2hash: ${v2hash}`);
await logMessage(`torrentId: ${torrentId}`);
await logMessage(`programStatus: ${programStatus}`);
await logMessage("\n\n");
await logMessage(args);
// Process based on program status
switch (programStatus) {
case "added":
await logMessage("Processing added torrent");
const addedSuccess = await handleAddedTorrent(torrentId);
if (!addedSuccess) {
await logMessage("Failed to process added torrent");
}
break;
case "finished":
await logMessage("Processing finished torrent");
const finishedSuccess = await handleFinishedTorrent(torrentId, torrentName, contentPath);
if (!finishedSuccess) {
await logMessage("Failed to process finished torrent");
}
break;
default:
await logMessage("Nothing to do here");
break;
}