Feat: ImageRequestInit (#979)
* add ImageRequestInit & fix Hako * remove multisrc fetchFile * remove plugins fetchFile * update docs and template file
This commit is contained in:
+21
-38
@@ -29,12 +29,12 @@ class ExamplePlugin implements Plugin.PluginBase {}
|
||||
| [icon](#pluginbasename) | yes | Plugin Icon |
|
||||
| [site](#pluginbasesite) | yes | Plugin site link |
|
||||
| [version](#pluginbaseversion) | yes | Plugin version |
|
||||
| [imageRequestInit](#pluginbaseimagerequestinit) | no | Plugin Image Request Init |
|
||||
| [filters](#pluginbasefilters) | no | [Filter definition](#filter-definition-object) object |
|
||||
| [popularNovels(page, options)](#pluginbasepopularnovels) | yes | Novel list getter |
|
||||
| [parseNovelAndChapters(url)](#pluginbaseparsenovelandchapters) | yes | Novel info and chapter list getter |
|
||||
| [parseChapter(url)](#pluginbaseparsechapter) | yes | Chapter text getter |
|
||||
| [searchNovels(searchTerm, page)](#pluginbasesearchnovels) | yes | Novel searching getter |
|
||||
| [fetchImage(url)](#pluginbasefetchimage) | yes | Customizable function for fetching images |
|
||||
|
||||
#### PluginBase::id
|
||||
|
||||
@@ -109,6 +109,26 @@ class ExamplePlugin implements Plugin.PluginBase {
|
||||
}
|
||||
```
|
||||
|
||||
#### PluginBase::imageRequestInit
|
||||
|
||||
The init for request to obtain images
|
||||
|
||||
Used if images failed to load due to site's protection
|
||||
|
||||
###### Example
|
||||
|
||||
```ts
|
||||
class ExamplePlugin implements Plugin.PluginBase {
|
||||
...
|
||||
imageRequestInit: Plugin.ImageRequestInit = {
|
||||
headers: {
|
||||
Referer: 'https://example.com',
|
||||
},
|
||||
};
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
#### PluginBase::filters
|
||||
|
||||
A [Filter definition]() object that holds filters used in [popularNovels](#pluginbasepopularnovels) function
|
||||
@@ -312,43 +332,6 @@ class ExamplePlugin implements Plugin.PluginBase {
|
||||
}
|
||||
```
|
||||
|
||||
#### PluginBase::fetchImage
|
||||
|
||||
Function used if images failed to load due to site's protection
|
||||
|
||||
```ts
|
||||
async fetchImage(url: string): Promise<string | undefined>
|
||||
```
|
||||
|
||||
See [Fetch functions]() for detailed list of fetch functions provided by us to help with fetching data
|
||||
|
||||
###### Parameter
|
||||
|
||||
- `url` Image's url to fetch
|
||||
|
||||
###### Returns
|
||||
|
||||
- `string` base64 representation of the image
|
||||
|
||||
or
|
||||
|
||||
- `undefined` on error
|
||||
|
||||
###### Example
|
||||
|
||||
```ts
|
||||
class ExamplePlugin implements Plugin.PluginBase {
|
||||
...
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
const headers = {
|
||||
Referer: "https://ln.hako.vn",
|
||||
};
|
||||
return await fetchFile(url, { headers: headers });
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### NovelItem
|
||||
|
||||
@@ -14,6 +14,7 @@ class TemplatePlugin implements Plugin.PluginBase {
|
||||
site = 'https://example.com';
|
||||
version = '1.0.0';
|
||||
filters: Filters | undefined = undefined;
|
||||
imageRequestInit?: Plugin.ImageRequestInit | undefined = undefined;
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
@@ -80,11 +81,6 @@ class TemplatePlugin implements Plugin.PluginBase {
|
||||
|
||||
return novels;
|
||||
}
|
||||
async fetchImage(url: string): Promise<string | undefined> {
|
||||
// if your plugin has images and they won't load
|
||||
// this is the function to fiddle with
|
||||
return fetchFile(url);
|
||||
}
|
||||
}
|
||||
|
||||
export default new TemplatePlugin();
|
||||
|
||||
Reference in New Issue
Block a user