e621-client 1.0.7 → 1.1.0

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.
@@ -28,13 +28,13 @@ export interface UserResponse {
28
28
  }
29
29
  export interface E621User {
30
30
  id: number;
31
+ name: string;
32
+ createdAt: Date;
31
33
  profile: {
32
- name: string;
33
34
  level: number;
34
35
  about: string;
35
36
  artInfo: string;
36
37
  avatarId: number | null;
37
- createdAt: Date;
38
38
  levelString: string;
39
39
  };
40
40
  counts: {
@@ -4,13 +4,13 @@ exports.parseUser = void 0;
4
4
  function parseUser(user) {
5
5
  return {
6
6
  id: user.id,
7
+ name: user.name,
8
+ createdAt: new Date(user.created_at),
7
9
  profile: {
8
- name: user.name,
9
10
  level: user.level,
10
11
  about: user.profile_about,
11
12
  artInfo: user.profile_artinfo,
12
13
  avatarId: user.avatar_id,
13
- createdAt: new Date(user.created_at),
14
14
  levelString: user.level_string,
15
15
  },
16
16
  counts: {
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "e621-client",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
7
- "build": "tsc"
7
+ "build": "tsc",
8
+ "publish": "npm run build & npm publish"
8
9
  },
9
10
  "keywords": [],
10
11
  "author": "Tommus",
@@ -1,140 +1,169 @@
1
- import { E621Post, parsePost } from "../types/e621/E621Post";
2
- import { E621User, UserResponse, parseUser } from "../types/e621/E621User";
3
- import {
4
- GetFavoritesResponse,
5
- GetPostResponse,
6
- GetPostsResponse,
7
- } from "../types/responses";
8
- import { ensureArray, translateOptions } from "../utils";
9
- import { E621ApiHeaders } from "./E621ApiHeaders";
10
-
11
- export interface E621ApiOptions {
12
- client: string;
13
- isBrowser: boolean;
14
- credentials?: Credentials;
15
- }
16
-
17
- export type GetOptions = {
18
- route: Route;
19
- params?: Params;
20
- headers?: E621ApiHeaders;
21
- };
22
-
23
- export interface Credentials {
24
- username: string;
25
- apiKey: string;
26
- }
27
-
28
- export type EntityId = string | number;
29
- export type Route = string | number | (string | number)[];
30
- export type Params = Record<string, string>;
31
- export type Pagination = { limit?: string; page?: string };
32
-
33
- export type GetUsersOptions = { nameMatches?: string } & Params & Pagination;
34
- export type GetPostsOptions = { tags?: string } & Pagination;
35
- export type GetFavoritesOptions = { userId?: string } & Pagination;
36
-
37
- export class E621ApiClient {
38
- protected static readonly BASE_URL = "https://e621.net/";
39
-
40
- private readonly client: string;
41
- private readonly isBrowser: boolean;
42
- private credentials: Credentials | null = null;
43
-
44
- constructor(options: E621ApiOptions) {
45
- this.client = options.client;
46
- this.isBrowser = options.isBrowser;
47
- this.credentials = options.credentials || null;
48
- }
49
-
50
- // Users
51
- public async getUsers(options: GetUsersOptions = {}): Promise<E621User[]> {
52
- const users = await this.get<UserResponse[]>({
53
- route: "users",
54
- params: translateOptions(options, {
55
- nameMatches: "search[name_matches]",
56
- }),
57
- });
58
- return users?.map(parseUser) || [];
59
- }
60
-
61
- public async getUserById(id: EntityId): Promise<E621User | null> {
62
- const user = await this.get<UserResponse>({ route: ["users", id] });
63
- return user ? parseUser(user) : null;
64
- }
65
-
66
- // Posts
67
- public async getPosts(options: GetPostsOptions = {}): Promise<E621Post[]> {
68
- const response = await this.get<GetPostsResponse>({
69
- route: "posts",
70
- params: options,
71
- });
72
- return response?.posts.map(parsePost) || [];
73
- }
74
-
75
- public async getPostById(id: EntityId): Promise<E621Post | null> {
76
- const response = await this.get<GetPostResponse>({ route: ["posts", id] });
77
- return response?.post ? parsePost(response.post) : null;
78
- }
79
-
80
- // Favorites
81
- public async getFavorites(
82
- options: GetFavoritesOptions = {}
83
- ): Promise<E621Post[]> {
84
- const response = await this.get<GetFavoritesResponse>({
85
- route: "favorites",
86
- params: translateOptions(options, { userId: "user_id" }),
87
- });
88
- return response?.posts?.map(parsePost) || [];
89
- }
90
-
91
- // Account
92
- public setCredentials(credentials: Credentials | null): E621ApiClient {
93
- this.credentials = credentials;
94
- return this;
95
- }
96
-
97
- public async checkCredentials(credentials?: Credentials): Promise<boolean> {
98
- if (credentials) {
99
- this.setCredentials(credentials);
100
- }
101
-
102
- const headers = new E621ApiHeaders();
103
- if (!this.isBrowser) {
104
- headers.addUserAgent(this.client);
105
- }
106
-
107
- return await fetch(this.buildUrl("favorites"), {
108
- headers: headers.addAuthorization(this.credentials).build(),
109
- })
110
- .then((res) => res.ok)
111
- .catch(() => false);
112
- }
113
-
114
- public async get<E>({
115
- route,
116
- params,
117
- headers = new E621ApiHeaders(),
118
- }: GetOptions): Promise<E | null> {
119
- if (!this.isBrowser) {
120
- headers.addUserAgent(this.client);
121
- }
122
-
123
- const response = await fetch(this.buildUrl(route, params), {
124
- method: "GET",
125
- headers: headers.addAuthorization(this.credentials).build(),
126
- });
127
- return response.json().catch(() => null);
128
- }
129
-
130
- private buildUrl(route: Route, params: Params = {}): string {
131
- const queryParams = new URLSearchParams(params);
132
- const url = E621ApiClient.BASE_URL + ensureArray(route).join("/") + ".json";
133
-
134
- if (this.isBrowser) {
135
- queryParams.set("_client", this.client);
136
- }
137
-
138
- return queryParams.size > 0 ? `${url}?${queryParams}` : url;
139
- }
140
- }
1
+ import { E621Post, parsePost } from "../types/e621/E621Post";
2
+ import { E621User, UserResponse, parseUser } from "../types/e621/E621User";
3
+ import {
4
+ GetFavoritesResponse,
5
+ GetPostResponse,
6
+ GetPostsResponse,
7
+ } from "../types/responses";
8
+ import { ensureArray, translateOptions } from "../utils";
9
+ import { E621ApiHeaders } from "./E621ApiHeaders";
10
+
11
+ export interface E621ApiOptions {
12
+ client: string;
13
+ isBrowser: boolean;
14
+ credentials?: Credentials;
15
+ }
16
+
17
+ export type GetOptions = {
18
+ route: Route;
19
+ params?: Params;
20
+ headers?: E621ApiHeaders;
21
+ };
22
+
23
+ export interface Credentials {
24
+ username: string;
25
+ apiKey: string;
26
+ }
27
+
28
+ export type EntityId = string | number;
29
+ export type Route = string | number | (string | number)[];
30
+ export type Params = Record<string, string>;
31
+ export type Pagination = { limit?: string; page?: string };
32
+
33
+ export type GetUsersOptions = { nameMatches?: string } & Params & Pagination;
34
+ export type GetPostsOptions = { tags?: string } & Pagination;
35
+ export type GetFavoritesOptions = { userId?: string } & Pagination;
36
+ export type GetAllFavoritesOptions = { userId?: string };
37
+
38
+ export class E621ApiClient {
39
+ protected static readonly BASE_URL = "https://e621.net/";
40
+
41
+ private readonly client: string;
42
+ private readonly isBrowser: boolean;
43
+ private credentials: Credentials | null = null;
44
+
45
+ constructor(options: E621ApiOptions) {
46
+ this.client = options.client;
47
+ this.isBrowser = options.isBrowser;
48
+ this.credentials = options.credentials || null;
49
+ }
50
+
51
+ // Users
52
+ public async getUsers(options: GetUsersOptions = {}): Promise<E621User[]> {
53
+ const users = await this.get<UserResponse[]>({
54
+ route: "users",
55
+ params: translateOptions(options, {
56
+ nameMatches: "search[name_matches]",
57
+ }),
58
+ });
59
+ return users?.map(parseUser) || [];
60
+ }
61
+
62
+ public async getUserById(id: EntityId): Promise<E621User | null> {
63
+ const user = await this.get<UserResponse>({ route: ["users", id] });
64
+ return user ? parseUser(user) : null;
65
+ }
66
+
67
+ // Posts
68
+ public async getPosts(options: GetPostsOptions = {}): Promise<E621Post[]> {
69
+ const response = await this.get<GetPostsResponse>({
70
+ route: "posts",
71
+ params: options,
72
+ });
73
+ return response?.posts.map(parsePost) || [];
74
+ }
75
+
76
+ public async getPostById(id: EntityId): Promise<E621Post | null> {
77
+ const response = await this.get<GetPostResponse>({ route: ["posts", id] });
78
+ return response?.post ? parsePost(response.post) : null;
79
+ }
80
+
81
+ // Favorites
82
+ public async getFavorites(
83
+ options: GetFavoritesOptions = {},
84
+ ): Promise<E621Post[]> {
85
+ const response = await this.get<GetFavoritesResponse>({
86
+ route: "favorites",
87
+ params: translateOptions(options, { userId: "user_id" }),
88
+ });
89
+ return response?.posts?.map(parsePost) || [];
90
+ }
91
+
92
+ public async getAllFavorites(
93
+ options: GetAllFavoritesOptions = {},
94
+ debugLogs = false,
95
+ ): Promise<E621Post[]> {
96
+ // max page size on e621 api
97
+ const favorites: E621Post[] = [];
98
+ const limit = 300;
99
+ let page = 1;
100
+
101
+ while (true) {
102
+ if (debugLogs) {
103
+ const user = options.userId ?? this.credentials?.username;
104
+ console.info(`page ${page} for user ${user}`);
105
+ }
106
+
107
+ const posts = await this.getFavorites({
108
+ ...options,
109
+ page: String(page++),
110
+ limit: String(limit),
111
+ });
112
+
113
+ if (posts.length === 0) break;
114
+ favorites.push(...posts);
115
+ }
116
+
117
+ return favorites;
118
+ }
119
+
120
+ // Account
121
+ public setCredentials(credentials: Credentials | null): E621ApiClient {
122
+ this.credentials = credentials;
123
+ return this;
124
+ }
125
+
126
+ public async checkCredentials(credentials?: Credentials): Promise<boolean> {
127
+ if (credentials) {
128
+ this.setCredentials(credentials);
129
+ }
130
+
131
+ const headers = new E621ApiHeaders();
132
+ if (!this.isBrowser) {
133
+ headers.addUserAgent(this.client);
134
+ }
135
+
136
+ return await fetch(this.buildUrl("favorites"), {
137
+ headers: headers.addAuthorization(this.credentials).build(),
138
+ })
139
+ .then((res) => res.ok)
140
+ .catch(() => false);
141
+ }
142
+
143
+ public async get<E>({
144
+ route,
145
+ params,
146
+ headers = new E621ApiHeaders(),
147
+ }: GetOptions): Promise<E | null> {
148
+ if (!this.isBrowser) {
149
+ headers.addUserAgent(this.client);
150
+ }
151
+
152
+ const response = await fetch(this.buildUrl(route, params), {
153
+ method: "GET",
154
+ headers: headers.addAuthorization(this.credentials).build(),
155
+ });
156
+ return response.json().catch(() => null);
157
+ }
158
+
159
+ private buildUrl(route: Route, params: Params = {}): string {
160
+ const queryParams = new URLSearchParams(params);
161
+ const url = E621ApiClient.BASE_URL + ensureArray(route).join("/") + ".json";
162
+
163
+ if (this.isBrowser) {
164
+ queryParams.set("_client", this.client);
165
+ }
166
+
167
+ return queryParams.size > 0 ? `${url}?${queryParams}` : url;
168
+ }
169
+ }
@@ -1,51 +1,51 @@
1
- import { Credentials } from "./E621ApiClient";
2
-
3
- export class E621ApiHeaders {
4
- private readonly value: Record<string, string>;
5
-
6
- constructor(value: Record<string, string> = {}) {
7
- this.value = value;
8
- }
9
-
10
- public addAuthorization(credentials: Credentials | null): E621ApiHeaders {
11
- if (credentials) {
12
- this.value.Authorization = E621ApiHeaders.buildAuthorization(credentials);
13
- }
14
- return this;
15
- }
16
-
17
- public addFormContentType(): E621ApiHeaders {
18
- this.value["Content-Type"] =
19
- "application/x-www-form-urlencoded; charset=UTF-8";
20
- return this;
21
- }
22
-
23
- public addUserAgent(userAgent: string): E621ApiHeaders {
24
- this.value["User-Agent"] = userAgent;
25
- return this;
26
- }
27
-
28
- public build(): Record<string, string> {
29
- return this.value;
30
- }
31
-
32
- protected static buildAuthorization({ username, apiKey }: Credentials) {
33
- const creds = `${username}:${apiKey}`;
34
-
35
- if (canUseWindow()) {
36
- return `Basic ${window.btoa(creds)}`;
37
- } else if (canUseBuffer()) {
38
- return `Basic ${Buffer.from(creds).toString("base64")}`;
39
- } else {
40
- throw new Error("Environment does not support base64 encoding");
41
- }
42
- }
43
- }
44
-
45
- function canUseWindow() {
46
- return typeof window !== "undefined";
47
- }
48
-
49
- function canUseBuffer() {
50
- return typeof Buffer !== "undefined" && typeof Buffer.from === "function";
51
- }
1
+ import { Credentials } from "./E621ApiClient";
2
+
3
+ export class E621ApiHeaders {
4
+ private readonly value: Record<string, string>;
5
+
6
+ constructor(value: Record<string, string> = {}) {
7
+ this.value = value;
8
+ }
9
+
10
+ public addAuthorization(credentials: Credentials | null): E621ApiHeaders {
11
+ if (credentials) {
12
+ this.value.Authorization = E621ApiHeaders.buildAuthorization(credentials);
13
+ }
14
+ return this;
15
+ }
16
+
17
+ public addFormContentType(): E621ApiHeaders {
18
+ this.value["Content-Type"] =
19
+ "application/x-www-form-urlencoded; charset=UTF-8";
20
+ return this;
21
+ }
22
+
23
+ public addUserAgent(userAgent: string): E621ApiHeaders {
24
+ this.value["User-Agent"] = userAgent;
25
+ return this;
26
+ }
27
+
28
+ public build(): Record<string, string> {
29
+ return this.value;
30
+ }
31
+
32
+ protected static buildAuthorization({ username, apiKey }: Credentials) {
33
+ const creds = `${username}:${apiKey}`;
34
+
35
+ if (canUseWindow()) {
36
+ return `Basic ${window.btoa(creds)}`;
37
+ } else if (canUseBuffer()) {
38
+ return `Basic ${Buffer.from(creds).toString("base64")}`;
39
+ } else {
40
+ throw new Error("Environment does not support base64 encoding");
41
+ }
42
+ }
43
+ }
44
+
45
+ function canUseWindow() {
46
+ return typeof window !== "undefined";
47
+ }
48
+
49
+ function canUseBuffer() {
50
+ return typeof Buffer !== "undefined" && typeof Buffer.from === "function";
51
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./client/E621ApiClient";
2
- export * from "./types/e621/E621User";
3
- export * from "./types/e621/E621Post";
1
+ export * from "./client/E621ApiClient";
2
+ export * from "./types/e621/E621User";
3
+ export * from "./types/e621/E621Post";
@@ -1,173 +1,173 @@
1
- export interface PostResponse {
2
- id: number;
3
- created_at: string;
4
- updated_at: string;
5
- file: {
6
- width: number;
7
- height: number;
8
- ext: string;
9
- size: number;
10
- md5: string;
11
- url: string;
12
- };
13
- preview: {
14
- width: number;
15
- height: number;
16
- url: string | null;
17
- };
18
- sample: {
19
- has: boolean;
20
- width: number;
21
- height: number;
22
- url: string | null;
23
- };
24
- score: {
25
- up: number;
26
- down: number;
27
- total: number;
28
- };
29
- tags: {
30
- general: string[];
31
- artist: string[];
32
- copyright: string[];
33
- character: string[];
34
- species: string[];
35
- invalid: string[];
36
- meta: string[];
37
- lore: string[];
38
- };
39
- locked_tags: string[];
40
- change_seq: number;
41
- flags: {
42
- pending: boolean;
43
- flagged: boolean;
44
- note_locked: boolean;
45
- status_locked: boolean;
46
- rating_locked: boolean;
47
- deleted: boolean;
48
- };
49
- rating: string;
50
- fav_count: number;
51
- sources: string[];
52
- pools: number[];
53
- relationships: {
54
- parent_id: number | null;
55
- has_children: boolean;
56
- has_active_children: boolean;
57
- children: number[];
58
- };
59
- approver_id: number | null;
60
- uploader_id: number;
61
- description: string;
62
- comment_count: number;
63
- is_favorited: boolean;
64
- has_notes: boolean;
65
- duration: number | null;
66
- }
67
-
68
- export interface E621Post {
69
- id: number;
70
- createdAt: Date;
71
- updatedAt: Date;
72
- file: {
73
- width: number;
74
- height: number;
75
- ext: string;
76
- size: number;
77
- md5: string;
78
- url: string;
79
- };
80
- preview: {
81
- width: number;
82
- height: number;
83
- url: string | null;
84
- };
85
- sample: {
86
- has: boolean;
87
- width: number;
88
- height: number;
89
- url: string | null;
90
- };
91
- score: {
92
- up: number;
93
- down: number;
94
- total: number;
95
- };
96
- tags: {
97
- general: string[];
98
- artist: string[];
99
- copyright: string[];
100
- character: string[];
101
- species: string[];
102
- invalid: string[];
103
- meta: string[];
104
- lore: string[];
105
- };
106
- lockedTags: string[];
107
- changeSeq: number;
108
- flags: {
109
- pending: boolean;
110
- flagged: boolean;
111
- noteLocked: boolean;
112
- statusLocked: boolean;
113
- ratingLocked: boolean;
114
- deleted: boolean;
115
- };
116
- rating: string;
117
- favCount: number;
118
- sources: string[];
119
- pools: number[];
120
- relationships: {
121
- parentId: number | null;
122
- hasChildren: boolean;
123
- hasActiveChildren: boolean;
124
- children: number[];
125
- };
126
- approverId: number | null;
127
- uploaderId: number;
128
- description: string;
129
- commentCount: number;
130
- isFavorited: boolean;
131
- hasNotes: boolean;
132
- duration: number | null;
133
- }
134
-
135
- export function parsePost(post: PostResponse): E621Post {
136
- return {
137
- id: post.id,
138
- createdAt: new Date(post.created_at),
139
- updatedAt: new Date(post.updated_at),
140
- file: post.file,
141
- preview: post.preview,
142
- sample: post.sample,
143
- score: post.score,
144
- tags: post.tags,
145
- lockedTags: post.locked_tags,
146
- changeSeq: post.change_seq,
147
- flags: {
148
- pending: post.flags.pending,
149
- flagged: post.flags.flagged,
150
- noteLocked: post.flags.note_locked,
151
- statusLocked: post.flags.status_locked,
152
- ratingLocked: post.flags.rating_locked,
153
- deleted: post.flags.deleted,
154
- },
155
- rating: post.rating,
156
- favCount: post.fav_count,
157
- sources: post.sources,
158
- pools: post.pools,
159
- relationships: {
160
- parentId: post.relationships.parent_id,
161
- hasChildren: post.relationships.has_children,
162
- hasActiveChildren: post.relationships.has_active_children,
163
- children: post.relationships.children,
164
- },
165
- approverId: post.approver_id,
166
- uploaderId: post.uploader_id,
167
- description: post.description,
168
- commentCount: post.comment_count,
169
- isFavorited: post.is_favorited,
170
- hasNotes: post.has_notes,
171
- duration: post.duration,
172
- };
173
- }
1
+ export interface PostResponse {
2
+ id: number;
3
+ created_at: string;
4
+ updated_at: string;
5
+ file: {
6
+ width: number;
7
+ height: number;
8
+ ext: string;
9
+ size: number;
10
+ md5: string;
11
+ url: string;
12
+ };
13
+ preview: {
14
+ width: number;
15
+ height: number;
16
+ url: string | null;
17
+ };
18
+ sample: {
19
+ has: boolean;
20
+ width: number;
21
+ height: number;
22
+ url: string | null;
23
+ };
24
+ score: {
25
+ up: number;
26
+ down: number;
27
+ total: number;
28
+ };
29
+ tags: {
30
+ general: string[];
31
+ artist: string[];
32
+ copyright: string[];
33
+ character: string[];
34
+ species: string[];
35
+ invalid: string[];
36
+ meta: string[];
37
+ lore: string[];
38
+ };
39
+ locked_tags: string[];
40
+ change_seq: number;
41
+ flags: {
42
+ pending: boolean;
43
+ flagged: boolean;
44
+ note_locked: boolean;
45
+ status_locked: boolean;
46
+ rating_locked: boolean;
47
+ deleted: boolean;
48
+ };
49
+ rating: string;
50
+ fav_count: number;
51
+ sources: string[];
52
+ pools: number[];
53
+ relationships: {
54
+ parent_id: number | null;
55
+ has_children: boolean;
56
+ has_active_children: boolean;
57
+ children: number[];
58
+ };
59
+ approver_id: number | null;
60
+ uploader_id: number;
61
+ description: string;
62
+ comment_count: number;
63
+ is_favorited: boolean;
64
+ has_notes: boolean;
65
+ duration: number | null;
66
+ }
67
+
68
+ export interface E621Post {
69
+ id: number;
70
+ createdAt: Date;
71
+ updatedAt: Date;
72
+ file: {
73
+ width: number;
74
+ height: number;
75
+ ext: string;
76
+ size: number;
77
+ md5: string;
78
+ url: string;
79
+ };
80
+ preview: {
81
+ width: number;
82
+ height: number;
83
+ url: string | null;
84
+ };
85
+ sample: {
86
+ has: boolean;
87
+ width: number;
88
+ height: number;
89
+ url: string | null;
90
+ };
91
+ score: {
92
+ up: number;
93
+ down: number;
94
+ total: number;
95
+ };
96
+ tags: {
97
+ general: string[];
98
+ artist: string[];
99
+ copyright: string[];
100
+ character: string[];
101
+ species: string[];
102
+ invalid: string[];
103
+ meta: string[];
104
+ lore: string[];
105
+ };
106
+ lockedTags: string[];
107
+ changeSeq: number;
108
+ flags: {
109
+ pending: boolean;
110
+ flagged: boolean;
111
+ noteLocked: boolean;
112
+ statusLocked: boolean;
113
+ ratingLocked: boolean;
114
+ deleted: boolean;
115
+ };
116
+ rating: string;
117
+ favCount: number;
118
+ sources: string[];
119
+ pools: number[];
120
+ relationships: {
121
+ parentId: number | null;
122
+ hasChildren: boolean;
123
+ hasActiveChildren: boolean;
124
+ children: number[];
125
+ };
126
+ approverId: number | null;
127
+ uploaderId: number;
128
+ description: string;
129
+ commentCount: number;
130
+ isFavorited: boolean;
131
+ hasNotes: boolean;
132
+ duration: number | null;
133
+ }
134
+
135
+ export function parsePost(post: PostResponse): E621Post {
136
+ return {
137
+ id: post.id,
138
+ createdAt: new Date(post.created_at),
139
+ updatedAt: new Date(post.updated_at),
140
+ file: post.file,
141
+ preview: post.preview,
142
+ sample: post.sample,
143
+ score: post.score,
144
+ tags: post.tags,
145
+ lockedTags: post.locked_tags,
146
+ changeSeq: post.change_seq,
147
+ flags: {
148
+ pending: post.flags.pending,
149
+ flagged: post.flags.flagged,
150
+ noteLocked: post.flags.note_locked,
151
+ statusLocked: post.flags.status_locked,
152
+ ratingLocked: post.flags.rating_locked,
153
+ deleted: post.flags.deleted,
154
+ },
155
+ rating: post.rating,
156
+ favCount: post.fav_count,
157
+ sources: post.sources,
158
+ pools: post.pools,
159
+ relationships: {
160
+ parentId: post.relationships.parent_id,
161
+ hasChildren: post.relationships.has_children,
162
+ hasActiveChildren: post.relationships.has_active_children,
163
+ children: post.relationships.children,
164
+ },
165
+ approverId: post.approver_id,
166
+ uploaderId: post.uploader_id,
167
+ description: post.description,
168
+ commentCount: post.comment_count,
169
+ isFavorited: post.is_favorited,
170
+ hasNotes: post.has_notes,
171
+ duration: post.duration,
172
+ };
173
+ }
@@ -1,108 +1,108 @@
1
- export interface UserResponse {
2
- wiki_page_version_count: number;
3
- artist_version_count: number;
4
- pool_version_count: number;
5
- forum_post_count: number;
6
- comment_count: number;
7
- flag_count: number;
8
- favorite_count: number;
9
- positive_feedback_count: number;
10
- neutral_feedback_count: number;
11
- negative_feedback_count: number;
12
- upload_limit: number;
13
- profile_about: string;
14
- profile_artinfo: string;
15
- id: number;
16
- created_at: string;
17
- name: string;
18
- level: number;
19
- base_upload_limit: number;
20
- post_upload_count: number;
21
- post_update_count: number;
22
- note_update_count: number;
23
- is_banned: boolean;
24
- can_approve_posts: boolean;
25
- can_upload_free: boolean;
26
- level_string: string;
27
- avatar_id: number | null;
28
- }
29
-
30
- export interface E621User {
31
- id: number;
32
- name: string;
33
- createdAt: Date;
34
-
35
- profile: {
36
- level: number;
37
- about: string;
38
- artInfo: string;
39
- avatarId: number | null;
40
- levelString: string;
41
- };
42
-
43
- counts: {
44
- wikiPageVersion: number;
45
- artistVersion: number;
46
- poolVersion: number;
47
- forumPost: number;
48
- comment: number;
49
- flag: number;
50
- favorite: number;
51
- positiveFeedback: number;
52
- neutralFeedback: number;
53
- negativeFeedback: number;
54
- };
55
-
56
- limits: {
57
- upload: number;
58
- baseUpload: number;
59
- postUpload: number;
60
- postUpdate: number;
61
- noteUpdate: number;
62
- };
63
-
64
- isBanned: boolean;
65
- canApprovePosts: boolean;
66
- canUploadFree: boolean;
67
- }
68
-
69
- export function parseUser(user: UserResponse): E621User {
70
- return {
71
- id: user.id,
72
- name: user.name,
73
- createdAt: new Date(user.created_at),
74
-
75
- profile: {
76
- level: user.level,
77
- about: user.profile_about,
78
- artInfo: user.profile_artinfo,
79
- avatarId: user.avatar_id,
80
- levelString: user.level_string,
81
- },
82
-
83
- counts: {
84
- wikiPageVersion: user.wiki_page_version_count,
85
- artistVersion: user.artist_version_count,
86
- poolVersion: user.pool_version_count,
87
- forumPost: user.forum_post_count,
88
- comment: user.comment_count,
89
- flag: user.flag_count,
90
- favorite: user.favorite_count,
91
- positiveFeedback: user.positive_feedback_count,
92
- neutralFeedback: user.neutral_feedback_count,
93
- negativeFeedback: user.negative_feedback_count,
94
- },
95
-
96
- limits: {
97
- upload: user.upload_limit,
98
- baseUpload: user.base_upload_limit,
99
- postUpload: user.post_upload_count,
100
- postUpdate: user.post_update_count,
101
- noteUpdate: user.note_update_count,
102
- },
103
-
104
- isBanned: user.is_banned,
105
- canApprovePosts: user.can_approve_posts,
106
- canUploadFree: user.can_upload_free,
107
- };
108
- }
1
+ export interface UserResponse {
2
+ wiki_page_version_count: number;
3
+ artist_version_count: number;
4
+ pool_version_count: number;
5
+ forum_post_count: number;
6
+ comment_count: number;
7
+ flag_count: number;
8
+ favorite_count: number;
9
+ positive_feedback_count: number;
10
+ neutral_feedback_count: number;
11
+ negative_feedback_count: number;
12
+ upload_limit: number;
13
+ profile_about: string;
14
+ profile_artinfo: string;
15
+ id: number;
16
+ created_at: string;
17
+ name: string;
18
+ level: number;
19
+ base_upload_limit: number;
20
+ post_upload_count: number;
21
+ post_update_count: number;
22
+ note_update_count: number;
23
+ is_banned: boolean;
24
+ can_approve_posts: boolean;
25
+ can_upload_free: boolean;
26
+ level_string: string;
27
+ avatar_id: number | null;
28
+ }
29
+
30
+ export interface E621User {
31
+ id: number;
32
+ name: string;
33
+ createdAt: Date;
34
+
35
+ profile: {
36
+ level: number;
37
+ about: string;
38
+ artInfo: string;
39
+ avatarId: number | null;
40
+ levelString: string;
41
+ };
42
+
43
+ counts: {
44
+ wikiPageVersion: number;
45
+ artistVersion: number;
46
+ poolVersion: number;
47
+ forumPost: number;
48
+ comment: number;
49
+ flag: number;
50
+ favorite: number;
51
+ positiveFeedback: number;
52
+ neutralFeedback: number;
53
+ negativeFeedback: number;
54
+ };
55
+
56
+ limits: {
57
+ upload: number;
58
+ baseUpload: number;
59
+ postUpload: number;
60
+ postUpdate: number;
61
+ noteUpdate: number;
62
+ };
63
+
64
+ isBanned: boolean;
65
+ canApprovePosts: boolean;
66
+ canUploadFree: boolean;
67
+ }
68
+
69
+ export function parseUser(user: UserResponse): E621User {
70
+ return {
71
+ id: user.id,
72
+ name: user.name,
73
+ createdAt: new Date(user.created_at),
74
+
75
+ profile: {
76
+ level: user.level,
77
+ about: user.profile_about,
78
+ artInfo: user.profile_artinfo,
79
+ avatarId: user.avatar_id,
80
+ levelString: user.level_string,
81
+ },
82
+
83
+ counts: {
84
+ wikiPageVersion: user.wiki_page_version_count,
85
+ artistVersion: user.artist_version_count,
86
+ poolVersion: user.pool_version_count,
87
+ forumPost: user.forum_post_count,
88
+ comment: user.comment_count,
89
+ flag: user.flag_count,
90
+ favorite: user.favorite_count,
91
+ positiveFeedback: user.positive_feedback_count,
92
+ neutralFeedback: user.neutral_feedback_count,
93
+ negativeFeedback: user.negative_feedback_count,
94
+ },
95
+
96
+ limits: {
97
+ upload: user.upload_limit,
98
+ baseUpload: user.base_upload_limit,
99
+ postUpload: user.post_upload_count,
100
+ postUpdate: user.post_update_count,
101
+ noteUpdate: user.note_update_count,
102
+ },
103
+
104
+ isBanned: user.is_banned,
105
+ canApprovePosts: user.can_approve_posts,
106
+ canUploadFree: user.can_upload_free,
107
+ };
108
+ }
@@ -1,13 +1,13 @@
1
- import { PostResponse } from "./e621/E621Post";
2
-
3
- export type GetFavoritesResponse = {
4
- posts: PostResponse[] | null;
5
- };
6
-
7
- export type GetPostResponse = {
8
- post: PostResponse | null;
9
- };
10
-
11
- export type GetPostsResponse = {
12
- posts: PostResponse[];
13
- };
1
+ import { PostResponse } from "./e621/E621Post";
2
+
3
+ export type GetFavoritesResponse = {
4
+ posts: PostResponse[] | null;
5
+ };
6
+
7
+ export type GetPostResponse = {
8
+ post: PostResponse | null;
9
+ };
10
+
11
+ export type GetPostsResponse = {
12
+ posts: PostResponse[];
13
+ };
package/src/utils.ts CHANGED
@@ -1,19 +1,19 @@
1
- export function ensureArray<T>(value: T | T[]): T[] {
2
- if (Array.isArray(value)) {
3
- return value;
4
- }
5
- return [value];
6
- }
7
-
8
- export function translateOptions<Options extends Record<string, string>>(
9
- options: Options,
10
- table: Partial<Options>
11
- ): Record<string, string> {
12
- const params: Record<string, string> = {};
13
-
14
- for (const [key, value] of Object.entries(options)) {
15
- params[table[key] ?? key] = value;
16
- }
17
-
18
- return params;
19
- }
1
+ export function ensureArray<T>(value: T | T[]): T[] {
2
+ if (Array.isArray(value)) {
3
+ return value;
4
+ }
5
+ return [value];
6
+ }
7
+
8
+ export function translateOptions<Options extends Record<string, string>>(
9
+ options: Options,
10
+ table: Partial<Options>,
11
+ ): Record<string, string> {
12
+ const params: Record<string, string> = {};
13
+
14
+ for (const [key, value] of Object.entries(options)) {
15
+ params[table[key] ?? key] = value;
16
+ }
17
+
18
+ return params;
19
+ }