e621 1.0.9 → 2.0.0-dev.11

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.
Files changed (50) hide show
  1. package/.node-version +1 -0
  2. package/README.md +116 -187
  3. package/build/package.json +14 -11
  4. package/build/src/index.d.ts +28 -295
  5. package/build/src/index.js +83 -442
  6. package/build/src/modules/Pools.d.ts +120 -0
  7. package/build/src/modules/Pools.js +247 -0
  8. package/build/src/modules/PostSets.d.ts +88 -0
  9. package/build/src/modules/PostSets.js +182 -0
  10. package/build/src/modules/Posts.d.ts +124 -0
  11. package/build/src/modules/Posts.js +323 -0
  12. package/build/src/modules/UserFeedback.d.ts +66 -0
  13. package/build/src/modules/UserFeedback.js +134 -0
  14. package/build/src/modules/Users.d.ts +110 -0
  15. package/build/src/modules/Users.js +248 -0
  16. package/build/src/modules/WikiPages.d.ts +99 -0
  17. package/build/src/modules/WikiPages.js +208 -0
  18. package/build/src/structures/AuthenticatedUser.d.ts +109 -0
  19. package/build/src/structures/AuthenticatedUser.js +128 -0
  20. package/build/src/structures/Pool.d.ts +85 -0
  21. package/build/src/structures/Pool.js +110 -0
  22. package/build/src/structures/PoolHistory.d.ts +42 -0
  23. package/build/src/structures/PoolHistory.js +53 -0
  24. package/build/src/structures/Post.d.ts +147 -0
  25. package/build/src/structures/Post.js +155 -0
  26. package/build/src/structures/PostHistory.d.ts +52 -0
  27. package/build/src/structures/PostHistory.js +93 -0
  28. package/build/src/structures/PostSet.d.ts +71 -0
  29. package/build/src/structures/PostSet.js +91 -0
  30. package/build/src/structures/User.d.ts +62 -0
  31. package/build/src/structures/User.js +80 -0
  32. package/build/src/structures/WikiPage.d.ts +16 -0
  33. package/build/src/structures/WikiPage.js +26 -0
  34. package/build/src/structures/WikiPageHistory.d.ts +37 -0
  35. package/build/src/structures/WikiPageHistory.js +49 -0
  36. package/build/src/types/index.d.ts +92 -0
  37. package/build/src/types/pools.d.ts +60 -0
  38. package/build/src/types/post_sets.d.ts +33 -0
  39. package/build/src/types/posts.d.ts +165 -0
  40. package/build/src/types/user_feedback.d.ts +27 -0
  41. package/build/src/types/users.d.ts +277 -0
  42. package/build/src/types/wiki_pages.d.ts +65 -0
  43. package/build/src/util/FormHelper.d.ts +9 -0
  44. package/build/src/util/FormHelper.js +15 -0
  45. package/build/src/util/MultipartData.d.ts +7 -0
  46. package/build/src/util/MultipartData.js +39 -0
  47. package/build/src/util/RequestHandler.d.ts +37 -0
  48. package/build/src/util/RequestHandler.js +311 -0
  49. package/package.json +14 -11
  50. package/LICENSE +0 -21
