e621-client 1.2.2 → 1.2.3
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 +47 -47
- package/dist/client/E621ApiClient.js +3 -3
- package/package.json +24 -24
- package/src/client/E621ApiClient.ts +6 -6
- package/demo.ts +0 -12
package/README.md
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
# e621 Client
|
|
2
|
-
|
|
3
|
-
This is a small client to do some stuff with the e621 API. It is created to fit my needs, but you can use it too, if it works for you.
|
|
4
|
-
|
|
5
|
-
I can't guarantee it will work in the future, so I recommend you just use another package instead or build a client yourself.
|
|
6
|
-
|
|
7
|
-
### Supported Endpoints
|
|
8
|
-
|
|
9
|
-
- `/favorites`
|
|
10
|
-
- `/users`
|
|
11
|
-
- `/users/:id`
|
|
12
|
-
- `/posts`
|
|
13
|
-
- `/posts/:id`
|
|
14
|
-
|
|
15
|
-
### Getting Started
|
|
16
|
-
|
|
17
|
-
Just create an instance of the client like so:
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
const client = new E621ApiClient({
|
|
21
|
-
client: "Your client name",
|
|
22
|
-
isBrowser: false,
|
|
23
|
-
});
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Now you can use it to do some stuff:
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
// not useful but still here (like me)
|
|
30
|
-
const posts = await client.getPosts();
|
|
31
|
-
|
|
32
|
-
// search posts by tags
|
|
33
|
-
const postsWithTags = await client.getPosts({
|
|
34
|
-
tags: "male score:>100",
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// search users by names (* for wildcards)
|
|
38
|
-
const toms = await client.getUsers({
|
|
39
|
-
nameMatches: "tom*",
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// if you have credentials set, they will be sent with your requests as well:
|
|
43
|
-
client.setCredentials({
|
|
44
|
-
username: "HornyFurry",
|
|
45
|
-
apiKey: "wouldntyouliketoknowweatherboy",
|
|
46
|
-
});
|
|
47
|
-
```
|
|
1
|
+
# e621 Client
|
|
2
|
+
|
|
3
|
+
This is a small client to do some stuff with the e621 API. It is created to fit my needs, but you can use it too, if it works for you.
|
|
4
|
+
|
|
5
|
+
I can't guarantee it will work in the future, so I recommend you just use another package instead or build a client yourself.
|
|
6
|
+
|
|
7
|
+
### Supported Endpoints
|
|
8
|
+
|
|
9
|
+
- `/favorites`
|
|
10
|
+
- `/users`
|
|
11
|
+
- `/users/:id`
|
|
12
|
+
- `/posts`
|
|
13
|
+
- `/posts/:id`
|
|
14
|
+
|
|
15
|
+
### Getting Started
|
|
16
|
+
|
|
17
|
+
Just create an instance of the client like so:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const client = new E621ApiClient({
|
|
21
|
+
client: "Your client name",
|
|
22
|
+
isBrowser: false,
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Now you can use it to do some stuff:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// not useful but still here (like me)
|
|
30
|
+
const posts = await client.getPosts();
|
|
31
|
+
|
|
32
|
+
// search posts by tags
|
|
33
|
+
const postsWithTags = await client.getPosts({
|
|
34
|
+
tags: "male score:>100",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// search users by names (* for wildcards)
|
|
38
|
+
const toms = await client.getUsers({
|
|
39
|
+
nameMatches: "tom*",
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// if you have credentials set, they will be sent with your requests as well:
|
|
43
|
+
client.setCredentials({
|
|
44
|
+
username: "HornyFurry",
|
|
45
|
+
apiKey: "wouldntyouliketoknowweatherboy",
|
|
46
|
+
});
|
|
47
|
+
```
|
|
@@ -73,15 +73,15 @@ class E621ApiClient {
|
|
|
73
73
|
var _a, _b;
|
|
74
74
|
// max page size on e621 api
|
|
75
75
|
const favorites = [];
|
|
76
|
-
const limit =
|
|
76
|
+
const limit = 320;
|
|
77
77
|
let page = 1;
|
|
78
78
|
while (true) {
|
|
79
79
|
if (this.debugLogs) {
|
|
80
80
|
const user = (_a = options.userId) !== null && _a !== void 0 ? _a : (_b = this.credentials) === null || _b === void 0 ? void 0 : _b.username;
|
|
81
|
-
console.info(
|
|
81
|
+
console.info("User", user, "page", page);
|
|
82
82
|
}
|
|
83
83
|
const posts = yield this.getFavorites(Object.assign(Object.assign({}, options), { page: String(page++), limit: String(limit) }));
|
|
84
|
-
if (posts.length === 0)
|
|
84
|
+
if (posts.length === 0 || posts.length < limit)
|
|
85
85
|
break;
|
|
86
86
|
favorites.push(...posts);
|
|
87
87
|
yield (0, utils_1.delay)(this.batchRateLimit);
|
package/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "e621-client",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "jest",
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"prepublishOnly": "tsc"
|
|
10
|
-
},
|
|
11
|
-
"keywords": [],
|
|
12
|
-
"author": "Tommus",
|
|
13
|
-
"license": "ISC",
|
|
14
|
-
"description": "A simple client for the e621 API",
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"@types/jest": "^29.5.12",
|
|
17
|
-
"@types/node": "^20.14.2",
|
|
18
|
-
"jest": "^29.7.0",
|
|
19
|
-
"prettier": "^3.3.1",
|
|
20
|
-
"ts-jest": "^29.2.3",
|
|
21
|
-
"ts-node": "^10.9.2",
|
|
22
|
-
"typescript": "^5.4.5"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "e621-client",
|
|
3
|
+
"version": "1.2.3",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "tsc"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "Tommus",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"description": "A simple client for the e621 API",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/jest": "^29.5.12",
|
|
17
|
+
"@types/node": "^20.14.2",
|
|
18
|
+
"jest": "^29.7.0",
|
|
19
|
+
"prettier": "^3.3.1",
|
|
20
|
+
"ts-jest": "^29.2.3",
|
|
21
|
+
"ts-node": "^10.9.2",
|
|
22
|
+
"typescript": "^5.4.5"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -113,7 +113,7 @@ export class E621ApiClient {
|
|
|
113
113
|
|
|
114
114
|
// Favorites
|
|
115
115
|
public async getFavorites(
|
|
116
|
-
options: GetFavoritesOptions = {}
|
|
116
|
+
options: GetFavoritesOptions = {}
|
|
117
117
|
): Promise<E621Post[]> {
|
|
118
118
|
const response = await this.get<GetFavoritesResponse>({
|
|
119
119
|
route: "favorites",
|
|
@@ -123,17 +123,17 @@ export class E621ApiClient {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
public async getAllFavorites(
|
|
126
|
-
options: GetAllFavoritesOptions = {}
|
|
126
|
+
options: GetAllFavoritesOptions = {}
|
|
127
127
|
): Promise<E621Post[]> {
|
|
128
128
|
// max page size on e621 api
|
|
129
129
|
const favorites: E621Post[] = [];
|
|
130
|
-
const limit =
|
|
130
|
+
const limit = 320;
|
|
131
131
|
let page = 1;
|
|
132
132
|
|
|
133
133
|
while (true) {
|
|
134
134
|
if (this.debugLogs) {
|
|
135
135
|
const user = options.userId ?? this.credentials?.username;
|
|
136
|
-
console.info(
|
|
136
|
+
console.info("User", user, "page", page);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
const posts = await this.getFavorites({
|
|
@@ -142,7 +142,7 @@ export class E621ApiClient {
|
|
|
142
142
|
limit: String(limit),
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
-
if (posts.length === 0) break;
|
|
145
|
+
if (posts.length === 0 || posts.length < limit) break;
|
|
146
146
|
favorites.push(...posts);
|
|
147
147
|
await delay(this.batchRateLimit);
|
|
148
148
|
}
|
|
@@ -187,7 +187,7 @@ export class E621ApiClient {
|
|
|
187
187
|
return null;
|
|
188
188
|
} else {
|
|
189
189
|
throw new Error(
|
|
190
|
-
`Request to ${route} failed with status code ${response.status}: "${response.statusText}"
|
|
190
|
+
`Request to ${route} failed with status code ${response.status}: "${response.statusText}"`
|
|
191
191
|
);
|
|
192
192
|
}
|
|
193
193
|
}
|
package/demo.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { E621ApiClient } from "./src/client/E621ApiClient";
|
|
2
|
-
|
|
3
|
-
async function demo() {
|
|
4
|
-
const client = new E621ApiClient({
|
|
5
|
-
isBrowser: false,
|
|
6
|
-
client: "EstoBox (by Tommus621 on e621)",
|
|
7
|
-
});
|
|
8
|
-
const favs = await client.getFavorites({ userId: "964986", page: "2" });
|
|
9
|
-
console.log(favs.length);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
demo().finally();
|