From 378e296761280228ef1d344954e1edd4c79358fe Mon Sep 17 00:00:00 2001 From: lgou2w Date: Tue, 5 Oct 2021 15:58:15 +0800 Subject: [PATCH] doc: update readme.md --- README.md | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 163 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 231003d..0c55a20 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,169 @@ pnpm i @l2studio/picacomic-api ## API -TODO +By default, the constructor does not need parameters. -## 协议 +```typescript +import { PicaComicAPI } from '@l2studio/picacomic-api' + +class PicaComicAPI(opts?: Partial) +``` + +### Options + +```typescript +type Options = { + timeout?: number // http request timeout (optional) + proxy?: { // http proxy (optional) + host: string // proxy host (required) + port: number // porxy port (required) + } + app?: { // PicaComic app client options (optional) + api: string + apiKey: string + signatureKey: string + accept: string + channel: '1' | '2' | '3' + version: string + uuid: string + platform: string + buildVersion: string + userAgent: string + imageQuality: 'original' | 'low' | 'medium' | 'high' + } + // Callback function used to re-authenticate and return a new token when the token is invalid. (optional) + // Example: + // async reauthorizationTokenCallback (self) { + // console.log('Token invalid, re-authenticate...') + // return await self.signIn({ + // email : 'your picacomic account email', + // password: 'your picacomic account password' + // }) + // } + reauthorizationTokenCallback?: (self: PicaComicAPI) => string | Promise +} +``` + +### .signIn + +```typescript +/** + * Sign in to the PicaComic account with the given email and password payload. + * + * @param payload - Email and password payload + * @return Access token + */ +PicaComicAPI.prototype.signIn(payload: { email: string, password: string }): Promise +``` + +### .fetchCategories + +```typescript +/** + * Fetch all categories using the given access token payload. + * + * @param payload - Access token payload + * @return Category[] + */ +PicaComicAPI.prototype.fetchCategories(payload: { token: string }): Promise +``` + +### .fetchComics + +```typescript +/** + * Fetch comics using the given payload. + * + * @param payload - { + * token - Access token + * category - Specify category name (e.g.: 'Cosplay') + * page - Page number (optional) + * sort - Sorting type (optional) + * } + * @return Comics + */ +PicaComicAPI.prototype.fetchComics(payload: { token: string, category: string, page?: number, sort?: 'ua' | 'dd' | 'da' | 'ld' | 'vd' }): Promise +``` + +### .fetchComic + +```typescript +/** + * Fetch comic info using the given payload. + * + * @param payload - { + * token - Access token + * id - Specify comic id + * } + * @return ComicInfo + */ +PicaComicAPI.prototype.fetchComics(payload: { token: string, id: string }): Promise +``` + +### .fetchComicEpisodes + +```typescript +/** + * Fetch comic episodes using the given payload. + * + * @param payload - { + * token - Access token + * comicId - Specify comic id + * page - Page number (optional) + * } + * @return ComicEpisodes + */ +PicaComicAPI.prototype.fetchComicEpisodes(payload: { token: string, comicId: string, page?: number }): Promise +``` + +### .fetchComicEpisodePages + +```typescript +/** + * Fetch pages of the specified comic episode using the given payload. + * + * @param payload - { + * token - Access token + * comicId - Specify comic id + * epsOrder - Specify episode order of the comic + * page - Page number (optional) + * } + * @return ComicEpisodePages + */ +PicaComicAPI.prototype.fetchComicEpisodePages(payload: { token: string, comicId: string, epsOrder: number, page?: number }): Promise +``` + +### .stringifyImageUrl + + +```typescript +/** + * Stringify the given media image data into image url. + * + * @param payload - { + * fileServer - File server + * path - Path name + * } + * @return Stringify image url + */ +PicaComicAPI.prototype.stringifyImageUrl(payload: { fileServer: string; path: string }): string +``` + +### .fetchImage + +```typescript +/** + * Fetch image from the given media image data. + * + * @param payload - { + * fileServer - File server + * path - Path name + * } + * @return Duplex (Got stream) + */ +PicaComicAPI.prototype.fetchImage(payload: { fileServer: string; path: string }): Promise +``` + +## License Apache-2.0