@riffyh/adapter-nhentai 1.1.1 → 1.2.1
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.mjs +54 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import pThrottle from "p-throttle";
|
|
2
|
-
//#region src/
|
|
2
|
+
//#region src/language.ts
|
|
3
|
+
const languageMap = {
|
|
4
|
+
12227: "en",
|
|
5
|
+
29963: "cn",
|
|
6
|
+
6346: "jp"
|
|
7
|
+
};
|
|
8
|
+
const languageKey = Object.keys(languageMap);
|
|
9
|
+
const getLanguageByTagId = (tagIds) => {
|
|
10
|
+
const targetTagId = tagIds.find((id) => languageKey.includes(id.toString()));
|
|
11
|
+
if (targetTagId) return languageMap[targetTagId] || null;
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/getGallery.ts
|
|
3
16
|
const getGallery = (options) => pThrottle({
|
|
4
17
|
limit: options?.apiKey ? 45 : 20,
|
|
5
18
|
interval: 60 * 1e3
|
|
@@ -20,6 +33,7 @@ const getGallery = (options) => pThrottle({
|
|
|
20
33
|
width: data.cover.width,
|
|
21
34
|
height: data.cover.height
|
|
22
35
|
},
|
|
36
|
+
language: getLanguageByTagId(data.tags.map((t) => t.id)),
|
|
23
37
|
pages: data.pages.map((page) => ({
|
|
24
38
|
order: page.number,
|
|
25
39
|
src: `https://i4.nhentai.net/${page.path}`,
|
|
@@ -36,6 +50,26 @@ const getGallery = (options) => pThrottle({
|
|
|
36
50
|
};
|
|
37
51
|
});
|
|
38
52
|
//#endregion
|
|
53
|
+
//#region src/functions/searchResultMapper.ts
|
|
54
|
+
const searchResultMapper = (searchResult, page) => ({
|
|
55
|
+
galleries: searchResult.result.map((result) => ({
|
|
56
|
+
id: result.id.toString(),
|
|
57
|
+
key: "nh",
|
|
58
|
+
title: {
|
|
59
|
+
display: result.english_title ?? result.japanese_title,
|
|
60
|
+
original: null
|
|
61
|
+
},
|
|
62
|
+
language: getLanguageByTagId(result.tag_ids),
|
|
63
|
+
cover: {
|
|
64
|
+
src: `https://t4.nhentai.net/${result.thumbnail}`,
|
|
65
|
+
width: result.thumbnail_width,
|
|
66
|
+
height: result.thumbnail_height
|
|
67
|
+
}
|
|
68
|
+
})),
|
|
69
|
+
currentPage: page,
|
|
70
|
+
maximumPages: searchResult.num_pages
|
|
71
|
+
});
|
|
72
|
+
//#endregion
|
|
39
73
|
//#region src/getListing.ts
|
|
40
74
|
const getListing = (options) => pThrottle({
|
|
41
75
|
limit: options?.apiKey ? 10 : 20,
|
|
@@ -46,27 +80,10 @@ const getListing = (options) => pThrottle({
|
|
|
46
80
|
sort: "date",
|
|
47
81
|
page: page.toString()
|
|
48
82
|
});
|
|
49
|
-
|
|
83
|
+
return searchResultMapper(await fetch(`https://nhentai.net/api/v2/search?${payload.toString()}`, { headers: options?.apiKey ? { Authorization: `Key ${options.apiKey}` } : {} }).then((o) => {
|
|
50
84
|
if (o.ok) return o.json();
|
|
51
85
|
else throw o;
|
|
52
|
-
});
|
|
53
|
-
return {
|
|
54
|
-
galleries: data.result.map((result) => ({
|
|
55
|
-
id: result.id.toString(),
|
|
56
|
-
key: "nh",
|
|
57
|
-
title: {
|
|
58
|
-
display: result.english_title ?? result.japanese_title,
|
|
59
|
-
original: null
|
|
60
|
-
},
|
|
61
|
-
cover: {
|
|
62
|
-
src: `https://t4.nhentai.net/${result.thumbnail}`,
|
|
63
|
-
width: result.thumbnail_width,
|
|
64
|
-
height: result.thumbnail_height
|
|
65
|
-
}
|
|
66
|
-
})),
|
|
67
|
-
currentPage: page,
|
|
68
|
-
maximumPages: data.num_pages
|
|
69
|
-
};
|
|
86
|
+
}), page);
|
|
70
87
|
});
|
|
71
88
|
//#endregion
|
|
72
89
|
//#region src/getImage.ts
|
|
@@ -75,6 +92,22 @@ const getImage = ({ url }) => fetch(url).then(async (o) => {
|
|
|
75
92
|
else throw o;
|
|
76
93
|
});
|
|
77
94
|
//#endregion
|
|
95
|
+
//#region src/getTagListing.ts
|
|
96
|
+
const getTagListing = (options) => pThrottle({
|
|
97
|
+
limit: options?.apiKey ? 15 : 30,
|
|
98
|
+
interval: 60 * 1e3
|
|
99
|
+
})(async ({ id, page }) => {
|
|
100
|
+
const payload = new URLSearchParams({
|
|
101
|
+
tag_id: id,
|
|
102
|
+
sort: "date",
|
|
103
|
+
page: page.toString()
|
|
104
|
+
});
|
|
105
|
+
return searchResultMapper(await fetch(`https://nhentai.net/api/v2/galleries/tagged?${payload.toString()}`, { headers: options?.apiKey ? { Authorization: `Key ${options.apiKey}` } : {} }).then((o) => {
|
|
106
|
+
if (o.ok) return o.json();
|
|
107
|
+
else throw o;
|
|
108
|
+
}), page);
|
|
109
|
+
});
|
|
110
|
+
//#endregion
|
|
78
111
|
//#region src/index.ts
|
|
79
112
|
const nhentai = (options) => {
|
|
80
113
|
return {
|
|
@@ -83,6 +116,7 @@ const nhentai = (options) => {
|
|
|
83
116
|
iconUrl: "https://nhentai.net/favicon.png",
|
|
84
117
|
getGallery: getGallery(options),
|
|
85
118
|
getListing: getListing(options),
|
|
119
|
+
getTagListing: getTagListing(options),
|
|
86
120
|
getImage
|
|
87
121
|
};
|
|
88
122
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/language.ts","../src/getGallery.ts","../src/functions/searchResultMapper.ts","../src/getListing.ts","../src/getImage.ts","../src/getTagListing.ts","../src/index.ts"],"sourcesContent":["import type { Language } from \"@riffyh/commons\";\n\nconst languageMap: Record<number, Language> = {\n 12227: \"en\",\n 29963: \"cn\",\n 6346: \"jp\",\n};\n\nconst languageKey = Object.keys(languageMap);\n\nexport const getLanguageByTagId = (tagIds: number[]): Language | null => {\n const targetTagId = tagIds.find((id) => languageKey.includes(id.toString()));\n\n if (targetTagId) return languageMap[targetTagId] || null;\n\n return null;\n};\n","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\";\nimport { getLanguageByTagId } from \"./language\";\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 language: getLanguageByTagId(data.tags.map((t) => t.id)),\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 type { ListingResult } from \"@riffyh/commons\";\nimport type { NhentaiSearchResult } from \"../types/NhentaiSearchResult\";\nimport { key } from \"../key\";\nimport { getLanguageByTagId } from \"../language\";\n\nexport const searchResultMapper = (\n searchResult: NhentaiSearchResult,\n page: number,\n): ListingResult => ({\n galleries: searchResult.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 language: getLanguageByTagId(result.tag_ids),\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: searchResult.num_pages,\n});\n","import pThrottle from \"p-throttle\";\n\nimport type { DataSource } from \"@riffyh/commons\";\nimport type { NhentaiSearchResult } from \"./types/NhentaiSearchResult\";\nimport type { Options } from \"./types/Options\";\nimport { searchResultMapper } from \"./functions/searchResultMapper\";\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 return searchResultMapper(data, page);\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 type { Options } from \"./types/Options\";\nimport type { NhentaiSearchResult } from \"./types/NhentaiSearchResult\";\nimport { searchResultMapper } from \"./functions/searchResultMapper\";\nimport pThrottle from \"p-throttle\";\n\nexport const getTagListing = (options?: Options): DataSource[\"getTagListing\"] =>\n pThrottle({\n limit: options?.apiKey ? 15 : 30,\n interval: 60 * 1000,\n })(async ({ id, page }) => {\n const payload = new URLSearchParams({\n tag_id: id,\n sort: \"date\",\n page: page.toString(),\n });\n\n const data = await fetch(`https://nhentai.net/api/v2/galleries/tagged?${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 return searchResultMapper(data, page);\n });\n","import type { DataSource } from \"@riffyh/commons\";\nimport { getGallery } from \"./getGallery\";\nimport { getListing } from \"./getListing\";\nimport { getImage } from \"./getImage\";\nimport { key } from \"./key\";\n\nimport type { Options } from \"./types/Options\";\nimport { getTagListing } from \"./getTagListing\";\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 getTagListing: getTagListing(options),\n getImage,\n };\n};\n"],"mappings":";;AAEA,MAAM,cAAwC;CAC5C,OAAO;CACP,OAAO;CACP,MAAM;AACR;AAEA,MAAM,cAAc,OAAO,KAAK,WAAW;AAE3C,MAAa,sBAAsB,WAAsC;CACvE,MAAM,cAAc,OAAO,MAAM,OAAO,YAAY,SAAS,GAAG,SAAS,CAAC,CAAC;CAE3E,IAAI,aAAa,OAAO,YAAY,gBAAgB;CAEpD,OAAO;AACT;;;ACRA,MAAa,cAAc,YACzB,UAAU;CACR,OAAO,SAAS,SAAS,KAAK;CAC9B,UAAU,KAAK;AACjB,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS;CACnB,MAAM,OAAO,MAAM,MAAM,wCAAwC,MAAM,EACrE,SAAS,SAAS,SACd,EACE,eAAe,OAAO,QAAQ,SAChC,IACA,CAAC,EACP,CAAC,CAAC,CAAC,MAAM,MAAM;EACb,IAAI,EAAE,IAAI,OAAO,EAAE,KAAK;OACnB,MAAM;CACb,CAAC;CA8BD,OAAO;EA3BL,IAAI,KAAK,GAAG,SAAS;EACrB,KAAA;EACA,OAAO;GACL,SAAS,KAAK,MAAM,WAAW,KAAK,MAAM,UAAU,KAAK,MAAM;GAC/D,UAAU,KAAK,MAAM,YAAY;EACnC;EACA,OAAO;GACL,KAAK,0BAA0B,KAAK,MAAM;GAC1C,OAAO,KAAK,MAAM;GAClB,QAAQ,KAAK,MAAM;EACrB;EACA,UAAU,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AAE,IAAI,OAAO,OAAO,KAAK,MAAM,EAAE,YAAY,CAAC;MAC7C,MAAM;AACb,CAAC;;;ACAH,MAAa,iBAAiB,YAC5B,UAAU;CACR,OAAO,SAAS,SAAS,KAAK;CAC9B,UAAU,KAAK;AACjB,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,WAAW;CACzB,MAAM,UAAU,IAAI,gBAAgB;EAClC,QAAQ;EACR,MAAM;EACN,MAAM,KAAK,SAAS;CACtB,CAAC;CAaD,OAAO,mBAAmB,MAXP,MAAM,+CAA+C,QAAQ,SAAS,KAAK,EAC5F,SAAS,SAAS,SACd,EACE,eAAe,OAAO,QAAQ,SAChC,IACA,CAAC,EACP,CAAC,CAAC,CAAC,MAAM,MAAM;EACb,IAAI,EAAE,IAAI,OAAO,EAAE,KAAK;OACnB,MAAM;CACb,CAAC,GAE+B,IAAI;AACtC,CAAC;;;ACpBH,MAAa,WAAW,YAAkC;CACxD,OAAO;EACL,KAAA;EACA,MAAM;EACN,SAAS;EACT,YAAY,WAAW,OAAO;EAC9B,YAAY,WAAW,OAAO;EAC9B,eAAe,cAAc,OAAO;EACpC;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riffyh/adapter-nhentai",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/rayriffy/rayriffy-h.git"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"p-throttle": "8.1.0",
|
|
20
|
-
"@riffyh/commons": "2.
|
|
20
|
+
"@riffyh/commons": "2.2.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"tsdown": "0.22.3"
|