diff --git a/_template_.js b/_template_.js index 2087ac8..374cfb4 100644 --- a/_template_.js +++ b/_template_.js @@ -560,74 +560,20 @@ class NewComicSource extends ComicSource { * @param url * @param comicId * @param epId - * @returns {{} | Promise<{}>} + * @returns {ImageLoadingConfig | Promise} */ onImageLoad: (url, comicId, epId) => { - /* - ``` - return { - url: `${url}?id=comicId`, - // http method - method: 'GET', - // any - data: null, - headers: { - 'user-agent': 'pica_comic/v3.1.0', - }, - // * modify response data - // * @param data {ArrayBuffer} - // * @returns {ArrayBuffer} - onResponse: (data) => { - return data - }, - // {string | null} a js script. The script will be executed in a new Isolate. - // The script should contain a function named `modifyImage`, which receives an [Image] as the only argument, and returns an [Image]. - // Only [Image] api is available in the script. - // Do not use this field if it is not necessary. - modifyImage: ` - function modifyImage(buffer) { - - } - `, - } - ``` - */ - return {} }, /** * [Optional] provide configs for a thumbnail loading * @param url {string} - * @returns {{}} + * @returns {ImageLoadingConfig | Promise} + * + * `ImageLoadingConfig.modifyImage` and `ImageLoadingConfig.onLoadFailed` will be ignored. + * They are not supported for thumbnails. */ onThumbnailLoad: (url) => { - /* - ``` - return { - url: `${url}?id=comicId`, - // http method - method: 'GET', - // {any} - data: null, - headers: { - 'user-agent': 'pica_comic/v3.1.0', - }, - // modify response data - onResponse: (data) => { - return data - }, - // {string | null} a js script. The script will be executed in a new Isolate. - // The script should contain a function named `modifyImage`, which receives an [Image] as the only argument, and returns an [Image]. - // Only [Image] api is available in the script. - // Do not use this field if it is not necessary. - modifyImage: ` - function modifyImage(image) { - - } - `, - } - ``` - */ return {} }, /** diff --git a/_venera_.js b/_venera_.js index 932590c..6d08177 100644 --- a/_venera_.js +++ b/_venera_.js @@ -940,6 +940,33 @@ function Comment({userName, avatar, content, time, replyCount, id, isLiked, scor this.voteStatus = voteStatus; } +/** + * Create image loading config + * @param url {string?} + * @param method {string?} - http method, uppercase + * @param data {any} - request data, may be null + * @param headers {Object?} - request headers + * @param onResponse {((ArrayBuffer) => ArrayBuffer)?} - modify response data + * @param modifyImage {string?} + * A js script string. + * The script will be executed in a new Isolate. + * A function named `modifyImage` should be defined in the script, which receives an [Image] as the only argument, and returns an [Image].. + * @param onLoadFailed {(() => ImageLoadingConfig)?} - called when the image loading failed + * @constructor + * @since 1.0.5 + * + * To keep the compatibility with the old version, do not use the constructor. Consider creating a new object with the properties directly. + */ +function ImageLoadingConfig({url, method, data, headers, onResponse, modifyImage, onLoadFailed}) { + this.url = url; + this.method = method; + this.data = data; + this.headers = headers; + this.onResponse = onResponse; + this.modifyImage = modifyImage; + this.onLoadFailed = onLoadFailed; +} + class ComicSource { name = "" diff --git a/ehentai.js b/ehentai.js index 658afa6..0d109f9 100644 --- a/ehentai.js +++ b/ehentai.js @@ -7,7 +7,7 @@ class Ehentai extends ComicSource { // unique id of the source key = "ehentai" - version = "1.0.5" + version = "1.0.6" minAppVersion = "1.0.0" @@ -837,16 +837,15 @@ class Ehentai extends ComicSource { * @param image * @param comicId * @param epId + * @param nl * @returns {{}} */ - onImageLoad: async (image, comicId, epId) => { + onImageLoad: async (image, comicId, epId, nl) => { let first = await this.comic.loadThumbnails(comicId) console.log(first) let key = await this.comic.getKey(first.urls[0]) let page = Number(image) - console.log(key) - let getImageFromApi = async (nl) => { if(key.mpvkey) { let res = await Network.post(this.apiUrl, { @@ -904,13 +903,22 @@ class Ehentai extends ComicSource { } } - let res = await getImageFromApi() + let res = await getImageFromApi(nl) + + let onLoadFailed = null + + if(res.nl) { + onLoadFailed = async () => { + return this.comic.onImageLoad(image, comicId, epId, res.nl) + } + } return { url: res.url, headers: { 'referer': this.baseUrl, - } + }, + onLoadFailed: onLoadFailed, } }, /** diff --git a/index.json b/index.json index 3faad95..175859a 100644 --- a/index.json +++ b/index.json @@ -45,7 +45,7 @@ "name": "ehentai", "fileName": "ehentai.js", "key": "ehentai", - "version": "1.0.5" + "version": "1.0.6" }, { "name": "禁漫天堂",