Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
iuroc committed Sep 9, 2024
1 parent 971cb13 commit e46c01d
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 33 deletions.
115 changes: 115 additions & 0 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
declare class Book {
private static gedeId;
/** 获取类别列表 */
static getCategories(): Promise<{
id: number;
name: string;
}[]>;
/**
* 获取指定类别的图书列表
* @param catagoryId 图书类别编号
* @param page 页码
* @param pageSize 返回数据条数
* @returns
*/
static getList(catagoryId: number, page?: number, pageSize?: number): Promise<BookItem[]>;
/**
* 获取图书详情
* @param id 图书编号
* @returns
*/
static getInfo(id: string): Promise<BookInfo>;
/**
* 获取图书正文和目录数据
* @param id 图书编号
* @param page 页码
* @param pageSize 数据条数
* @param width 阅读器宽度像素,影响计算单页字数
* @param height 阅读器高度像素,影响计算单页字数
* @returns
*/
static getData(id: string, page?: number, pageSize?: number, width?: number, height?: number): Promise<BookData>;
/** 获取图书目录数据 */
static getCatalog(id: string): Promise<BookData>;
}
/** 图书列表项 */
type BookItem = {
name: string;
author: string;
id: string;
publish: string;
summary: string;
bigCover: string;
smallCover: string;
surl: string;
price: string;
/** 网页阅读器 */
webReader: string;
type: 'HY' | 'GD';
isbn: string;
};
/** 图书详情 */
type BookInfo = BookItem & {
/** EPUB 文件地址 */
epub: string;
/** 发布时间 */
publishTime: string;
};

declare class Magazine {
private static gedeId;
/** 获取类别列表 */
static getCategories(): Promise<{
id: number;
name: string;
}[]>;
/** 加载指定类别的期刊列表 */
static getList(catagoryId: number, page?: number, pageSize?: number): Promise<MagazineItem[]>;
/**
* 获取期刊的分期列表
* @param id 期刊编号
* @returns
*/
static getIssues(id: number): Promise<IssueItem[]>;
/**
* 获取期刊正文和目录数据
* @param surl 某期的 `surl`
* @param issueId 某期编号
* @param page 页码
* @param pageSize 数据条数
* @param width 阅读器宽度像素,影响计算单页字数
* @param height 阅读器高度像素,影响计算单页字数
* @returns
*/
static getData(surl: string, issueId: string, page?: number, pageSize?: number, width?: number, height?: number): Promise<BookData>;
/** 获取期刊目录数据 */
static getCatalog(surl: string, issueId: string): Promise<BookData>;
private static getDetailURL;
}
type MagazineItem = {
/** 期刊名称 */
name: string;
/** 在线阅读器所需参数 */
surl: string;
/** 期刊编号 */
id: number;
/** 国内刊号 */
cn: string;
/** 国际刊号 */
issn: string;
/** 期刊介绍 */
summary: string;
/** 封面地址 */
cover: string;
};
type IssueItem = {
issueId: string;
magazineName: string;
cover: string;
name: string;
qrCode: string;
surl: string;
webReader: string;
};

