@irfanshadikrishad/anilist 1.0.5 → 1.0.7
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/CHANGELOG.md +18 -0
- package/CODE_OF_CONDUCT.md +43 -0
- package/CONTRIBUTING.md +75 -0
- package/README.md +232 -204
- package/bin/helpers/auth.d.ts +1 -1
- package/bin/helpers/auth.js +42 -28
- package/bin/helpers/fetcher.js +1 -2
- package/bin/helpers/lists.js +29 -50
- package/bin/helpers/more.d.ts +5 -1
- package/bin/helpers/more.js +235 -78
- package/bin/helpers/mutations.d.ts +3 -1
- package/bin/helpers/mutations.js +34 -21
- package/bin/helpers/queries.d.ts +2 -2
- package/bin/helpers/queries.js +120 -118
- package/bin/helpers/types.d.ts +11 -0
- package/bin/helpers/types.js +1 -0
- package/bin/helpers/workers.d.ts +15 -1
- package/bin/helpers/workers.js +203 -1
- package/bin/index.js +47 -3
- package/package.json +33 -5
package/bin/helpers/auth.js
CHANGED
|
@@ -36,7 +36,7 @@ function storeAccessToken(token) {
|
|
|
36
36
|
fs.writeFileSync(save_path, token, { encoding: "utf8" });
|
|
37
37
|
}
|
|
38
38
|
catch (error) {
|
|
39
|
-
console.error(
|
|
39
|
+
console.error(`\nError storing acess-token. ${error.message}`);
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
}
|
|
@@ -78,23 +78,21 @@ function anilistUserLogin(clientId, clientSecret) {
|
|
|
78
78
|
console.log(`\nWelcome Back, ${name}!`);
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
-
console.log(
|
|
81
|
+
console.log(`\nLogged in successfull!`);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
else {
|
|
85
|
-
console.error("
|
|
85
|
+
console.error("\nFailed to get access token:", token_Data);
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
function currentUserInfo() {
|
|
90
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
91
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
92
|
-
|
|
93
|
-
if (loggedIn) {
|
|
94
|
-
const sToken = yield retriveAccessToken();
|
|
92
|
+
if (yield isLoggedIn()) {
|
|
95
93
|
const headers = {
|
|
96
94
|
"Content-Type": "application/json",
|
|
97
|
-
Authorization: `Bearer ${
|
|
95
|
+
Authorization: `Bearer ${yield retriveAccessToken()}`,
|
|
98
96
|
};
|
|
99
97
|
const request = yield fetch(aniListEndpoint, {
|
|
100
98
|
method: "POST",
|
|
@@ -110,26 +108,35 @@ function currentUserInfo() {
|
|
|
110
108
|
perPage: 10,
|
|
111
109
|
});
|
|
112
110
|
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;
|
|
113
|
-
console.log(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
111
|
+
console.log(`
|
|
112
|
+
ID: ${user === null || user === void 0 ? void 0 : user.id}
|
|
113
|
+
Name: ${user === null || user === void 0 ? void 0 : user.name}
|
|
114
|
+
siteUrl: ${user === null || user === void 0 ? void 0 : user.siteUrl}
|
|
115
|
+
profileColor: ${(_c = user === null || user === void 0 ? void 0 : user.options) === null || _c === void 0 ? void 0 : _c.profileColor}
|
|
116
|
+
timeZone: ${(_d = user === null || user === void 0 ? void 0 : user.options) === null || _d === void 0 ? void 0 : _d.timezone}
|
|
117
|
+
activityMergeTime: ${(_e = user === null || user === void 0 ? void 0 : user.options) === null || _e === void 0 ? void 0 : _e.activityMergeTime}
|
|
118
|
+
donatorTier: ${user === null || user === void 0 ? void 0 : user.donatorTier}
|
|
119
|
+
donatorBadge: ${user === null || user === void 0 ? void 0 : user.donatorBadge}
|
|
120
|
+
unreadNotificationCount:${user === null || user === void 0 ? void 0 : user.unreadNotificationCount}
|
|
121
|
+
Account Created: ${new Date((user === null || user === void 0 ? void 0 : user.createdAt) * 1000).toUTCString()}
|
|
122
|
+
Account Updated: ${new Date((user === null || user === void 0 ? void 0 : user.updatedAt) * 1000).toUTCString()}
|
|
123
|
+
|
|
124
|
+
Statistics (Anime):
|
|
125
|
+
Count: ${(_g = (_f = user === null || user === void 0 ? void 0 : user.statistics) === null || _f === void 0 ? void 0 : _f.anime) === null || _g === void 0 ? void 0 : _g.count}
|
|
126
|
+
Mean Score: ${(_j = (_h = user === null || user === void 0 ? void 0 : user.statistics) === null || _h === void 0 ? void 0 : _h.anime) === null || _j === void 0 ? void 0 : _j.meanScore}
|
|
127
|
+
Minutes Watched: ${(_l = (_k = user === null || user === void 0 ? void 0 : user.statistics) === null || _k === void 0 ? void 0 : _k.anime) === null || _l === void 0 ? void 0 : _l.minutesWatched}
|
|
128
|
+
|
|
129
|
+
Statistics (Manga):
|
|
130
|
+
Count: ${(_o = (_m = user === null || user === void 0 ? void 0 : user.statistics) === null || _m === void 0 ? void 0 : _m.manga) === null || _o === void 0 ? void 0 : _o.count}
|
|
131
|
+
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
|
+
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
|
+
`);
|
|
126
134
|
console.log(`\nRecent Activities:`);
|
|
127
|
-
activities.length > 0
|
|
128
|
-
activities.map(({
|
|
129
|
-
progress
|
|
130
|
-
? console.log(`${status} ${progress} of ${getTitle(media === null || media === void 0 ? void 0 : media.title)}`)
|
|
131
|
-
: console.log(`${status} ${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
|
|
135
|
+
if (activities.length > 0) {
|
|
136
|
+
activities.map(({ status, progress, media }) => {
|
|
137
|
+
console.log(`${status} ${progress ? `${progress} of ` : ""}${getTitle(media === null || media === void 0 ? void 0 : media.title)}`);
|
|
132
138
|
});
|
|
139
|
+
}
|
|
133
140
|
return user;
|
|
134
141
|
}
|
|
135
142
|
else {
|
|
@@ -145,8 +152,7 @@ function currentUserInfo() {
|
|
|
145
152
|
}
|
|
146
153
|
function isLoggedIn() {
|
|
147
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
|
|
149
|
-
if (isTokenStored !== null) {
|
|
155
|
+
if ((yield retriveAccessToken()) !== null) {
|
|
150
156
|
return true;
|
|
151
157
|
}
|
|
152
158
|
else {
|
|
@@ -159,7 +165,7 @@ function logoutUser() {
|
|
|
159
165
|
if (fs.existsSync(save_path)) {
|
|
160
166
|
try {
|
|
161
167
|
fs.unlinkSync(save_path);
|
|
162
|
-
console.log(
|
|
168
|
+
console.log(`\nLogout successful. See you soon, ${yield currentUsersName()}.`);
|
|
163
169
|
}
|
|
164
170
|
catch (error) {
|
|
165
171
|
console.error("\nError logging out:", error);
|
|
@@ -173,6 +179,10 @@ function logoutUser() {
|
|
|
173
179
|
function currentUsersId() {
|
|
174
180
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
181
|
var _a;
|
|
182
|
+
if (!(yield isLoggedIn())) {
|
|
183
|
+
console.log(`\nUser not logged in.`);
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
176
186
|
const request = yield fetch(aniListEndpoint, {
|
|
177
187
|
method: "POST",
|
|
178
188
|
headers: {
|
|
@@ -193,6 +203,10 @@ function currentUsersId() {
|
|
|
193
203
|
function currentUsersName() {
|
|
194
204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
205
|
var _a;
|
|
206
|
+
if (!(yield isLoggedIn())) {
|
|
207
|
+
console.log(`\nUser not logged in.`);
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
196
210
|
const request = yield fetch(aniListEndpoint, {
|
|
197
211
|
method: "POST",
|
|
198
212
|
headers: {
|
package/bin/helpers/fetcher.js
CHANGED
|
@@ -24,11 +24,10 @@ function fetcher(query, variables) {
|
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
25
|
var _a;
|
|
26
26
|
try {
|
|
27
|
-
const LOGGEDIN = yield isLoggedIn();
|
|
28
27
|
const headers = {
|
|
29
28
|
"content-type": "application/json",
|
|
30
29
|
};
|
|
31
|
-
if (
|
|
30
|
+
if (yield isLoggedIn()) {
|
|
32
31
|
headers["Authorization"] = `Bearer ${yield retriveAccessToken()}`;
|
|
33
32
|
}
|
|
34
33
|
const request = yield fetch(aniListEndpoint, {
|
package/bin/helpers/lists.js
CHANGED
|
@@ -61,8 +61,7 @@ function getTrending(count) {
|
|
|
61
61
|
},
|
|
62
62
|
]);
|
|
63
63
|
// Lets save to the list now
|
|
64
|
-
|
|
65
|
-
if (ISLOGGEDIN) {
|
|
64
|
+
if (yield isLoggedIn()) {
|
|
66
65
|
const query = addAnimeToListMutation;
|
|
67
66
|
const variables = {
|
|
68
67
|
mediaId: selectedAnime,
|
|
@@ -137,8 +136,7 @@ function getPopular(count) {
|
|
|
137
136
|
},
|
|
138
137
|
]);
|
|
139
138
|
// Lets save to the list now
|
|
140
|
-
|
|
141
|
-
if (ISLOGGEDIN) {
|
|
139
|
+
if (yield isLoggedIn()) {
|
|
142
140
|
const query = addAnimeToListMutation;
|
|
143
141
|
const variables = {
|
|
144
142
|
mediaId: selectedAnime,
|
|
@@ -171,10 +169,8 @@ function loggedInUsersAnimeLists() {
|
|
|
171
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
170
|
var _a, _b, _c, _d, _e;
|
|
173
171
|
try {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const userID = yield currentUsersId();
|
|
177
|
-
if (userID) {
|
|
172
|
+
if (yield isLoggedIn()) {
|
|
173
|
+
if (yield currentUsersId()) {
|
|
178
174
|
const request = yield fetch(aniListEndpoint, {
|
|
179
175
|
method: "POST",
|
|
180
176
|
headers: {
|
|
@@ -183,7 +179,7 @@ function loggedInUsersAnimeLists() {
|
|
|
183
179
|
},
|
|
184
180
|
body: JSON.stringify({
|
|
185
181
|
query: currentUserAnimeList,
|
|
186
|
-
variables: { id:
|
|
182
|
+
variables: { id: yield currentUsersId() },
|
|
187
183
|
}),
|
|
188
184
|
});
|
|
189
185
|
const response = yield request.json();
|
|
@@ -233,8 +229,7 @@ function loggedInUsersAnimeLists() {
|
|
|
233
229
|
},
|
|
234
230
|
]);
|
|
235
231
|
// Lets save to the list now
|
|
236
|
-
|
|
237
|
-
if (ISLOGGEDIN) {
|
|
232
|
+
if (yield isLoggedIn()) {
|
|
238
233
|
const query = addAnimeToListMutation;
|
|
239
234
|
const variables = {
|
|
240
235
|
mediaId: selectedAnime,
|
|
@@ -283,8 +278,7 @@ function loggedInUsersMangaLists() {
|
|
|
283
278
|
return __awaiter(this, void 0, void 0, function* () {
|
|
284
279
|
var _a, _b, _c, _d, _e, _f;
|
|
285
280
|
try {
|
|
286
|
-
|
|
287
|
-
if (loggedIn) {
|
|
281
|
+
if (yield isLoggedIn()) {
|
|
288
282
|
const userID = yield currentUsersId();
|
|
289
283
|
if (userID) {
|
|
290
284
|
const request = yield fetch(aniListEndpoint, {
|
|
@@ -344,8 +338,7 @@ function loggedInUsersMangaLists() {
|
|
|
344
338
|
},
|
|
345
339
|
]);
|
|
346
340
|
// Save the selected manga to the selected list type
|
|
347
|
-
|
|
348
|
-
if (ISLOGGEDIN) {
|
|
341
|
+
if (yield isLoggedIn()) {
|
|
349
342
|
const query = addMangaToListMutation;
|
|
350
343
|
const variables = {
|
|
351
344
|
mediaId: selectedManga,
|
|
@@ -400,8 +393,7 @@ function loggedInUsersMangaLists() {
|
|
|
400
393
|
function deleteAnimeCollection() {
|
|
401
394
|
return __awaiter(this, void 0, void 0, function* () {
|
|
402
395
|
var _a, _b, _c, _d;
|
|
403
|
-
|
|
404
|
-
if (loggedIn) {
|
|
396
|
+
if (yield isLoggedIn()) {
|
|
405
397
|
const userID = yield currentUsersId();
|
|
406
398
|
if (userID) {
|
|
407
399
|
const request = yield fetch(aniListEndpoint, {
|
|
@@ -431,7 +423,7 @@ function deleteAnimeCollection() {
|
|
|
431
423
|
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
432
424
|
if (selectedEntries) {
|
|
433
425
|
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
434
|
-
for (const [
|
|
426
|
+
for (const [_, entry] of selectedEntries.entries.entries()) {
|
|
435
427
|
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
436
428
|
yield deleteAnimeByAnimeId(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);
|
|
437
429
|
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
@@ -496,8 +488,7 @@ function deleteAnimeByAnimeId(id, title) {
|
|
|
496
488
|
function deleteMangaCollection() {
|
|
497
489
|
return __awaiter(this, void 0, void 0, function* () {
|
|
498
490
|
var _a, _b, _c, _d;
|
|
499
|
-
|
|
500
|
-
if (loggedIn) {
|
|
491
|
+
if (yield isLoggedIn()) {
|
|
501
492
|
const userID = yield currentUsersId();
|
|
502
493
|
if (userID) {
|
|
503
494
|
const request = yield fetch(aniListEndpoint, {
|
|
@@ -527,7 +518,7 @@ function deleteMangaCollection() {
|
|
|
527
518
|
const selectedEntries = lists.find((list) => list.name === selectedList);
|
|
528
519
|
if (selectedEntries) {
|
|
529
520
|
console.log(`\nDeleting entries of '${selectedEntries.name}':`);
|
|
530
|
-
for (const [
|
|
521
|
+
for (const [_, entry] of selectedEntries.entries.entries()) {
|
|
531
522
|
if (entry === null || entry === void 0 ? void 0 : entry.id) {
|
|
532
523
|
yield deleteMangaByMangaId(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);
|
|
533
524
|
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
@@ -561,12 +552,12 @@ function deleteMangaCollection() {
|
|
|
561
552
|
}
|
|
562
553
|
function deleteMangaByMangaId(id, title) {
|
|
563
554
|
return __awaiter(this, void 0, void 0, function* () {
|
|
564
|
-
var _a, _b
|
|
555
|
+
var _a, _b;
|
|
565
556
|
try {
|
|
566
557
|
const request = yield fetch(aniListEndpoint, {
|
|
567
558
|
method: "POST",
|
|
568
559
|
headers: {
|
|
569
|
-
"
|
|
560
|
+
"Content-Type": "application/json",
|
|
570
561
|
Authorization: `Bearer ${yield retriveAccessToken()}`,
|
|
571
562
|
},
|
|
572
563
|
body: JSON.stringify({
|
|
@@ -574,18 +565,18 @@ function deleteMangaByMangaId(id, title) {
|
|
|
574
565
|
variables: { id },
|
|
575
566
|
}),
|
|
576
567
|
});
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
568
|
+
const { data, errors } = yield request.json();
|
|
569
|
+
const statusMessage = title ? getTitle(title) : "";
|
|
570
|
+
if (request.ok) {
|
|
571
|
+
const deleted = (_a = data === null || data === void 0 ? void 0 : data.DeleteMediaListEntry) === null || _a === void 0 ? void 0 : _a.deleted;
|
|
572
|
+
console.log(`del ${statusMessage} ${deleted ? "✅" : "❌"}`);
|
|
581
573
|
}
|
|
582
574
|
else {
|
|
583
|
-
console.
|
|
584
|
-
console.log(response);
|
|
575
|
+
console.error(`Error deleting manga. ${(_b = errors === null || errors === void 0 ? void 0 : errors[0]) === null || _b === void 0 ? void 0 : _b.message}`);
|
|
585
576
|
}
|
|
586
577
|
}
|
|
587
578
|
catch (error) {
|
|
588
|
-
console.
|
|
579
|
+
console.error(`Error deleting manga. ${id} ${error instanceof Error ? error.message : error}`);
|
|
589
580
|
}
|
|
590
581
|
});
|
|
591
582
|
}
|
|
@@ -594,24 +585,13 @@ function getUpcomingAnimes(count) {
|
|
|
594
585
|
var _a, _b, _c, _d, _e;
|
|
595
586
|
try {
|
|
596
587
|
const { nextSeason, nextYear } = getNextSeasonAndYear();
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if (loggedIn) {
|
|
602
|
-
headers["Authorization"] = `Bearer ${yield retriveAccessToken()}`;
|
|
603
|
-
}
|
|
604
|
-
const request = yield fetch(aniListEndpoint, {
|
|
605
|
-
method: "POST",
|
|
606
|
-
headers: headers,
|
|
607
|
-
body: JSON.stringify({
|
|
608
|
-
query: upcomingAnimesQuery,
|
|
609
|
-
variables: { nextSeason, nextYear, perPage: count },
|
|
610
|
-
}),
|
|
588
|
+
const request = yield fetcher(upcomingAnimesQuery, {
|
|
589
|
+
nextSeason,
|
|
590
|
+
nextYear,
|
|
591
|
+
perPage: count,
|
|
611
592
|
});
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
const upcoming = (_c = (_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.media) !== null && _c !== void 0 ? _c : [];
|
|
593
|
+
if (request) {
|
|
594
|
+
const upcoming = (_c = (_b = (_a = request === null || request === void 0 ? void 0 : request.data) === null || _a === void 0 ? void 0 : _a.Page) === null || _b === void 0 ? void 0 : _b.media) !== null && _c !== void 0 ? _c : [];
|
|
615
595
|
const { selectedAnime } = yield inquirer.prompt([
|
|
616
596
|
{
|
|
617
597
|
type: "list",
|
|
@@ -640,8 +620,7 @@ function getUpcomingAnimes(count) {
|
|
|
640
620
|
},
|
|
641
621
|
]);
|
|
642
622
|
// Lets save to the list now
|
|
643
|
-
|
|
644
|
-
if (ISLOGGEDIN) {
|
|
623
|
+
if (yield isLoggedIn()) {
|
|
645
624
|
const query = addAnimeToListMutation;
|
|
646
625
|
const variables = { mediaId: selectedAnime, status: selectedListType };
|
|
647
626
|
const response = yield fetcher(query, variables);
|
|
@@ -655,7 +634,7 @@ function getUpcomingAnimes(count) {
|
|
|
655
634
|
}
|
|
656
635
|
}
|
|
657
636
|
else {
|
|
658
|
-
console.error(`\nSomething went wrong. ${(_e =
|
|
637
|
+
console.error(`\nSomething went wrong. ${(_e = request === null || request === void 0 ? void 0 : request.errors[0]) === null || _e === void 0 ? void 0 : _e.message}`);
|
|
659
638
|
}
|
|
660
639
|
}
|
|
661
640
|
catch (error) {
|
package/bin/helpers/more.d.ts
CHANGED
|
@@ -4,4 +4,8 @@ declare function getAnimeSearchResults(search: string, count: number): Promise<v
|
|
|
4
4
|
declare function getMangaSearchResults(search: string, count: number): Promise<void>;
|
|
5
5
|
declare function deleteUserActivities(): Promise<void>;
|
|
6
6
|
declare function writeTextActivity(status: string): Promise<void>;
|
|
7
|
-
|
|
7
|
+
declare function exportAnimeList(): Promise<void>;
|
|
8
|
+
declare function exportMangaList(): Promise<void>;
|
|
9
|
+
declare function importAnimeList(): Promise<void>;
|
|
10
|
+
declare function importMangaList(): Promise<void>;
|
|
11
|
+
export { getUserInfoByUsername, getAnimeDetailsByID, getAnimeSearchResults, getMangaSearchResults, deleteUserActivities, writeTextActivity, exportAnimeList, exportMangaList, importAnimeList, importMangaList, };
|