@irfanshadikrishad/anilist 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -18
- package/bin/helpers/auth.d.ts +23 -10
- package/bin/helpers/auth.js +574 -173
- package/bin/helpers/fetcher.js +3 -3
- package/bin/helpers/lists.d.ts +22 -8
- package/bin/helpers/lists.js +915 -536
- package/bin/helpers/mutations.js +31 -31
- package/bin/helpers/queries.js +127 -127
- package/bin/helpers/types.d.ts +3 -3
- package/bin/helpers/workers.d.ts +9 -11
- package/bin/helpers/workers.js +8 -307
- package/bin/index.js +24 -25
- package/package.json +3 -2
- package/bin/helpers/more.d.ts +0 -11
- package/bin/helpers/more.js +0 -500
package/bin/helpers/auth.js
CHANGED
|
@@ -14,101 +14,123 @@ import open from "open";
|
|
|
14
14
|
import os from "os";
|
|
15
15
|
import path from "path";
|
|
16
16
|
import { fetcher } from "./fetcher.js";
|
|
17
|
-
import {
|
|
17
|
+
import { AniList, MyAnimeList } from "./lists.js";
|
|
18
|
+
import { deleteActivityMutation, saveTextActivityMutation, } from "./mutations.js";
|
|
19
|
+
import { activityAllQuery, activityAnimeListQuery, activityMangaListQuery, activityMediaList, activityMessageQuery, activityTextQuery, currentUserAnimeList, currentUserMangaList, currentUserQuery, deleteMangaEntryMutation, deleteMediaEntryMutation, userActivityQuery, } from "./queries.js";
|
|
18
20
|
import { aniListEndpoint, getTitle, redirectUri } from "./workers.js";
|
|
19
21
|
const home_dir = os.homedir();
|
|
20
22
|
const save_path = path.join(home_dir, ".anilist_token");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
fs.writeFileSync(save_path, token, { encoding: "utf8" });
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
console.error(`\nError storing acess-token. ${error.message}`);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function retriveAccessToken() {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
if (fs.existsSync(save_path)) {
|
|
46
|
-
return fs.readFileSync(save_path, { encoding: "utf8" });
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function anilistUserLogin(clientId, clientSecret) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
console.log("Starting AniList login...");
|
|
56
|
-
const authUrl = `https://anilist.co/api/v2/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code`;
|
|
57
|
-
console.log("Opening browser for AniList login...");
|
|
58
|
-
open(authUrl);
|
|
59
|
-
const authCode = yield getAccessTokenFromUser();
|
|
60
|
-
const tokenResponse = yield fetch("https://anilist.co/api/v2/oauth/token", {
|
|
61
|
-
method: "POST",
|
|
62
|
-
headers: {
|
|
63
|
-
"Content-Type": "application/json",
|
|
64
|
-
},
|
|
65
|
-
body: JSON.stringify({
|
|
66
|
-
grant_type: "authorization_code",
|
|
67
|
-
client_id: String(clientId),
|
|
68
|
-
client_secret: clientSecret,
|
|
69
|
-
redirect_uri: redirectUri,
|
|
70
|
-
code: authCode,
|
|
71
|
-
}),
|
|
72
|
-
});
|
|
73
|
-
const token_Data = yield tokenResponse.json();
|
|
74
|
-
if (token_Data === null || token_Data === void 0 ? void 0 : token_Data.access_token) {
|
|
75
|
-
yield storeAccessToken(token_Data === null || token_Data === void 0 ? void 0 : token_Data.access_token);
|
|
76
|
-
const name = yield currentUsersName();
|
|
77
|
-
if (name) {
|
|
78
|
-
console.log(`\nWelcome Back, ${name}!`);
|
|
23
|
+
class Auth {
|
|
24
|
+
/**
|
|
25
|
+
* Get access-token from user
|
|
26
|
+
*/
|
|
27
|
+
static GetAccessToken() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
try {
|
|
30
|
+
const { token } = yield inquirer.prompt([
|
|
31
|
+
{
|
|
32
|
+
type: "password",
|
|
33
|
+
name: "token",
|
|
34
|
+
message: "Please enter your AniList access token:",
|
|
35
|
+
},
|
|
36
|
+
]);
|
|
37
|
+
return token;
|
|
79
38
|
}
|
|
80
|
-
|
|
81
|
-
console.
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(`\nSomething went wrong. ${error.message}`);
|
|
82
41
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
static StoreAccessToken(token) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
try {
|
|
47
|
+
fs.writeFileSync(save_path, token, { encoding: "utf8" });
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error(`\nError storing acess-token. ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
static RetriveAccessToken() {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
try {
|
|
57
|
+
if (fs.existsSync(save_path)) {
|
|
58
|
+
return fs.readFileSync(save_path, { encoding: "utf8" });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(`\nError retriving acess-token. ${error.message}`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
static Login(clientId, clientSecret) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
try {
|
|
72
|
+
console.log("Starting AniList login...");
|
|
73
|
+
const authUrl = `https://anilist.co/api/v2/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code`;
|
|
74
|
+
console.log("Opening browser for AniList login...");
|
|
75
|
+
open(authUrl);
|
|
76
|
+
const authCode = yield Auth.GetAccessToken();
|
|
77
|
+
const tokenResponse = yield fetch("https://anilist.co/api/v2/oauth/token", {
|
|
78
|
+
method: "POST",
|
|
79
|
+
headers: {
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
grant_type: "authorization_code",
|
|
84
|
+
client_id: String(clientId),
|
|
85
|
+
client_secret: clientSecret,
|
|
86
|
+
redirect_uri: redirectUri,
|
|
87
|
+
code: authCode,
|
|
88
|
+
}),
|
|
109
89
|
});
|
|
110
|
-
const
|
|
111
|
-
|
|
90
|
+
const token_Data = yield tokenResponse.json();
|
|
91
|
+
if (token_Data === null || token_Data === void 0 ? void 0 : token_Data.access_token) {
|
|
92
|
+
yield Auth.StoreAccessToken(token_Data === null || token_Data === void 0 ? void 0 : token_Data.access_token);
|
|
93
|
+
const name = yield Auth.MyUserName();
|
|
94
|
+
if (name) {
|
|
95
|
+
console.log(`\nWelcome Back, ${name}!`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.log(`\nLogged in successfull!`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
console.error("\nFailed to get access token:", token_Data);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error(`\nFailed logging in. ${error.message}`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
static Myself() {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
113
|
+
try {
|
|
114
|
+
if (yield Auth.isLoggedIn()) {
|
|
115
|
+
const headers = {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
118
|
+
};
|
|
119
|
+
const request = yield fetch(aniListEndpoint, {
|
|
120
|
+
method: "POST",
|
|
121
|
+
headers: headers,
|
|
122
|
+
body: JSON.stringify({ query: currentUserQuery }),
|
|
123
|
+
});
|
|
124
|
+
const { data, errors } = yield request.json();
|
|
125
|
+
if (request.status === 200) {
|
|
126
|
+
const user = data === null || data === void 0 ? void 0 : data.Viewer;
|
|
127
|
+
const activiResponse = yield fetcher(userActivityQuery, {
|
|
128
|
+
id: user === null || user === void 0 ? void 0 : user.id,
|
|
129
|
+
page: 1,
|
|
130
|
+
perPage: 10,
|
|
131
|
+
});
|
|
132
|
+
const activities = (_b = (_a = activiResponse === null || activiResponse === void 0 ? void 0 : activiResponse.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities;
|
|
133
|
+
console.log(`
|
|
112
134
|
ID: ${user === null || user === void 0 ? void 0 : user.id}
|
|
113
135
|
Name: ${user === null || user === void 0 ? void 0 : user.name}
|
|
114
136
|
siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
|
|
@@ -131,97 +153,476 @@ Statistics (Manga):
|
|
|
131
153
|
Chapters Read: ${(_q = (_p = user === null || user === void 0 ? void 0 : user.statistics) === null || _p === void 0 ? void 0 : _p.manga) === null || _q === void 0 ? void 0 : _q.chaptersRead}
|
|
132
154
|
Volumes Read: ${(_s = (_r = user === null || user === void 0 ? void 0 : user.statistics) === null || _r === void 0 ? void 0 : _r.manga) === null || _s === void 0 ? void 0 : _s.volumesRead}
|
|
133
155
|
`);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
156
|
+
console.log(`\nRecent Activities:`);
|
|
157
|
+
if (activities.length > 0) {
|
|
158
|
+
activities.map(({ status, progress, media }) => {
|
|
159
|
+
console.log(`${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return user;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
console.error(`\nSomething went wrong. Please log in again. ${errors[0].message}`);
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
console.error(`\nPlease login first to use this feature.`);
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
console.error(`\nError from Myself. ${error.message}`);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
static isLoggedIn() {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
try {
|
|
182
|
+
if ((yield Auth.RetriveAccessToken()) !== null) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
console.error(`\nError getting isLoggedIn. ${error.message}`);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
static Logout() {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
try {
|
|
197
|
+
if (fs.existsSync(save_path)) {
|
|
198
|
+
try {
|
|
199
|
+
fs.unlinkSync(save_path);
|
|
200
|
+
console.log(`\nLogout successful. See you soon, ${yield Auth.MyUserName()}.`);
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
console.error("\nError logging out:", error);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
console.error("\nYou may already be logged out.");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
console.error(`\nError logging out. ${error.message}`);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
static MyUserId() {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
219
|
+
console.log(`\nUser not logged in.`);
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
const token = yield Auth.RetriveAccessToken();
|
|
223
|
+
const request = yield fetch(aniListEndpoint, {
|
|
224
|
+
method: "POST",
|
|
225
|
+
headers: {
|
|
226
|
+
"Content-Type": "application/json",
|
|
227
|
+
"Authorization": `Bearer ${token}`,
|
|
228
|
+
},
|
|
229
|
+
body: JSON.stringify({ query: currentUserQuery }),
|
|
230
|
+
});
|
|
231
|
+
if (!(request.status === 200)) {
|
|
232
|
+
console.error(`Failed to fetch user data. Status: ${request.status}`);
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
const { data } = yield request.json();
|
|
236
|
+
return (_b = (_a = data === null || data === void 0 ? void 0 : data.Viewer) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null;
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
static MyUserName() {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
var _a, _b;
|
|
242
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
243
|
+
console.log(`\nUser not logged in.`);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
const token = yield Auth.RetriveAccessToken();
|
|
247
|
+
const request = yield fetch(aniListEndpoint, {
|
|
248
|
+
method: "POST",
|
|
249
|
+
headers: {
|
|
250
|
+
"Content-Type": "application/json",
|
|
251
|
+
"Authorization": `Bearer ${token}`,
|
|
252
|
+
},
|
|
253
|
+
body: JSON.stringify({ query: currentUserQuery }),
|
|
254
|
+
});
|
|
255
|
+
if (!request.ok) {
|
|
256
|
+
console.error(`Failed to fetch user data. Status: ${request.status}`);
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
const { data } = yield request.json();
|
|
260
|
+
return (_b = (_a = data === null || data === void 0 ? void 0 : data.Viewer) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : null;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
static DeleteMyActivities() {
|
|
264
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
var _a, _b, _c, _d, _e, _f;
|
|
266
|
+
try {
|
|
267
|
+
if (yield Auth.isLoggedIn()) {
|
|
268
|
+
const { activityType } = yield inquirer.prompt([
|
|
269
|
+
{
|
|
270
|
+
type: "list",
|
|
271
|
+
name: "activityType",
|
|
272
|
+
message: "What type of activity you want to delete?",
|
|
273
|
+
choices: [
|
|
274
|
+
{ name: "All Activity", value: 0 },
|
|
275
|
+
{ name: "Text Activity", value: 1 },
|
|
276
|
+
{ name: "Media List Activity", value: 2 },
|
|
277
|
+
{ name: "Anime List Activity", value: 3 },
|
|
278
|
+
{ name: "Manga List Activity", value: 4 },
|
|
279
|
+
{ name: "Message Activity", value: 5 },
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
]);
|
|
283
|
+
const userId = yield Auth.MyUserId();
|
|
284
|
+
const variables = { page: 1, perPage: 100, userId };
|
|
285
|
+
const queryMap = {
|
|
286
|
+
0: activityAllQuery,
|
|
287
|
+
1: activityTextQuery,
|
|
288
|
+
2: activityMediaList,
|
|
289
|
+
3: activityAnimeListQuery,
|
|
290
|
+
4: activityMangaListQuery,
|
|
291
|
+
5: activityMessageQuery,
|
|
292
|
+
};
|
|
293
|
+
const query = queryMap[activityType];
|
|
294
|
+
let hasMoreActivities = true;
|
|
295
|
+
while (hasMoreActivities) {
|
|
296
|
+
const response = yield fetcher(query, {
|
|
297
|
+
page: 1,
|
|
298
|
+
perPage: 50,
|
|
299
|
+
userId: yield Auth.MyUserId(),
|
|
300
|
+
});
|
|
301
|
+
if ((_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.activities) {
|
|
302
|
+
let count = 0;
|
|
303
|
+
const activities = (_d = (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.Page) === null || _d === void 0 ? void 0 : _d.activities;
|
|
304
|
+
if (!activities || activities.length === 0) {
|
|
305
|
+
console.log(`\nNo more activities available.`);
|
|
306
|
+
hasMoreActivities = false;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
for (const act of activities) {
|
|
310
|
+
// Ensure ID is present to avoid unintended errors
|
|
311
|
+
if (act === null || act === void 0 ? void 0 : act.id) {
|
|
312
|
+
const deleteResponse = yield fetcher(deleteActivityMutation, {
|
|
313
|
+
id: act === null || act === void 0 ? void 0 : act.id,
|
|
314
|
+
});
|
|
315
|
+
const isDeleted = (_f = (_e = deleteResponse === null || deleteResponse === void 0 ? void 0 : deleteResponse.data) === null || _e === void 0 ? void 0 : _e.DeleteActivity) === null || _f === void 0 ? void 0 : _f.deleted;
|
|
316
|
+
count++;
|
|
317
|
+
console.log(`[${count}/${activities.length}] ${act === null || act === void 0 ? void 0 : act.id} ${isDeleted ? "✅" : "❌"}`);
|
|
318
|
+
// Avoiding rate-limit
|
|
319
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
// In case of an unexpected null response, exit the loop
|
|
326
|
+
console.log(`\nProbably deleted all the activities of this type.`);
|
|
327
|
+
hasMoreActivities = false;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
console.error(`\nPlease log in to delete your activities.`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
console.error(`\nSomething went wrong. ${error.message}`);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
static DeleteMyAnimeList() {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
var _a, _b, _c, _d;
|
|
343
|
+
if (yield Auth.isLoggedIn()) {
|
|
344
|
+
const userID = yield Auth.MyUserId();
|
|
345
|
+
if (userID) {
|
|
346
|
+
const request = yield fetch(aniListEndpoint, {
|
|
347
|
+
method: "POST",
|
|
348
|
+
headers: {
|
|
349
|
+
"content-type": "application/json",
|
|
350
|
+
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
351
|
+
},
|
|
352
|
+
body: JSON.stringify({
|
|
353
|
+
query: currentUserAnimeList,
|
|
354
|
+
variables: { id: userID },
|
|
355
|
+
}),
|
|
138
356
|
});
|
|
357
|
+
const response = yield request.json();
|
|
358
|
+
if (request.status === 200) {
|
|
359
|
+
const lists = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.MediaListCollection) === null || _b === void 0 ? void 0 : _b.lists;
|
|
360
|
+
if (lists.length > 0) {
|
|
361
|
+
const { selectedList } = yield inquirer.prompt([
|
|
362
|
+
{
|
|
363
|
+
type: "list",
|
|
364
|
+
name: "selectedList",
|
|
365
|
+
message: "Select an anime list:",
|
|
366
|
+
choices: lists.map((list) => list.name),
|
|
367
|
+
pageSize: 10,
|
|
368
|
+
},
|
|
369
|
+
]);
|
|
370
|
+
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
371
|
+
if (selectedEntries) {
|
|
372
|
+
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
373
|
+
for (const [_, entry] of selectedEntries.entries.entries()) {
|
|
374
|
+
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
375
|
+
yield Auth.DeleteAnimeById(entry === null || entry === void 0 ? void 0 : entry.id, (_c = entry === null || entry === void 0 ? void 0 : entry.media) === null || _c === void 0 ? void 0 : _c.title);
|
|
376
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
console.log(`No id in entry.`);
|
|
380
|
+
console.log(entry);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
console.log("No entries found.");
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
console.log(`\nNo anime(s) found in any list.`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
console.log(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
console.log(`\nFailed getting current user Id.`);
|
|
139
398
|
}
|
|
140
|
-
return user;
|
|
141
399
|
}
|
|
142
400
|
else {
|
|
143
|
-
console.error(`\
|
|
144
|
-
return null;
|
|
401
|
+
console.error(`\nPlease log in first to delete your lists.`);
|
|
145
402
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
function isLoggedIn() {
|
|
154
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
if ((yield retriveAccessToken()) !== null) {
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function logoutUser() {
|
|
164
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
if (fs.existsSync(save_path)) {
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
static DeleteAnimeById(id, title) {
|
|
406
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
407
|
+
var _a, _b, _c;
|
|
166
408
|
try {
|
|
167
|
-
|
|
168
|
-
|
|
409
|
+
const request = yield fetch(aniListEndpoint, {
|
|
410
|
+
method: "POST",
|
|
411
|
+
headers: {
|
|
412
|
+
"content-type": "application/json",
|
|
413
|
+
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
414
|
+
},
|
|
415
|
+
body: JSON.stringify({
|
|
416
|
+
query: deleteMediaEntryMutation,
|
|
417
|
+
variables: { id },
|
|
418
|
+
}),
|
|
419
|
+
});
|
|
420
|
+
const response = yield request.json();
|
|
421
|
+
if (request.status === 200) {
|
|
422
|
+
const deleted = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.DeleteMediaListEntry) === null || _b === void 0 ? void 0 : _b.deleted;
|
|
423
|
+
console.log(`del ${title ? getTitle(title) : ""} ${deleted ? "✅" : "❌"}`);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
console.log(`\nError deleting anime. ${(_c = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _c === void 0 ? void 0 : _c.message}`);
|
|
427
|
+
console.log(response);
|
|
428
|
+
}
|
|
169
429
|
}
|
|
170
430
|
catch (error) {
|
|
171
|
-
console.
|
|
431
|
+
console.log(`\nError deleting anime. ${id} ${error.message}`);
|
|
172
432
|
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
static DeleteMyMangaList() {
|
|
436
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
437
|
+
var _a, _b, _c, _d;
|
|
438
|
+
try {
|
|
439
|
+
if (yield Auth.isLoggedIn()) {
|
|
440
|
+
const userID = yield Auth.MyUserId();
|
|
441
|
+
if (userID) {
|
|
442
|
+
const request = yield fetch(aniListEndpoint, {
|
|
443
|
+
method: "POST",
|
|
444
|
+
headers: {
|
|
445
|
+
"content-type": "application/json",
|
|
446
|
+
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
447
|
+
},
|
|
448
|
+
body: JSON.stringify({
|
|
449
|
+
query: currentUserMangaList,
|
|
450
|
+
variables: { id: userID },
|
|
451
|
+
}),
|
|
452
|
+
});
|
|
453
|
+
const response = yield request.json();
|
|
454
|
+
if (request.status === 200) {
|
|
455
|
+
const lists = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.MediaListCollection) === null || _b === void 0 ? void 0 : _b.lists;
|
|
456
|
+
if (lists.length > 0) {
|
|
457
|
+
const { selectedList } = yield inquirer.prompt([
|
|
458
|
+
{
|
|
459
|
+
type: "list",
|
|
460
|
+
name: "selectedList",
|
|
461
|
+
message: "Select a manga list:",
|
|
462
|
+
choices: lists.map((list) => list.name),
|
|
463
|
+
pageSize: 10,
|
|
464
|
+
},
|
|
465
|
+
]);
|
|
466
|
+
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
467
|
+
if (selectedEntries) {
|
|
468
|
+
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
469
|
+
for (const [_, entry] of selectedEntries.entries.entries()) {
|
|
470
|
+
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
471
|
+
yield Auth.DeleteMangaById(entry === null || entry === void 0 ? void 0 : entry.id, (_c = entry === null || entry === void 0 ? void 0 : entry.media) === null || _c === void 0 ? void 0 : _c.title);
|
|
472
|
+
yield new Promise((resolve) => setTimeout(resolve, 1100));
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
console.log(`No id in entry.`);
|
|
476
|
+
console.log(entry);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
console.error("\nNo entries found.");
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
console.error(`\nNo manga(s) found in any list.`);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
console.error(`\nSomething went wrong. ${(_d = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _d === void 0 ? void 0 : _d.message}`);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
console.error(`\nFailed getting current user Id.`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
console.error(`\nPlease log in first to delete your lists.`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
console.error(`\nError deleting manga.`);
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
static DeleteMangaById(id, title) {
|
|
506
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
507
|
+
var _a, _b;
|
|
508
|
+
try {
|
|
509
|
+
const request = yield fetch(aniListEndpoint, {
|
|
510
|
+
method: "POST",
|
|
511
|
+
headers: {
|
|
512
|
+
"Content-Type": "application/json",
|
|
513
|
+
"Authorization": `Bearer ${yield Auth.RetriveAccessToken()}`,
|
|
514
|
+
},
|
|
515
|
+
body: JSON.stringify({
|
|
516
|
+
query: deleteMangaEntryMutation,
|
|
517
|
+
variables: { id },
|
|
518
|
+
}),
|
|
519
|
+
});
|
|
520
|
+
const { data, errors } = yield request.json();
|
|
521
|
+
const statusMessage = title ? getTitle(title) : "";
|
|
522
|
+
if (request.ok) {
|
|
523
|
+
const deleted = (_a = data === null || data === void 0 ? void 0 : data.DeleteMediaListEntry) === null || _a === void 0 ? void 0 : _a.deleted;
|
|
524
|
+
console.log(`del ${statusMessage} ${deleted ? "✅" : "❌"}`);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
console.error(`Error deleting manga. ${(_b = errors === null || errors === void 0 ? void 0 : errors[0]) === null || _b === void 0 ? void 0 : _b.message}`);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
catch (error) {
|
|
531
|
+
console.error(`Error deleting manga. ${id} ${error instanceof Error ? error.message : error}`);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
static Write(status) {
|
|
536
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
537
|
+
var _a;
|
|
538
|
+
try {
|
|
539
|
+
if (!(yield Auth.isLoggedIn())) {
|
|
540
|
+
console.error(`\nPlease login to use this feature.`);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
const query = saveTextActivityMutation;
|
|
544
|
+
const variables = {
|
|
545
|
+
status: status +
|
|
546
|
+
`<br><br><br><br>*Written using [@irfanshadikrishad/anilist](https://www.npmjs.com/package/@irfanshadikrishad/anilist).*`,
|
|
547
|
+
};
|
|
548
|
+
const data = yield fetcher(query, variables);
|
|
549
|
+
if (!data) {
|
|
550
|
+
console.error(`\nSomething went wrong. ${data}.`);
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
const savedActivity = (_a = data.data) === null || _a === void 0 ? void 0 : _a.SaveTextActivity;
|
|
554
|
+
if (savedActivity === null || savedActivity === void 0 ? void 0 : savedActivity.id) {
|
|
555
|
+
console.log(`\n[${savedActivity.id}] status saved successfully!`);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
catch (error) {
|
|
559
|
+
console.error(`\n${error.message}`);
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
static callAnimeImporter() {
|
|
564
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
565
|
+
try {
|
|
566
|
+
const { source } = yield inquirer.prompt([
|
|
567
|
+
{
|
|
568
|
+
type: "list",
|
|
569
|
+
name: "source",
|
|
570
|
+
message: "Select a source:",
|
|
571
|
+
choices: [
|
|
572
|
+
{ name: "Exported JSON file.", value: 1 },
|
|
573
|
+
{ name: "MyAnimeList (XML)", value: 2 },
|
|
574
|
+
],
|
|
575
|
+
pageSize: 10,
|
|
576
|
+
},
|
|
577
|
+
]);
|
|
578
|
+
switch (source) {
|
|
579
|
+
case 1:
|
|
580
|
+
yield AniList.importAnime();
|
|
581
|
+
break;
|
|
582
|
+
case 2:
|
|
583
|
+
yield MyAnimeList.importAnime();
|
|
584
|
+
break;
|
|
585
|
+
default:
|
|
586
|
+
console.log(`\nInvalid Choice.`);
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
catch (error) {
|
|
591
|
+
console.error(`\n${error.message}`);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
static callMangaImporter() {
|
|
596
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
597
|
+
try {
|
|
598
|
+
const { source } = yield inquirer.prompt([
|
|
599
|
+
{
|
|
600
|
+
type: "list",
|
|
601
|
+
name: "source",
|
|
602
|
+
message: "Select a source:",
|
|
603
|
+
choices: [
|
|
604
|
+
{ name: "Exported JSON file.", value: 1 },
|
|
605
|
+
{ name: "MyAnimeList (XML)", value: 2 },
|
|
606
|
+
],
|
|
607
|
+
pageSize: 10,
|
|
608
|
+
},
|
|
609
|
+
]);
|
|
610
|
+
switch (source) {
|
|
611
|
+
case 1:
|
|
612
|
+
yield AniList.importManga();
|
|
613
|
+
break;
|
|
614
|
+
case 2:
|
|
615
|
+
yield MyAnimeList.importManga();
|
|
616
|
+
break;
|
|
617
|
+
default:
|
|
618
|
+
console.log(`\nInvalid Choice.`);
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
catch (error) {
|
|
623
|
+
console.error(`\n${error.message}`);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}
|
|
226
627
|
}
|
|
227
|
-
export {
|
|
628
|
+
export { Auth };
|