nhentai-client 0.0.1 → 0.0.2
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/package.json +1 -1
- package/src/client.ts +22 -3
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { findWorkingUrl } from "./utils/findWorkingUrl";
|
|
2
2
|
import {
|
|
3
3
|
API_URL,
|
|
4
|
+
I_IMAGE_URL,
|
|
4
5
|
MAP_IMAGE_TYPE_TO_EXTENSION,
|
|
5
6
|
T_IMAGE_URL,
|
|
6
7
|
type Book,
|
|
8
|
+
type Image,
|
|
7
9
|
type Page,
|
|
8
10
|
type Sort,
|
|
9
11
|
} from "./client.types";
|
|
10
12
|
|
|
11
|
-
export const getCoverImageUrl = async (
|
|
12
|
-
const baseUrl = `${T_IMAGE_URL}/galleries/${
|
|
13
|
-
const ext = MAP_IMAGE_TYPE_TO_EXTENSION[
|
|
13
|
+
export const getCoverImageUrl = async (mediaId: string, cover: Image) => {
|
|
14
|
+
const baseUrl = `${T_IMAGE_URL}/galleries/${mediaId}/cover`;
|
|
15
|
+
const ext = MAP_IMAGE_TYPE_TO_EXTENSION[cover.t];
|
|
14
16
|
|
|
15
17
|
if (ext !== "webp") {
|
|
16
18
|
return `${baseUrl}.${ext}`;
|
|
@@ -22,6 +24,23 @@ export const getCoverImageUrl = async (book: Book) => {
|
|
|
22
24
|
return await findWorkingUrl(candidates);
|
|
23
25
|
};
|
|
24
26
|
|
|
27
|
+
export const getPageImageUrl = async (
|
|
28
|
+
mediaId: string,
|
|
29
|
+
page: Image,
|
|
30
|
+
index: number
|
|
31
|
+
) => {
|
|
32
|
+
const baseUrl = `${I_IMAGE_URL}/galleries/${mediaId}/${index}`;
|
|
33
|
+
const ext = MAP_IMAGE_TYPE_TO_EXTENSION[page.t];
|
|
34
|
+
if (ext !== "webp") {
|
|
35
|
+
return `${baseUrl}.${ext}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const candidates = Object.values(MAP_IMAGE_TYPE_TO_EXTENSION).map(
|
|
39
|
+
(ext) => `${baseUrl}.${ext}.webp`
|
|
40
|
+
);
|
|
41
|
+
return await findWorkingUrl(candidates);
|
|
42
|
+
};
|
|
43
|
+
|
|
25
44
|
export const getBookUrl = (id: number) => {
|
|
26
45
|
return `${API_URL}/gallery/${id}`;
|
|
27
46
|
};
|