-
Notifications
You must be signed in to change notification settings - Fork 1
/
doujin.ts
100 lines (83 loc) · 2.63 KB
/
doujin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { Image } from './image';
import { TagManager } from './tag';
import { HOST_URL } from './constants';
import { APIDoujin } from './apitypes';
export class Doujin {
readonly id: number;
/**
* Media ID, this is **NOT** the same as the doujin id
*/
readonly mediaId: number;
/**
* All the titles that the doujin has.
* @param english Example: (C92) [Rosapersica (Ichinomiya)] Keijun Yahagi wa Koi o Shita. Jou | Light Cruiser Yahagi Fell In Love - First (Kantai Collection -KanColle-) [English] [Spicaworks]
* @param japanese Example: (C92) [Rosapersica (一ノ宮)] 軽巡矢矧は恋をした。上 (艦隊これくしょん -艦これ-) [英訳]
* @param pretty Example: Keijun Yahagi wa Koi o Shita. Jou | Light Cruiser Yahagi Fell In Love - First
*/
readonly titles: {
english: string;
japanese: string;
pretty: string;
};
readonly pages: Image[];
/**
* Cover image of the doujin
*/
readonly cover: Image;
/**
* Low resolution cover
*/
readonly thumbnail: Image;
/**
* Content url
*/
readonly url: string;
/**
* Scanlator if exists
*/
readonly scanlator: string | null;
/**
* The time it was published to the site
*/
readonly uploadDate: Date;
/**
* The timestamp of when it was published to the site
*/
readonly uploadTimestamp: number;
/**
* Page count
*/
readonly length: number;
readonly favorites: number;
readonly tags: TagManager;
/**
* Raw data from the API
*/
readonly raw: APIDoujin;
/**
* @hidden
* @param raw API data
*/
constructor(raw: APIDoujin) {
this.raw = raw;
this.id = raw.id;
this.mediaId = Number(raw.media_id);
this.titles = raw.title;
this.scanlator = raw.scanlator.length > 0 ? raw.scanlator : null;
this.uploadDate = new Date(raw.upload_date * 1000);
this.uploadTimestamp = raw.upload_date;
this.length = raw.num_pages;
this.favorites = raw.num_favorites;
this.url = `${HOST_URL}/g/${raw.id}`;
this.pages = raw.images.pages.map((image, index) => new Image(image, index + 1, this));
this.cover = new Image(raw.images.cover, 'cover', this);
this.thumbnail = new Image(raw.images.thumbnail, 'thumb', this);
this.tags = new TagManager(raw.tags);
}
hasTagByName(name: string): boolean {
return !!this.tags.all.find(tag => tag.name === name);
}
hasTagByID(ID: number): boolean {
return !!this.tags.all.find(tag => tag.id === ID);
}
}