Lanraragi ApiKey 鉴权支持 (#148)

* feat: auth with `apiKey`

* chore: revise version
This commit is contained in:
Cusox.
2025-09-01 20:43:17 +08:00
committed by GitHub
parent edebc0c430
commit aafc7078ba

View File

@@ -2,23 +2,34 @@
class Lanraragi extends ComicSource {
name = "Lanraragi"
key = "lanraragi"
version = "1.0.0"
version = "1.1.0"
minAppVersion = "1.4.0"
url = "https://git.nyne.dev/nyne/venera-configs/raw/branch/main/lanraragi.js"
settings = {
api: { title: "API", type: "input", default: "http://lrr.tvc-16.science" }
api: { title: "API", type: "input", default: "http://lrr.tvc-16.science" },
apiKey: { title: "APIKEY", type: "input", default: "" }
}
get baseUrl() {
get baseUrl() {
const api = this.loadSetting('api') || this.settings.api.default
return api.replace(/\/$/, '')
}
get headers() {
let apiKey = this.loadSetting('apiKey')
if (apiKey) apiKey = "Bearer " + Convert.encodeBase64(Convert.encodeUtf8(apiKey))
return {
"Authorization": `${apiKey}`,
}
}
async init() {
try {
const url = `${this.baseUrl}/api/categories`
const res = await Network.get(url)
const res = await Network.get(url, this.headers)
if (res.status !== 200) { this.saveData('categories', []); return }
let data = []
try { data = JSON.parse(res.body) } catch (_) { data = [] }
@@ -39,7 +50,7 @@ class Lanraragi extends ComicSource {
explore = [
{ title: "Lanraragi", type: "multiPageComicList", load: async (page = 1) => {
const url = `${this.baseUrl}/api/archives`
const res = await Network.get(url)
const res = await Network.get(url, this.headers)
if (res.status !== 200) throw `Invalid status code: ${res.status}`
const data = JSON.parse(res.body)
const list = data.slice((page-1)*50, page*50)
@@ -114,7 +125,7 @@ class Lanraragi extends ComicSource {
add('search[regex]', 'false')
const url = `${base}/search?${qp.join('&')}`
const res = await Network.get(url)
const res = await Network.get(url, this.headers)
if (res.status !== 200) throw `Invalid status code: ${res.status}`
const data = JSON.parse(res.body)
const list = Array.isArray(data.data) ? data.data : []
@@ -169,7 +180,7 @@ class Lanraragi extends ComicSource {
add('groupby_tanks', groupby)
const url = `${base}/api/search?${qp.join('&')}`
const res = await Network.get(url)
const res = await Network.get(url, this.headers)
if (res.status !== 200) throw `Invalid status code: ${res.status}`
const data = JSON.parse(res.body)
const all = Array.isArray(data.data) ? data.data : []
@@ -225,7 +236,7 @@ class Lanraragi extends ComicSource {
comic = {
loadInfo: async (id) => {
const url = `${this.baseUrl}/api/archives/${id}/metadata`
const res = await Network.get(url)
const res = await Network.get(url, this.headers)
if (res.status !== 200) throw `Invalid status code: ${res.status}`
const data = JSON.parse(res.body)
const cover = `${this.baseUrl}/api/archives/${id}/thumbnail`
@@ -237,7 +248,7 @@ class Lanraragi extends ComicSource {
},
loadThumbnails: async (id, next) => {
const metaUrl = `${this.baseUrl}/api/archives/${id}/metadata`
const res = await Network.get(metaUrl)
const res = await Network.get(metaUrl, this.headers)
if (res.status !== 200) throw `Invalid status code: ${res.status}`
const data = JSON.parse(res.body)
const pagecount = data.pagecount || 1
@@ -249,7 +260,7 @@ class Lanraragi extends ComicSource {
loadEp: async (comicId, epId) => {
const base = (this.baseUrl || '').replace(/\/$/, '')
const url = `${base}/api/archives/${comicId}/files?force=false`
const res = await Network.get(url)
const res = await Network.get(url, this.headers)
if (res.status !== 200) throw `Invalid status code: ${res.status}`
const data = JSON.parse(res.body)
const images = (data.pages || []).map(p => {
@@ -260,8 +271,16 @@ class Lanraragi extends ComicSource {
}).filter(Boolean)
return { images }
},
// onImageLoad: (url, comicId, epId) => ({}),
// onThumbnailLoad: (url) => ({}),
onImageLoad: (url, comicId, epId) => {
return {
headers: this.headers
}
},
onThumbnailLoad: (url) => {
return {
headers: this.headers
}
},
// likeComic: async (id, isLike) => {},
// loadComments: async (comicId, subId, page, replyTo) => {},
// sendComment: async (comicId, subId, content, replyTo) => {},
@@ -272,4 +291,4 @@ class Lanraragi extends ComicSource {
// link: { domains: ['example.com'], linkToId: (url) => null },
enableTagsTranslate: false,
}
}
}