-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdownload-verification.js
More file actions
94 lines (86 loc) · 3.82 KB
/
Copy pathdownload-verification.js
File metadata and controls
94 lines (86 loc) · 3.82 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2021-2025 BuiltByBit (Mick Capital Pty. Ltd.)
// MIT License (https://github.com/BuiltByBit/js-api-wrapper/blob/main/LICENSE)
const { Wrapper, Token, TokenType } = require("@builtbybit/api-wrapper");
const readline = require("readline");
const { table } = require("table");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const config = {
header: {
alignment: "center",
content: "BuiltByBit Download Verification"
}
};
let token = new Token(TokenType.PRIVATE, "Find @ https://builtbybit.com/account/api");
let wrapper = new Wrapper();
async function main() {
await wrapper.init(token);
let ownedResources = await wrapper.resources().listOwnedAll().catch(e => { console.error(e); });
let resourceIds = [["Resource Title", "Resource ID"]];
for (const resource of ownedResources) {
resourceIds.push([resource.title, resource.resource_id]);
}
const ownedConfig = {
header: {
alignment: "center",
content: "BuiltByBit Download Verification\nOwned Resources"
}
};
console.log(table(resourceIds, ownedConfig));
rl.question("Lookup by (u)sername or by (r)esource id? ", async (answer) =>{
let downloadDetails;
let user;
let downloads = [];
switch (answer.toLowerCase()) {
case "u":
try {
rl.question("What is the username of the user you'd like to lookup? ", async (username) => {
user = await wrapper.members().fetchByUsername(username).catch(e => { console.error(e); });
console.log("Fetching...");
downloads.push(["Resource Title", "Resource ID", "Download Date"]);
for (const resource of ownedResources) {
// eslint-disable-next-line max-len
downloadDetails = await wrapper.resources().downloads().listByMemberAll(resource.resource_id, user.member_id).catch(e => { console.error(e); });
for (const download of downloadDetails) {
// eslint-disable-next-line max-len
downloads.push([resource.title, resource.resource_id, new Date(download.download_date * 1000).toLocaleString()]);
}
}
console.log(table(downloads, config));
rl.close();
});
} catch (e) {
console.error(e);
rl.close();
}
break;
case "r":
try {
rl.question("What is the resource id of the resource you'd like to lookup? ", async (resourceId) => {
// eslint-disable-next-line max-len
downloadDetails = await wrapper.resources().downloads().listAll(resourceId).catch(e => { console.error(e); });
downloads.push(["Username", "Member ID", "Download Date"]);
console.log("Fetching...");
for (const download of downloadDetails) {
user = await wrapper.members().fetch(download.downloader_id).catch(e => { console.error(e); });
// eslint-disable-next-line max-len
downloads.push([user.username, user.member_id, new Date(download.download_date * 1000).toLocaleString()]);
}
console.log(table(downloads, config));
rl.close();
});
} catch (e) {
console.error(e);
rl.close();
}
break;
default:
console.error("Invalid input. Please try again.");
rl.close();
break;
}
});
}
main().catch(error => console.error("ERROR: " + error));