@riffyh/adapter-nhentai 1.0.3 → 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.
- package/dist/index.d.mts +6 -1
- package/dist/index.mjs +12 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { DataSource } from "@riffyh/commons";
|
|
2
2
|
|
|
3
|
+
//#region src/types/Options.d.ts
|
|
4
|
+
interface Options {
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
3
8
|
//#region src/index.d.ts
|
|
4
|
-
declare const nhentai: () => DataSource;
|
|
9
|
+
declare const nhentai: (options?: Options) => DataSource;
|
|
5
10
|
//#endregion
|
|
6
11
|
export { nhentai };
|
|
7
12
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import pThrottle from "p-throttle";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
//#region src/getGalery.ts
|
|
3
|
+
const getGallery = (options) => pThrottle({
|
|
4
|
+
limit: options?.apiKey ? 45 : 20,
|
|
4
5
|
interval: 60 * 1e3
|
|
5
6
|
})(async ({ id }) => {
|
|
6
|
-
const data = await fetch(`https://nhentai.net/api/v2/galleries/${id}`).then((o) => {
|
|
7
|
+
const data = await fetch(`https://nhentai.net/api/v2/galleries/${id}`, { headers: options?.apiKey ? { Authorization: `Key ${options.apiKey}` } : {} }).then((o) => {
|
|
7
8
|
if (o.ok) return o.json();
|
|
8
9
|
else throw o;
|
|
9
10
|
});
|
|
@@ -34,8 +35,10 @@ const getGallery = pThrottle({
|
|
|
34
35
|
}))
|
|
35
36
|
};
|
|
36
37
|
});
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/getListing.ts
|
|
40
|
+
const getListing = (options) => pThrottle({
|
|
41
|
+
limit: options?.apiKey ? 10 : 20,
|
|
39
42
|
interval: 60 * 1e3
|
|
40
43
|
})(async ({ searchQuery, page }) => {
|
|
41
44
|
const payload = new URLSearchParams({
|
|
@@ -43,7 +46,7 @@ const getListing = pThrottle({
|
|
|
43
46
|
sort: "date",
|
|
44
47
|
page: page.toString()
|
|
45
48
|
});
|
|
46
|
-
const data = await fetch(`https://nhentai.net/api/v2/search?${payload.toString()}`).then((o) => {
|
|
49
|
+
const data = await fetch(`https://nhentai.net/api/v2/search?${payload.toString()}`, { headers: options?.apiKey ? { Authorization: `Key ${options.apiKey}` } : {} }).then((o) => {
|
|
47
50
|
if (o.ok) return o.json();
|
|
48
51
|
else throw o;
|
|
49
52
|
});
|
|
@@ -73,13 +76,13 @@ const getImage = ({ url }) => fetch(url).then(async (o) => {
|
|
|
73
76
|
});
|
|
74
77
|
//#endregion
|
|
75
78
|
//#region src/index.ts
|
|
76
|
-
const nhentai = () => {
|
|
79
|
+
const nhentai = (options) => {
|
|
77
80
|
return {
|
|
78
81
|
key: "nh",
|
|
79
82
|
name: "nhentai",
|
|
80
83
|
iconUrl: "https://nhentai.net/favicon.png",
|
|
81
|
-
getGallery,
|
|
82
|
-
getListing,
|
|
84
|
+
getGallery: getGallery(options),
|
|
85
|
+
getListing: getListing(options),
|
|
83
86
|
getImage
|
|
84
87
|
};
|
|
85
88
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/getGalery.ts","../src/getListing.ts","../src/getImage.ts","../src/index.ts"],"sourcesContent":["import pThrottle from \"p-throttle\";\nimport { key } from \"./key\";\n\nimport type { DataSource, Gallery } from \"@riffyh/commons\";\nimport type { NhentaiGallery } from \"./types/NhentaiGallery\";\nimport type { Options } from \"./types/Options\";\n\nexport const getGallery = (options?: Options): DataSource[\"getGallery\"] =>\n pThrottle({\n limit: options?.apiKey ? 45 : 20,\n interval: 60 * 1000,\n })(async ({ id }) => {\n const data = await fetch(`https://nhentai.net/api/v2/galleries/${id}`, {\n headers: options?.apiKey\n ? {\n Authorization: `Key ${options.apiKey}`,\n }\n : {},\n }).then((o) => {\n if (o.ok) return o.json() as Promise<NhentaiGallery>;\n else throw o;\n });\n\n const gallery: Gallery = {\n id: data.id.toString(),\n key,\n title: {\n display: data.title.english ?? data.title.pretty ?? data.title.japanese,\n original: data.title.japanese || null,\n },\n cover: {\n src: `https://t4.nhentai.net/${data.cover.path}`,\n width: data.cover.width,\n height: data.cover.height,\n },\n pages: data.pages.map((page) => ({\n order: page.number,\n src: `https://i4.nhentai.net/${page.path}`,\n width: page.width,\n height: page.height,\n })),\n tags: data.tags.map((tag) => ({\n id: tag.id.toString(),\n key,\n name: tag.name,\n type: tag.type,\n slug: tag.slug,\n })),\n };\n\n return gallery;\n });\n","import pThrottle from \"p-throttle\";\nimport { key } from \"./key\";\n\nimport type { DataSource, ListingResult } from \"@riffyh/commons\";\nimport type { NhentaiSearchResult } from \"./types/NhentaiSearchResult\";\nimport type { Options } from \"./types/Options\";\n\nexport const getListing = (options?: Options): DataSource[\"getListing\"] =>\n pThrottle({\n limit: options?.apiKey ? 10 : 20,\n interval: 60 * 1000,\n })(async ({ searchQuery, page }) => {\n const payload = new URLSearchParams({\n query: searchQuery ?? \"-thisisrandomstringtomakesurethatthereisnoanytagbeingexcluded\",\n sort: \"date\",\n page: page.toString(),\n });\n\n const data = await fetch(`https://nhentai.net/api/v2/search?${payload.toString()}`, {\n headers: options?.apiKey\n ? {\n Authorization: `Key ${options.apiKey}`,\n }\n : {},\n }).then((o) => {\n if (o.ok) return o.json() as Promise<NhentaiSearchResult>;\n else throw o;\n });\n\n const result: ListingResult = {\n galleries: data.result.map((result) => ({\n id: result.id.toString(),\n key,\n title: {\n display: result.english_title ?? result.japanese_title,\n original: null,\n },\n cover: {\n src: `https://t4.nhentai.net/${result.thumbnail}`,\n width: result.thumbnail_width,\n height: result.thumbnail_height,\n },\n })),\n currentPage: page,\n maximumPages: data.num_pages,\n };\n\n return result;\n });\n","import type { DataSource } from \"@riffyh/commons\";\n\nexport const getImage: DataSource[\"getImage\"] = ({ url }) =>\n fetch(url).then(async (o) => {\n if (o.ok) return Buffer.from(await o.arrayBuffer());\n else throw o;\n });\n","import type { DataSource } from \"@riffyh/commons\";\nimport { getGallery } from \"./getGalery\";\nimport { getListing } from \"./getListing\";\nimport { getImage } from \"./getImage\";\nimport { key } from \"./key\";\n\nimport type { Options } from \"./types/Options\";\n\nexport const nhentai = (options?: Options): DataSource => {\n return {\n key,\n name: \"nhentai\",\n iconUrl: \"https://nhentai.net/favicon.png\",\n getGallery: getGallery(options),\n getListing: getListing(options),\n getImage,\n };\n};\n"],"mappings":";;AAOA,MAAa,cAAc,YACzB,UAAU;CACR,OAAO,SAAS,SAAS,KAAK;CAC9B,UAAU,KAAK;CAChB,CAAC,CAAC,OAAO,EAAE,SAAS;CACnB,MAAM,OAAO,MAAM,MAAM,wCAAwC,MAAM,EACrE,SAAS,SAAS,SACd,EACE,eAAe,OAAO,QAAQ,UAC/B,GACD,EAAE,EACP,CAAC,CAAC,MAAM,MAAM;AACb,MAAI,EAAE,GAAI,QAAO,EAAE,MAAM;MACpB,OAAM;GACX;AA6BF,QA3ByB;EACvB,IAAI,KAAK,GAAG,UAAU;EACtB,KAAA;EACA,OAAO;GACL,SAAS,KAAK,MAAM,WAAW,KAAK,MAAM,UAAU,KAAK,MAAM;GAC/D,UAAU,KAAK,MAAM,YAAY;GAClC;EACD,OAAO;GACL,KAAK,0BAA0B,KAAK,MAAM;GAC1C,OAAO,KAAK,MAAM;GAClB,QAAQ,KAAK,MAAM;GACpB;EACD,OAAO,KAAK,MAAM,KAAK,UAAU;GAC/B,OAAO,KAAK;GACZ,KAAK,0BAA0B,KAAK;GACpC,OAAO,KAAK;GACZ,QAAQ,KAAK;GACd,EAAE;EACH,MAAM,KAAK,KAAK,KAAK,SAAS;GAC5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