From cd74abb40b6662f185bb736d583a666dc8cfcbe9 Mon Sep 17 00:00:00 2001 From: Sharique Hassan Malik <146327065+Sharique-Hassan-Malik@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:58:49 +0500 Subject: [PATCH 1/2] feat(english): add Boti Translation source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit botitranslation.com is a client-side app on the StoryWave backend; the plugin reads its public JSON API (the site-domain header selects the catalogue). Browse by the site's ranking lists, with genre and status filters; search; full chapter list oldest first. A chapter sold ("charge") and not bought is marked 🔒 and can be hidden with "Hide locked chapters"; opening one says it is locked instead of showing the API's preview. Closes #1714. --- plugins/english/botitranslation.ts | 310 ++++++++++++++++++ public/static/src/en/botitranslation/icon.png | Bin 0 -> 3166 bytes 2 files changed, 310 insertions(+) create mode 100644 plugins/english/botitranslation.ts create mode 100644 public/static/src/en/botitranslation/icon.png diff --git a/plugins/english/botitranslation.ts b/plugins/english/botitranslation.ts new file mode 100644 index 0000000000..61b57b3ca3 --- /dev/null +++ b/plugins/english/botitranslation.ts @@ -0,0 +1,310 @@ +import { fetchApi } from '@libs/fetch'; +import { Filters, FilterTypes } from '@libs/filterInputs'; +import { NovelStatus } from '@libs/novelStatus'; +import { + checkResponse, + createPluginError, + PluginError, +} from '@libs/pluginError'; +import { storage } from '@libs/storage'; +import { Plugin } from '@/types/plugin'; + +/** + * botitranslation.com is a client-side app on the shared "StoryWave" backend. + * All data comes from its public JSON API; the `site-domain` header tells the + * multi-tenant backend which catalogue to serve. Paths: the book id for a + * novel, `/` for a chapter. + */ +const API = 'https://api.mystorywave.com/story-wave-backend/api/v1'; +const SITE_DOMAIN = 'www.botitranslation.com'; +const PAGE_SIZE = 30; +const CACHE_MS = 10 * 60 * 1000; + +type ApiResponse = { code?: number; message?: string; data?: T }; +type Book = { + id: number; + title: string; + coverImgUrl?: string; + synopsis?: string; + authorPseudonym?: string; + genre?: number; + status?: number; +}; +type Chapter = { + id: number; + title: string; + chapterOrder?: number; + publishTime?: number; + paywallStatus?: string; + paid?: boolean; +}; +type Page = { list?: T[]; totalPages?: number; totalCount?: number }; + +/** + * A chapter is locked when it is sold ("charge") and not bought; the API then + * gives only a preview of about 1000 characters. "free" and "1" chapters come + * whole. + */ +const isLocked = (c: { paywallStatus?: string; paid?: boolean }) => + c.paywallStatus === 'charge' && !c.paid; + +const HEADERS = { + 'site-domain': SITE_DOMAIN, + 'Accept': 'application/json', + 'Referer': 'https://www.botitranslation.com/', +}; + +class BotiTranslationPlugin implements Plugin.PluginBase { + id = 'botitranslation'; + name = 'Boti Translation'; + icon = 'src/en/botitranslation/icon.png'; + site = 'https://www.botitranslation.com/'; + version = '1.0.0'; + + pluginSettings = { + hideLocked: { + value: '', + label: 'Hide locked chapters', + type: 'Switch', + }, + }; + + // Sorts are the site's own ranking lists; genre ids and names as the API + // reports them; status 1 = ongoing, 2 = completed. + filters = { + sort: { + type: FilterTypes.Picker, + label: 'Sort', + value: 'MostPopularLocal', + options: [ + { label: 'Most popular', value: 'MostPopularLocal' }, + { label: 'Popular translations', value: 'TranslationMostPopularLocal' }, + { label: 'Most words', value: 'MostWordCountLocal' }, + { label: 'Recently updated', value: 'LastUpdatedLocal' }, + ], + }, + status: { + type: FilterTypes.Picker, + label: 'Status', + value: '', + options: [ + { label: 'All', value: '' }, + { label: 'Ongoing', value: '1' }, + { label: 'Completed', value: '2' }, + ], + }, + genre: { + type: FilterTypes.CheckboxGroup, + label: 'Genres (any of)', + value: [], + options: [ + { label: 'Fantasy', value: '1' }, + { label: 'Sci-fi', value: '2' }, + { label: 'Sports', value: '3' }, + { label: 'Urban', value: '4' }, + { label: 'Eastern Fantasy', value: '5' }, + { label: 'Horror&Thriller', value: '6' }, + { label: 'Video Game', value: '7' }, + { label: 'History', value: '8' }, + { label: 'War', value: '9' }, + { label: 'Urban Romance', value: '10' }, + { label: 'Fantasy Romance', value: '11' }, + { label: 'Historical Romance', value: '12' }, + { label: 'Teen', value: '13' }, + { label: 'LGBT+', value: '14' }, + ], + }, + } satisfies Filters; + + private catalogue: Record = {}; + + private async api( + path: string, + params?: Record, + init?: { method: string; body: string }, + ): Promise { + let url = API + path; + if (params) { + url += + '?' + + Object.keys(params) + .map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k])) + .join('&'); + } + const r = await fetchApi(url, { + headers: init + ? { ...HEADERS, 'Content-Type': 'application/json' } + : HEADERS, + ...init, + }); + checkResponse(r); + let json: ApiResponse; + try { + json = (await r.json()) as ApiResponse; + } catch { + throw createPluginError(PluginError.InvalidResponse, { url }); + } + if (json.code !== 0 || json.data === undefined || json.data === null) { + throw createPluginError(PluginError.InvalidResponse, { + message: + 'Boti Translation: ' + + (json.message || 'no data') + + ' (' + + path + + ')', + url, + }); + } + return json.data; + } + + private mapBook(b: Book): Plugin.NovelItem { + const novel: Plugin.NovelItem = { name: b.title, path: String(b.id) }; + if (b.coverImgUrl) novel.cover = b.coverImgUrl; + return novel; + } + + /** One page of a ranking list (the same request the site's home page makes). */ + private rankList(name: string, page: number, size: number) { + return this.api>('/content/books/custom/' + name, undefined, { + method: 'POST', + body: JSON.stringify({ + conditionJson: '{}', + pageNumber: page, + pageSize: size, + }), + }); + } + + /** + * The ranking lists ignore genre and status, so those filters run here over + * the whole list of the chosen order, fetched once and kept ten minutes. + */ + private async wholeList(name: string): Promise { + const hit = this.catalogue[name]; + if (hit && Date.now() - hit.at < CACHE_MS) return hit.list; + const first = await this.rankList(name, 1, 2000); + let list = first.list || []; + for ( + let page = 2; + list.length < (first.totalCount || 0) && page <= 20; + page++ + ) { + list = list.concat((await this.rankList(name, page, 2000)).list || []); + } + this.catalogue[name] = { at: Date.now(), list }; + return list; + } + + async popularNovels( + pageNo: number, + { + showLatestNovels, + filters, + }: Plugin.PopularNovelsOptions, + ): Promise { + const sort = showLatestNovels + ? 'LastUpdatedLocal' + : filters?.sort?.value || 'MostPopularLocal'; + const genres = filters?.genre?.value || []; + const status = filters?.status?.value || ''; + if (!genres.length && !status) { + const page = await this.rankList(sort, pageNo, PAGE_SIZE); + return (page.list || []).map(b => this.mapBook(b)); + } + const hits = (await this.wholeList(sort)).filter( + b => + (!genres.length || genres.includes(String(b.genre))) && + (!status || String(b.status) === status), + ); + return hits + .slice((pageNo - 1) * PAGE_SIZE, pageNo * PAGE_SIZE) + .map(b => this.mapBook(b)); + } + + async parseNovel(novelPath: string): Promise { + const id = novelPath.replace(/[^0-9]/g, ''); + const book = await this.api('/content/books/' + id); + const hideLocked = storage.get('hideLocked'); + + // The API pages the list, newest first. + const chapters: Plugin.ChapterItem[] = []; + let pageNumber = 1; + let totalPages = 1; + do { + const page = await this.api>('/content/chapters/page', { + bookId: id, + pageNumber, + pageSize: 100, + }); + totalPages = page.totalPages || 1; + for (const c of page.list || []) { + const locked = isLocked(c); + if (locked && hideLocked) continue; + chapters.push({ + name: (locked ? '🔒 ' : '') + c.title, + path: id + '/' + c.id, + chapterNumber: c.chapterOrder, + releaseTime: c.publishTime + ? new Date(c.publishTime).toISOString().slice(0, 10) + : undefined, + }); + } + pageNumber++; + } while (pageNumber <= totalPages && pageNumber <= 500); + chapters.sort((a, b) => (a.chapterNumber || 0) - (b.chapterNumber || 0)); + + const novel: Plugin.SourceNovel = { + path: novelPath, + name: book.title, + chapters, + }; + if (book.coverImgUrl) novel.cover = book.coverImgUrl; + if (book.synopsis) novel.summary = book.synopsis.replace(/\r/g, ''); + if (book.authorPseudonym) novel.author = book.authorPseudonym; + if (book.status === 1) novel.status = NovelStatus.Ongoing; + else if (book.status === 2) novel.status = NovelStatus.Completed; + return novel; + } + + async parseChapter(chapterPath: string): Promise { + const id = (chapterPath.split('/').pop() || '').replace(/[^0-9]/g, ''); + const chapter = await this.api<{ + content?: string; + paywallStatus?: string; + paid?: boolean; + }>('/content/chapters/' + id); + if (!chapter.content || isLocked(chapter)) { + // A paid chapter the reader has not unlocked comes without content. + throw createPluginError(PluginError.AuthRequired, { + message: + 'This chapter is locked on Boti Translation. Unlock it on the site to read it.', + url: this.site + 'viewer/' + id, + }); + } + return chapter.content; + } + + async searchNovels( + searchTerm: string, + pageNo: number, + ): Promise { + // The parameter is `keyWord`; a lowercase `keyword` is ignored and the + // full list comes back. + const page = await this.api>('/content/books/search', { + keyWord: searchTerm, + pageNumber: pageNo, + pageSize: PAGE_SIZE, + }); + return (page.list || []).map(b => this.mapBook(b)); + } + + resolveUrl = (path: string, isNovel?: boolean): string => { + const parts = path.split('/'); + return isNovel + ? this.site + 'story/' + parts[0] + : this.site + 'viewer/' + parts[parts.length - 1]; + }; +} + +export default new BotiTranslationPlugin(); diff --git a/public/static/src/en/botitranslation/icon.png b/public/static/src/en/botitranslation/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a98572200bcc4b7f3ef14f9b8b38676aac363cef GIT binary patch literal 3166 zcmai%_ct317sr!WA-39LkM>oSiqvY12(?;mN}o{Fs#cBGs?eHITS|vrHL8@*B1Wja zYZR$b8Wa@-p=N8np1pN$J_O+mA%EPMSjSKxHMprLNd70RDO|lU_GXZo0FJ;mtErO&s?$h&9 zG(h>4uRUjKaAjUD0rIkpuQWtDuzNU{Z(J?NiPiIVIQY}~h~vsx04Hy$DKHm}5R)bKCsT8grkeM;(R5Z4&27$>^lR8e8_a!|WJymooI^3%`XeG6I9 zrb){rnwi03ao%NDEI52*Rgph>nVkK1Q77QwWf>Ed57@MM@2mH#??hqCu7KgS1t8X7 zy+vMDD#5%j@X8zk+u!5w|IW%oSsh5j6hfzjpai9b$|hY)_KVe3Sq};jrS;l|ZX+x0 zF=JuA_QQ)EoWXPKLqr=$8bs)zdQ37sacIp-7zA*(1UuayQMP=e{dg%(sYUkn19jWm zd9M?osYXP^S@qBzCx9*fd;*p{F+9of#tb3G4EXAG8~3nsa3ZI-m>JF)_5E6zqbzQ- z&SGyjh)3h2-fkvt=ldU1%DaZx`}Jd-QC%Mu-XZX@@3R!CJ1bRNFJ)B{UvH+9Yl@T@ z{3)XT5G5V7>+bdf71wW0%r$Jv0jKyW>nU8WbrXr7jZ%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Df(-@5a-kAdv#j%s(*lF_cG-QgoPZp z76}r_#X%i459OemO5DQ7v@|Jh=mhtGr2N&x7u!a{QAZ8p$^Y5O8hmx{8KJhZU9k&Mj**TDOX9&h{BQgi*&l|_4XdzBhZLg~OkyW`AW21Qf869fc{s#x0C-*iXB3ur?C_r0F2FPVHu z5+`IMeK6GJUs{3*rsf`xm3E=nRuq8brXln)HI4Qy?&ZqhzakZ}<~obG)HXYs_@(|h zhk(0BY!!8O{PhKpqNT@`q5<3c!pL#Gt^QhaYUQ7W2!qj~v0F>0$Jaut%8WK4t*Liw zUq62^8Q`C1#n-hs{4=u5|Fq5NW|L42q5P|92-N8Hoo5nU-}H2kz*P$VT^@jlzqm+_ zVOHgfB-&krx5R&uniR!EW+1~|)&FPWF@d6C8ZLfCD9A)E7I2yN sVGmkT0s)S+L1RBE{v3}>G3-PtKy@1WZ30X_{Tl$LM%U2gD96bE13~%q9RL6T literal 0 HcmV?d00001 From 4a5ec3e4fce7e03002ba4688df8f40566fbf162e Mon Sep 17 00:00:00 2001 From: Sharique Hassan Malik <146327065+Sharique-Hassan-Malik@users.noreply.github.com> Date: Thu, 3 Dec 2026 17:54:28 +0500 Subject: [PATCH 2/2] fix(english/botitranslation): default the hide locked chapters switch to false A Switch setting's value is a boolean (docs/docs.md, plugin settings). --- plugins/english/botitranslation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/english/botitranslation.ts b/plugins/english/botitranslation.ts index 61b57b3ca3..1ffe50644c 100644 --- a/plugins/english/botitranslation.ts +++ b/plugins/english/botitranslation.ts @@ -63,7 +63,7 @@ class BotiTranslationPlugin implements Plugin.PluginBase { pluginSettings = { hideLocked: { - value: '', + value: false, label: 'Hide locked chapters', type: 'Switch', },