e621-client 1.1.2 → 1.1.4
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/dist/client/E621ApiClient.js +7 -3
- package/dist/test.js +2 -2
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +1 -6
- package/package.json +2 -2
- package/src/client/E621ApiClient.ts +9 -4
- package/src/utils.ts +0 -5
|
@@ -112,16 +112,20 @@ class E621ApiClient {
|
|
|
112
112
|
if (!this.isBrowser) {
|
|
113
113
|
headers.addUserAgent(this.client);
|
|
114
114
|
}
|
|
115
|
-
const
|
|
115
|
+
const url = this.buildUrl(route, params);
|
|
116
|
+
const response = yield fetch(url, {
|
|
116
117
|
method: "GET",
|
|
117
118
|
headers: headers.addAuthorization(this.credentials).build(),
|
|
118
119
|
});
|
|
119
120
|
if (response.ok) {
|
|
120
|
-
return response.json()
|
|
121
|
+
return response.json();
|
|
121
122
|
}
|
|
122
|
-
else {
|
|
123
|
+
else if (response.status === 404) {
|
|
123
124
|
return null;
|
|
124
125
|
}
|
|
126
|
+
else {
|
|
127
|
+
throw new Error(`Request to ${route} failed with status code ${response.status}`);
|
|
128
|
+
}
|
|
125
129
|
});
|
|
126
130
|
}
|
|
127
131
|
buildUrl(route, params = {}) {
|
package/dist/test.js
CHANGED
|
@@ -16,8 +16,8 @@ function test() {
|
|
|
16
16
|
isBrowser: false,
|
|
17
17
|
client: "EstoBox (by Tommus621 on e621)",
|
|
18
18
|
});
|
|
19
|
-
const
|
|
20
|
-
console.log(
|
|
19
|
+
const favs = yield client.getFavorites({ userId: "964986", page: "2" });
|
|
20
|
+
console.log(favs.length);
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
test().finally();
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export declare function ensureArray<T>(value: T | T[]): T[];
|
|
2
2
|
export declare function translateOptions<Options extends Record<string, string>>(options: Options, table: Partial<Options>): Record<string, string>;
|
|
3
|
-
export declare function logErrorAndReturnNull(error: unknown): null;
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.translateOptions = exports.ensureArray = void 0;
|
|
4
4
|
function ensureArray(value) {
|
|
5
5
|
if (Array.isArray(value)) {
|
|
6
6
|
return value;
|
|
@@ -17,8 +17,3 @@ function translateOptions(options, table) {
|
|
|
17
17
|
return params;
|
|
18
18
|
}
|
|
19
19
|
exports.translateOptions = translateOptions;
|
|
20
|
-
function logErrorAndReturnNull(error) {
|
|
21
|
-
console.error(error);
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
exports.logErrorAndReturnNull = logErrorAndReturnNull;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "e621-client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
|
8
|
-
"
|
|
8
|
+
"prepublishOnly": "tsc"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [],
|
|
11
11
|
"author": "Tommus",
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
GetPostResponse,
|
|
6
6
|
GetPostsResponse,
|
|
7
7
|
} from "../types/responses";
|
|
8
|
-
import { ensureArray,
|
|
8
|
+
import { ensureArray, translateOptions } from "../utils";
|
|
9
9
|
import { E621ApiHeaders } from "./E621ApiHeaders";
|
|
10
10
|
|
|
11
11
|
export interface E621ApiOptions {
|
|
@@ -149,15 +149,20 @@ export class E621ApiClient {
|
|
|
149
149
|
headers.addUserAgent(this.client);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
const
|
|
152
|
+
const url = this.buildUrl(route, params);
|
|
153
|
+
const response = await fetch(url, {
|
|
153
154
|
method: "GET",
|
|
154
155
|
headers: headers.addAuthorization(this.credentials).build(),
|
|
155
156
|
});
|
|
156
157
|
|
|
157
158
|
if (response.ok) {
|
|
158
|
-
return response.json()
|
|
159
|
-
} else {
|
|
159
|
+
return response.json();
|
|
160
|
+
} else if (response.status === 404) {
|
|
160
161
|
return null;
|
|
162
|
+
} else {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Request to ${route} failed with status code ${response.status}`,
|
|
165
|
+
);
|
|
161
166
|
}
|
|
162
167
|
}
|
|
163
168
|
|