package/.node-version ADDED
@@ -0,0 +1 @@
1
+ 16.13.0
package/README.md CHANGED
@@ -1,195 +1,124 @@
1
- # 621
2
- A module for fetching posts from e621.
1
+ # E621
2
+
3
+ The most comprehensive wrapper for e621 you'll ever find.
4
+
5
+ We support almost anything normal users can do, with plans to bring everything else in, and more later in development.
6
+
7
+ ### Features:
8
+ - [x] Creating Posts (Buffer & URL)
9
+ - [x] Listing/Creating/Editing/Voting On/Favoriting Posts
10
+ - [x] Listing/Creating/Editing/Deleting/Modifying/Adding To/Removing From Post Sets
11
+ - [x] Listing/Creating/Editing/Deleting/Modifying/Adding To/Removing From Pools
12
+ - [x] Listing/Creating/Deleting/Editing User Feedback
13
+ - [x] Reverting Pool Changes
14
+ - [x] Listing Post History
15
+ - [x] Editing The Authenticated User (all properties minus password and email)
16
+ - [ ] Deleting/Approving/Unapproving/Destroying Posts
17
+ - [ ] Creating/Solving/Deleting Post Flags
18
+ - [ ] Listing/Creating/Editing/Deleting/Modifying Wiki Pages
19
+ - [ ] Listing/Creating/Editing/Deleting/Modifying Artists
20
+ - [ ] Listing/Editing/Deleting/Modifying Tags
21
+ - [ ] General Janitorial/Moderative/Admninistrative Actions
22
+ - [ ] More Planned!
23
+
24
+ ### Not Planned:
25
+ - Dmails (routes do not support json, and I'm not scraping html)
3
26
 
4
- [![](https://nodei.co/npm/e621.png)](https://npm.im/e621)
5
27
  <hr>
6
28
 
7
- ## Usage
8
- To use this module, simply make an instance of the main class and call one of the methods. I'll be listing parameters by providing the jsdoc.
29
+ This module is structures with submodules corresponding to separate areas of the site. All of these modules are on the primary class, which can be constructed like so:
30
+ ```typescript
31
+ import E621 from "e621"; // or const E621 = require("e621");
9
32
 
10
- ## Get Posts
11
- ```ts
12
- // For regular javascript usage, switch out this for `const E621 = require("e621");
13
- import E621 from "e621";
14
- /**
15
- * Construct an instance of E621
16
- *
17
- * @param {string} [username] - your e621 username to use for requests
18
- * @param {string} [apiKey] - an api key to use for requests
19
- * @param {string[]} [blacklist=[]] - a list of tags to use to filter out posts
20
- * @param {string }[userAgent] - A user agent to use for requests
21
- * @param {boolean} [fixNullURLs=true] - If null urls should be converted to proper urls
22
- * @param {string} [baseDomain=this.baseDomain] - The domain to use for api requests
23
- * @param {boolean} [setHost=false] - If we should set the Host header on requests to e621.net (useful for proxies).
24
- * @example new E621();
25
- * @example new E621("YourUsername", "YourAPIKey");
26
- * @example new E621("YourUsername", "YourAPIKey", ["male/male"]);
27
- * @example new E621("YourUsername", "YourAPIKey", ["male/male"], "MyAwesomeProject/1.0.0");
28
- * @example new E621("YourUsername", "YourAPIKey", ["male/male"], "MyAwesomeProject/1.0.0", false);
29
- * @example new E621("YourUsername", "YourAPIKey", ["male/male"], "MyAwesomeProject/1.0.0", false, "mye621.local");
30
- * @example new E621("YourUsername", "YourAPIKey", ["male/male"], "MyAwesomeProject/1.0.0", false, "mye621.local", false);
31
- */
32
- const e = new E621();
33
+ // no options are required, see below for the options
34
+ const e621 = new E621();
33
35
 
34
- /**
35
- * Get posts from e621
36
- * @param {string[]} [tags=[]] - The tags to fetch posts for, 40 max
37
- * @param {number} [limit=25] - The, maximum amount of posts to get, 320 max
38
- * @param {number} [page=1] - The page of posts to get, see {@link https://e621.net/help/api#posts_list|E621 API Posts#List}
39
- * @returns {Promise<(Post | NullableURLPost)[]>}
40
- * @example getPosts()
41
- * @example getPosts("male bulge");
42
- * @example getPosts(["male", "bulge"]);
43
- * @example getPosts(["male", "bulge"], 5);
44
- * @example getPosts(["male", "bulge"], 5, 1);
45
- */
46
- e.getPosts(["male/male"]).then(console.log) // array of posts, see Post Structure
36
+ // the options are all an object in the first parameter, e.g.
37
+ const e621 = new E621({
38
+ authUser: "",
39
+ authKey: ""
40
+ });
47
41
 
48
- /**
49
- * Get a specifc post from e621, by id
50
- * @param {number} id - The id of the post to get
51
- * @returns {Promise<(Post | NullableURLPost)>}
52
- * @example getPostById(1391357)
53
- */
54
- e.getPostById(1391357).then(console.log) // single post, see Post Structure
55
-
56
- /**
57
- * Get a specifc post from e621, by id
58
- * @param {number} id - The id of the post to get
59
- * @returns {Promise<(Post | NullableURLPost)>}
60
- * @example getPostById(1391357)
61
- */
62
- e.getPostByMD5("6fd0b0f2237543bfeee5ca9318a97b46").then(console.log) // single post, see Post Structure
63
- ```
64
-
65
- ## Edit Post
66
- This is mostly untested, but should work
67
- ```ts
68
- import E621 from "e621";
69
- // both username & apikey are required for edits!
70
- const e = new E621("YourUsername", "YourAPIKey");
71
-
72
- // they all return a post, see Post Structure
73
- // if no reason is provided, "Edit via https://npm.im/e621" will be used.
74
-
75
- // add tag
76
- e.editPost(1022094, "Some Reason Here", "added_tag");
77
-
78
- // remove tag (notice the minus)
79
- e.editPost(1022094, "Some Reason Here", "-remove_tag");
80
-
81
- // the undefined parts are REQUIRED if you are not using the previous parameters
82
-
83
- // add source
84
- e.editPost(1022094, "Some Reason Here", undefined, "https://some.added/source");
85
-
86
- // remove source (notice the minus)
87
- e.editPost(1022094, "Some Reason Here", undefined, "-https://some.removed/source");
88
-
89
- // update parent id
90
- e.editPost(1022094, "Some Reason Here", undefined, undefined, 1097929);
91
-
92
- // set description
93
- e.editPost(1022094, "Some Reason Here", undefined, undefined, undefined, "My Amazing Post Description");
94
-
95
- // set rating - s: safe, q: questionable, e: explicit
96
- e.editPost(1022094, "Some Reason Here", undefined, undefined, undefined, undefined, "e");
97
-
98
- // set rating locked
99
- e.editPost(1022094, "Some Reason Here", undefined, undefined, undefined, undefined, undefined, true);
100
-
101
- // set note locked
102
- e.editPost(1022094, "Some Reason Here", undefined, undefined, undefined, undefined, undefined, undefined, false);
103
-
104
- // set has embedded notes
105
- e.editPost(1022094, "Some Reason Here", undefined, undefined, undefined, undefined, undefined, undefined, undefined, true);
42
+ // all of the available modules stem from this main class,
43
+ // e.g. use e621.posts.METHOD(), e621.users.METHOD()
106
44
  ```
107
45
 
108
- ## Create Post
109
- This is mostly untested, but should work
110
- ```ts
111
- import E621 from "e621";
112
- // both username & apikey are required for uploading!
113
- const e = new E621("YourUsername", "YourAPIKey");
114
-
115
- // they all return a post, see Post Structure
116
-
117
- // minimum requirements: fileURL, tags, rating
118
- e.createPost("https://pbs.twimg.com/media/EbOwnXpXkAIC5ZX.jpg:orig", ["gaokun", "bulge", "penis_outline" (...)], "e");
119
-
120
- // sources
121
- e.createPost("https://pbs.twimg.com/media/EbOwnXpXkAIC5ZX.jpg:orig", ["gaokun", "bulge", "penis_outline" (...)], "e",
122
- ["https://twitter.com/Gaokunx3", "https://twitter.com/Gaokunx3/status/1275559030522556417"]);
123
-
124
- // description
125
- e.createPost("https://pbs.twimg.com/media/EbOwnXpXkAIC5ZX.jpg:orig", ["gaokun", "bulge", "penis_outline" (...)], "e", ["https://twitter.com/Gaokunx3", "https://twitter.com/Gaokunx3/status/1275559030522556417"], "Some Description Stuff Here");
126
-
127
- // parent id
128
- e.createPost("https://pbs.twimg.com/media/EbOwnXpXkAIC5ZX.jpg:orig", ["gaokun", "bulge", "penis_outline" (...)], "e", ["https://twitter.com/Gaokunx3", "https://twitter.com/Gaokunx3/status/1275559030522556417"], "Some Description Stuff Here", 1234);
129
-
130
- // referer (?)
131
- e.createPost("https://pbs.twimg.com/media/EbOwnXpXkAIC5ZX.jpg:orig", ["gaokun", "bulge", "penis_outline" (...)], "e", ["https://twitter.com/Gaokunx3", "https://twitter.com/Gaokunx3/status/1275559030522556417"], "Some Description Stuff Here", 1234, "https://npm.im/e621");
132
-
133
- // md5 confirmation
134
- e.createPost("https://pbs.twimg.com/media/EbOwnXpXkAIC5ZX.jpg:orig", ["gaokun", "bulge", "penis_outline" (...)], "e", ["https://twitter.com/Gaokunx3", "https://twitter.com/Gaokunx3/status/1275559030522556417"], "Some Description Stuff Here", 1234, "https://npm.im/e621", "abcdefghijklmnopqrstuvwxyz123456");
135
- ```
136
-
137
- ## Post Structure
138
- Through the e621 api, some posts can have null urls. By default, we fix this by replacing it with a proper url. You can turn this off via an option in the constructor.
139
- ```ts
140
- // If you haven't used typescript, pretend this is just an object, and the values after
141
- // the colons are the type of what should be there
142
-
143
- // Post is just a version without the null value on file.url, preview.url, and sample.url
144
- interface NullableURLPost {
145
- id: string;
146
- created_at: string;
147
- updated_at: string;
148
- file: {
149
- width: number;
150
- height: number;
151
- ext: string;
152
- md5: string;
153
- url: string | null;
154
- };
155
- preview: {
156
- width: number;
157
- height: number;
158
- url: string | null;
159
- };
160
- sample: {
161
- has: boolean;
162
- height: number;
163
- width: number;
164
- url: string | null;
165
- alternates: {}; // @TODO
166
- };
167
- score: {
168
- up: number;
169
- down: number;
170
- total: number;
171
- };
172
- // a record is just a key-value pair, every key here is an array of strings
173
- tags: Record<"general" | "species" | "character" | "copyright" | "artist" | "invalid" | "lore" | "meta", string[]>;
174
- locked_tags: string[];
175
- change_seq: number;
176
- flags: Record<"pending" | "flagged" | "note_locked" | "status_locked" | "rating_locked" | "deleted", boolean>;
177
- rating: "s" | "q" | "e";
178
- fav_count: number;
179
- sources: string[];
180
- pools: number[];
181
- relationships: {
182
- parent_id: number | null;
183
- has_children: boolean;
184
- has_active_children: boolean;
185
- children: number[]
186
- };
187
- approver_id: number | null;
188
- uploader_id: number | null;
189
- description: string;
190
- comment_count: number;
191
- is_favorited: boolean;
192
- has_notes: boolean;
193
- duration: number | null;
194
- }
195
- ```
46
+ #### Options
47
+ Most of these options shouldn't be used unless you know what you're doing (you probably only need `authUser` and `authKey`, and you can set `userAgent`)
48
+ | Option | Type | Default | Description |
49
+ |:---:|:---:|:---:|:---:|
50
+ | `authUser` | String | None | User for authentication |
51
+ | `authKey` | String | None | Token for authentication |
52
+ | `userAgent` | String | [See Code](https://github.com/DonovanDMC/E621/blob/89d662f19dc76c77e28f40b18a96f9043c4e2a3a/src/types/index.d.ts#L57-L59) | UserAgent for requests |
53
+ | `reconstructStaticURL` | [See Code](https://github.com/DonovanDMC/E621/blob/89d662f19dc76c77e28f40b18a96f9043c4e2a3a/src/util/RequestHandler.ts#L254-L256) | [See Code](https://github.com/DonovanDMC/E621/blob/89d662f19dc76c77e28f40b18a96f9043c4e2a3a/src/types/index.d.ts#L63-L65) | Override default url reconstruction |
54
+ | `imageReconstructionType` | "e621" \| "yiffy" \| "local" \| null | [See Code](https://github.com/DonovanDMC/E621/blob/89d662f19dc76c77e28f40b18a96f9043c4e2a3a/src/types/index.d.ts#L39) | [See Code](https://github.com/DonovanDMC/E621/blob/89d662f19dc76c77e28f40b18a96f9043c4e2a3a/src/types/index.d.ts#L41) |
55
+ | `instanceSSL` | Boolean | true | [See Code](https://github.com/DonovanDMC/E621/blob/89d662f19dc76c77e28f40b18a96f9043c4e2a3a/src/types/index.d.ts#L03) |
56
+ | `instancePort` | Number | 443 | [See Code](https://github.com/DonovanDMC/E621/blob/89d662f19dc76c77e28f40b18a96f9043c4e2a3a/src/types/index.d.ts#L9) |
57
+ | `instanceHost` | String | e621.net | [See Code](https://github.com/DonovanDMC/E621/blob/89d662f19dc76c77e28f40b18a96f9043c4e2a3a/src/types/index.d.ts#L15) |
58
+
59
+ A map of features we support to their methods is listed below.
60
+
61
+ ## Methods
62
+ The legend for the symbols can be found after the table.
63
+ | Section | Description | Location |
64
+ |:---:|:---:|:---:|
65
+ | Pools | Get Pool | `pools.get` |
66
+ | Pools | Get Pool By Name | `pools.getByName` |
67
+ | Pools | Search Pools | `pools.search` |
68
+ | Pools | Create Pool* | `pools.create` |
69
+ | Pools | Modify Pool* | `pools.modify` |
70
+ | Pools | Delete Pool^ | `pools.delete` |
71
+ | Pools | Revert Pool* | `pools.revert` |
72
+ | Pools | Search Pool History | `pools.searchHistory` |
73
+ | Pools | Add Post To Pool | `pools.addPost` |
74
+ | Pools | Remove Post From Pool | `pools.removePost` |
75
+ | Type | Description | Location |
76
+ | Posts | Get Post By ID | `posts.get` |
77
+ | Posts | Get Post By MD5 | `posts.getByMD5` |
78
+ | Posts | Search Posts | `posts.search` |
79
+ | Posts | Create Post* | `posts.create` |
80
+ | Posts | Modify Post* | `posts.modify` |
81
+ | Posts | Vote On Post* | `posts.vote` |
82
+ | Posts | Revert Post* | `posts.revert` |
83
+ | Posts | Search Post History | `posts.searchHistory` |
84
+ | Type | Description | Location |
85
+ | Post Sets | Get Post Set | `postSets.get` |
86
+ | Post Sets | Search Sets | `postSets.search` |
87
+ | Post Sets | Create Post Set* | `postSets.create` |
88
+ | Post Sets | Modify Post Set* | `postSets.modify` |
89
+ | Post Sets | Delete Post Set* | `postSets.delete` |
90
+ | Post Sets | Add Post To Set* | `postSets.addPost` |
91
+ | Post Sets | Remove Post From Set* | `postSets.removePost` |
92
+ | Type | Description | Location |
93
+ | User Feedback | Get Feedback | `userFeedback.get` |
94
+ | User Feedback | Search Feedback | `userFeedback.search` |
95
+ | User Feedback | Create Feedback# | `userFeedback.create` |
96
+ | User Feedback | Modify Feedback# | `userFeedback.modify` |
97
+ | User Feedback | Delete Feedback# | `userFeedback.delete` |
98
+ | Type | Description | Location |
99
+ | Users | Get User (ID/Name) | `users.get` |
100
+ | Users | Search Users | `users.search` |
101
+ | Users | Get Authenticated User* | `users.getSelf` |
102
+ | Users | Edit Authenticated User* | `users.editSelf` |
103
+ | Users | Get Upload Limit* | `users.getUploadLimit` |
104
+ | Users | Get Favorites | `users.getFavorites` |
105
+ | Users | Add Favorite* | `users.addFavorite` |
106
+ | Users | Remove Favorite* | `users.removeFavorite` |
107
+ | Type | Description | Location |
108
+ | Wiki Page | Get Wiki Page | `wikiPages.get` |
109
+ | Wiki Page | Get Wiki Page (By Name) | `wikiPages.getByName` |
110
+ | Wiki Page | Search Wiki Pages | `wikiPages.search` |
111
+ | Wiki Page | Create Wiki Page* | `wikiPages.create` |
112
+ | Wiki Page | Modify Wiki Page* | `wikiPages.modify` |
113
+ | Wiki Page | Delete Wiki Page^ | `wikiPages.delete` |
114
+ | Wiki Page | Revert Wiki Page* | `wikiPages.revert` |
115
+ | Wiki Page | Search Wiki Page History | `wikiPages.searchHistory` |
116
+
117
+ #### Method Symbol Legend
118
+ | Symbol | Meaning |
119
+ |:------:|:-----------------------:|
120
+ | * | Requires Authentication |
121
+ | $ | Requires Privileged |
122
+ | ^ | Requires Janitor |
123
+ | # | Requires Moderator |
124
+ | & | Requires Admin |
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "e621",
3
- "version": "1.0.9",
4
- "description": "A module for fetching posts from e621.",
3
+ "version": "2.0.0-dev.11",
4
+ "description": "A module for interfacing with e621.",
5
5
  "main": "build/src/index.js",
6
- "types": "build/src/index.d.ts",
7
6
  "scripts": {
8
- "prepare": "rm -rf build && tsc && echo Build Finished",
9
- "build": "npm run prepare"
7
+ "build": "rm -rf build && tsc -p tsc.json && sed -i '/__exportStar(require(\".\\/types\"), exports);/d' build/src/index.js && cp -r src/types build/src",
8
+ "prepublishOnly": "npm run build",
9
+ "dev": "npm publish --tag dev"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
@@ -14,20 +14,23 @@
14
14
  },
15
15
  "keywords": [
16
16
  "e621",
17
- "api",
18
17
  "e621-api",
18
+ "api",
19
19
  "e926",
20
- "e926-api"
20
+ "e926-api",
21
+ "e6",
22
+ "e9"
21
23
  ],
22
- "author": "Donovan_DMC <hewwo@yiff.rocks> (https://donovan.is.gay)",
24
+ "author": "Donovan Daniels <hewwo@yiff.rocks>",
23
25
  "license": "MIT",
24
26
  "bugs": {
25
27
  "url": "https://github.com/DonovanDMC/E621/issues"
26
28
  },
27
29
  "homepage": "https://github.com/DonovanDMC/E621#readme",
28
30
  "devDependencies": {
29
- "@types/node": "^14.14.22",
30
- "@uwu-codes/eslint-config": "^1.0.8",
31
- "@uwu-codes/tsconfig": "^1.0.1"
31
+ "@uwu-codes/eslint-config": "^1.0.25",
32
+ "@uwu-codes/tsconfig": "^1.0.1",
33
+ "ts-node": "^10.3.0",
34
+ "typescript": "^4.4.4"
32
35
  }
33
36
  }