export { Book, Magazine };
2 changes: 2 additions & 0 deletions dist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var p=Object.defineProperty;var i=(d,e)=>p(d,"name",{value:e,configurable:!0});class h{static{i(this,"Book")}static gedeId=847516381;static async getCategories(){const e=i(async r=>{const s=`https://gede.5read.com/apis/touchBook/bookCata.jspx${typeof r>"u"?"":`?gedeid=${r}`}`,n=await fetch(s).then(o=>o.json());if(!n.result)throw new Error(n.errorMsg);return n.msg.map(o=>({id:o.id,name:o.cataname}))},"getData");return(await Promise.all([e(this.gedeId),e()])).flat()}static async getList(e,r=0,t=72){const n=`https://gede.5read.com/apis/touchBook/books.jspx?${new URLSearchParams({cataid:e.toString(),page:(r+1).toString(),pageSize:t.toString()}).toString()}`,o=await fetch(n).then(a=>a.json());if(!o.result)throw new Error(o.errorMsg);return o.msg.list.map(a=>({name:a.title,author:a.author,bigCover:a.bcover,smallCover:a.cover,id:a.bookNum,price:a.price,publish:a.publish,summary:a.summary,surl:a.surl,webReader:`http://gede.5read.com/other/epub/read4tm.jsp?a=GEDE:${a.surl}`,type:a.type,isbn:a.isbn}))}static async getInfo(e){const r=`http://gede.5read.com/apis/touchBook/book.jspx?bookNum=${e}`,t=await fetch(r).then(s=>s.json());if(!t.result)throw new Error(t.errorMsg);return{name:t.msg.title,author:t.msg.author,bigCover:t.msg.bcover,smallCover:t.msg.cover,id:t.msg.bookNum,price:t.msg.price,publish:t.msg.publish,summary:t.msg.summary,surl:t.msg.surl,epub:t.msg.path,publishTime:t.msg.pubTime,webReader:`http://gede.5read.com/other/epub/read4tm.jsp?a=GEDE:${t.msg.surl}`,type:t.msg.type,isbn:t.msg.isbn}}static async getData(e,r=0,t=36,s=1500,n=1500){const a=`http://gede.5read.com/other/epub_epubRead_read.jspx?${new URLSearchParams({page:(r+1).toString(),psize:t.toString(),sid:e,w:s.toString(),h:n.toString(),detailUrl:`http://gede.5read.com/apis/touchBook/book.jspx?bookNum=${e}`,from:"4"}).toString()}`,c=await fetch(a).then(u=>u.json());if(!c.result)throw new Error(c.errorMsg);return{catalogs:c.msg.catalogs,contents:c.msg.contents}}static async getCatalog(e){return await this.getData(e,1,0)}}class l{static{i(this,"Magazine")}static gedeId=847516381;static async getCategories(){const e=`https://gede.5read.com/apis/magazine/magazineCatas.jspx?gedeid=${this.gedeId}`,r=await fetch(e).then(t=>t.json());if(!r.result)throw new Error(r.errorMsg);return r.msg.map(t=>({id:t.id,name:t.cataName}))}static async getList(e,r=0,t=72){const n=`http://gede.5read.com/apis/magazine/magazines.jspx?${new URLSearchParams({gedeid:"847516381",cataid:e.toString(),page:(r+1).toString(),pageSize:t.toString()}).toString()}`,o=await fetch(n).then(a=>a.json());if(!o.result)throw new Error(o.errorMsg);return o.msg.list.map(a=>({name:a.name,id:a.id,surl:a.surl,summary:a.summary,cover:a.coverPath,cn:a.cN,issn:a.iSSN}))}static async getIssues(e){const r=`http://gede.5read.com/apis/magazine/magazineItems.jspx?magazineid=${e}`,t=await fetch(r).then(s=>s.json());if(!t.result)throw new Error(t.errorMsg);return t.msg.itemList.map(s=>({issueId:s.magazineItemNum,name:s.issue,cover:s.coverPath,magazineName:s.name,qrCode:s.codeImg,surl:s.surl,webReader:`http://gede.5read.com/other/epub/read4tm.jsp?a=GEDE:${s.surl}`}))}static async getData(e,r,t=0,s=36,n=1500,o=1500){const a=await this.getDetailURL(e),u=`http://gede.5read.com/other/epub_epubRead_read.jspx?${new URLSearchParams({page:(t+1).toString(),psize:s.toString(),sid:r,w:n.toString(),h:o.toString(),detailUrl:a,from:"5"}).toString()}`,g=await fetch(u).then(m=>m.json());if(!g.result)throw new Error(g.errorMsg);return{catalogs:g.msg.catalogs,contents:g.msg.contents}}static async getCatalog(e,r){return await this.getData(e,r,1,0)}static async getDetailURL(e){const r=`http://gede.5read.com/other/epub/read4tm.jsp?a=GEDE:${e}`,s=(await fetch(r).then(n=>n.text())).match(/var\s*detailUrl\s*=\s*"([^"]+)"/);if(!s)throw new Error("\u83B7\u53D6 detailUrl \u5931\u8D25");return s[1]}}export{h as Book,l as Magazine};
//# sourceMappingURL=index.mjs.map
1 change: 1 addition & 0 deletions dist/index.mjs.map

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
"typescript": "^5.4.5"
},
"scripts": {
"dev": "tsc -w"
"build": "pkgroll --minify --clean-dist --sourcemap"
},
"name": "gede-book-api",
"description": "> 歌德电子书借阅机 API",
"version": "1.0.15",
"main": "js/main.mjs",
"types": "src/main.mts",
"version": "1.0.16",
"types": "./dist/index.d.mts",
"exports": "./dist/index.mjs",
"repository": {
"type": "git",
"url": "git+https://github.com/iuroc/gede-book-api.git"
},
"type": "module",
"author": "iuroc",
"license": "ISC",
"bugs": {
"url": "https://github.com/iuroc/gede-book-api/issues"
},
"homepage": "https://github.com/iuroc/gede-book-api#readme"
}
}
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/book.mts → src/book.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="types.d.mts" />
/// <reference path="types.d.ts" />

export class Book {
private static gedeId = 847516381
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {
Book,
} from './book.js'
import {
Magazine,
} from './magazine.js'

export {
Book,
Magazine,
}
2 changes: 1 addition & 1 deletion src/magazine.mts → src/magazine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="types.d.mts" />
/// <reference path="types.d.ts" />

export class Magazine {
private static gedeId = 847516381
Expand Down
19 changes: 0 additions & 19 deletions src/main.mts

This file was deleted.

File renamed without changes.
9 changes: 2 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
"compilerOptions": {
"target": "ESNext",
"strict": true,
"outDir": "js",
"lib": [
"ESNext",
"DOM"
],
"module": "ESNext",
"moduleResolution": "Bundler"
"module": "NodeNext",
"moduleResolution": "NodeNext"
},
}

0 comments on commit e46c01d

Please sign in to comment.