This repository has been archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.ts
220 lines (198 loc) · 6.3 KB
/
interface.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import {
Chapter,
ExtensionMetadata,
FilterValues,
PageRequesterData,
Series,
SeriesListResponse,
WebviewResponse,
} from "./types";
import { Response, RequestInfo, RequestInit } from "node-fetch";
import { SettingType } from "./enums";
import { FilterOption } from "./filters";
/**
* Get a series from the content source.
*
* @param id the id of the series on the content source
* @returns the series populated with fields from the content source, or undefined
*/
export interface GetSeriesFunc {
(id: string): Promise<Series | undefined>;
}
/**
* Request chapters for a series from the content source.
*
* @param id the id of the series on the content source
* @returns a list of chapters for the series, populated with fields from the content source
*/
export interface GetChaptersFunc {
(id: string): Promise<Chapter[]>;
}
/**
* Request data for a PageRequesterData object containing values used to get individual page URLs.
*
* This function is to support handling content sources with a non-uniform method of getting page
* URLs -- i.e. each chapter may be hosted on an arbitrary server, which can only be identified
* after requesting the base URL. The PageRequesterData received is solely used for GetPageUrlsFunc.
*
* @param seriesSourceId
* @param chapterSourceId
* @returns the PageRequesterData for passing to any GetPageUrlsFunc call for the chapter
*/
export interface GetPageRequesterDataFunc {
(seriesSourceId: string, chapterSourceId: string): Promise<PageRequesterData>;
}
/**
* Get page URLs for a chapter.
*
* Strictly speaking, this function does not necessarily return precise URLs for a resource; it only
* needs to return identifiers that can locate the actual page source (using the Series object if
* necessary). Particularly, if the series is an archive file, this function returns a list of paths
* within the archive that need to be extracted separately.
*
* @param pageRequesterData
* @returns list of URLs that can be used to retrieve page data (using GetImageFunc)
*/
export interface GetPageUrlsFunc {
(pageRequesterData: PageRequesterData): string[];
}
/**
* Get resolved data for an image.
*
* The return value should either be a string to put inside the src tag of an HTML <img> (usually
* the URL itself), or an ArrayBuffer that can be made into a Blob.
*
* @param series the series the image belongs to
* @param url the url for this page, e.g. from GetPageUrlsFunc or Series.remoteCoverUrl
* @returns promise for the data as described above
*/
export interface GetImageFunc {
(series: Series, url: string): Promise<string | ArrayBuffer>;
}
/**
* Search the content source for a series.
*
* @param text the user's search content, with any entered search params removed
* @param params a map of user-specified parameters for searching. These are currently entered in
* the form "key:value" like "author:oda" but this is not currently well-defined.
* @param page the page number on the source
* @returns SeriesListResponse with series that have fields set as available
*/
export interface GetSearchFunc {
(text: string, page: number, filterValues: FilterValues): Promise<SeriesListResponse>;
}
/**
* Get the directory for the content source (often equivalent to an empty search).
*
* @param page the page number on the source
* @returns SeriesListResponse with series that have fields set as available
*/
export interface GetDirectoryFunc {
(page: number, filterValues: FilterValues): Promise<SeriesListResponse>;
}
/**
* Get the types for the extension's settings.
*
* @returns a map of settings for the extension and their SettingType
*/
export interface GetSettingTypesFunc {
(): { [key: string]: SettingType };
}
/**
* Get the current settings for the extension.
*
* @returns a map of settings for the extension (with default/initial values already set)
*/
export interface GetSettingsFunc {
(): { [key: string]: any };
}
/**
* Set the settings for the extension.
*
* Use GetSettingsFunc to see available fields and their types.
*
* @param settings a map of settings for the extension
*/
export interface SetSettingsFunc {
(settings: { [key: string]: any }): void;
}
/**
* Get the extension's filter options.
*
* @returns List[FilterOption]
*/
export interface GetFilterOptionsFunc {
(): FilterOption[];
}
export interface FetchFunc {
(url: RequestInfo, init?: RequestInit | undefined): Promise<Response>;
}
export interface WebviewFunc {
(
url: string,
options?: {
httpReferrer?: string;
userAgent?: string;
extraHeaders?: string;
postData?: (
| { type: "rawData"; bytes: Buffer }
| {
type: "file";
filePath: string;
offset: number;
length: number;
modificationTime: number;
}
)[];
baseURLForDataURL?: string;
}
): Promise<WebviewResponse>;
}
export interface DocFunc {
(html?: string | Buffer): Document;
}
export class UtilFunctions {
fetchFn: FetchFunc;
webviewFn: WebviewFunc;
docFn: DocFunc;
constructor(fetchFn: FetchFunc, webviewFn: WebviewFunc, docFn: DocFunc) {
this.fetchFn = fetchFn;
this.webviewFn = webviewFn;
this.docFn = docFn;
}
}
export interface ExtensionClientInterface {
utilFns: UtilFunctions;
settings: { [key: string]: any };
getMetadata: () => ExtensionMetadata;
getSeries: GetSeriesFunc;
getChapters: GetChaptersFunc;
getPageRequesterData: GetPageRequesterDataFunc;
getPageUrls: GetPageUrlsFunc;
getImage: GetImageFunc;
getSearch: GetSearchFunc;
getDirectory: GetDirectoryFunc;
getSettingTypes: GetSettingTypesFunc;
getSettings: GetSettingsFunc;
setSettings: SetSettingsFunc;
getFilterOptions: GetFilterOptionsFunc;
}
export abstract class ExtensionClientAbstract implements ExtensionClientInterface {
utilFns: UtilFunctions;
settings: { [key: string]: any } = {};
constructor(utilFns: UtilFunctions) {
this.utilFns = utilFns;
}
getMetadata!: () => ExtensionMetadata;
getSeries!: GetSeriesFunc;
getChapters!: GetChaptersFunc;
getPageRequesterData!: GetPageRequesterDataFunc;
getPageUrls!: GetPageUrlsFunc;
getImage!: GetImageFunc;
getSearch!: GetSearchFunc;
getDirectory!: GetDirectoryFunc;
getSettingTypes!: GetSettingTypesFunc;
getSettings!: GetSettingsFunc;
setSettings!: SetSettingsFunc;
getFilterOptions!: GetFilterOptionsFunc;
}