mirror of
https://github.com/venera-app/venera-configs.git
synced 2025-09-27 08:27:24 +00:00
Lanraragi ApiKey 鉴权支持 (#148)
* feat: auth with `apiKey` * chore: revise version
This commit is contained in:
43
lanraragi.js
43
lanraragi.js
@@ -2,23 +2,34 @@
|
|||||||
class Lanraragi extends ComicSource {
|
class Lanraragi extends ComicSource {
|
||||||
name = "Lanraragi"
|
name = "Lanraragi"
|
||||||
key = "lanraragi"
|
key = "lanraragi"
|
||||||
version = "1.0.0"
|
version = "1.1.0"
|
||||||
minAppVersion = "1.4.0"
|
minAppVersion = "1.4.0"
|
||||||
url = "https://git.nyne.dev/nyne/venera-configs/raw/branch/main/lanraragi.js"
|
url = "https://git.nyne.dev/nyne/venera-configs/raw/branch/main/lanraragi.js"
|
||||||
|
|
||||||
settings = {
|
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
|
const api = this.loadSetting('api') || this.settings.api.default
|
||||||
|
|
||||||
return api.replace(/\/$/, '')
|
return api.replace(/\/$/, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get headers() {
|
||||||
|
let apiKey = this.loadSetting('apiKey')
|
||||||
|
if (apiKey) apiKey = "Bearer " + Convert.encodeBase64(Convert.encodeUtf8(apiKey))
|
||||||
|
|
||||||
|
return {
|
||||||
|
"Authorization": `${apiKey}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
try {
|
try {
|
||||||
const url = `${this.baseUrl}/api/categories`
|
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 }
|
if (res.status !== 200) { this.saveData('categories', []); return }
|
||||||
let data = []
|
let data = []
|
||||||
try { data = JSON.parse(res.body) } catch (_) { data = [] }
|
try { data = JSON.parse(res.body) } catch (_) { data = [] }
|
||||||
@@ -39,7 +50,7 @@ class Lanraragi extends ComicSource {
|
|||||||
explore = [
|
explore = [
|
||||||
{ title: "Lanraragi", type: "multiPageComicList", load: async (page = 1) => {
|
{ title: "Lanraragi", type: "multiPageComicList", load: async (page = 1) => {
|
||||||
const url = `${this.baseUrl}/api/archives`
|
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}`
|
if (res.status !== 200) throw `Invalid status code: ${res.status}`
|
||||||
const data = JSON.parse(res.body)
|
const data = JSON.parse(res.body)
|
||||||
const list = data.slice((page-1)*50, page*50)
|
const list = data.slice((page-1)*50, page*50)
|
||||||
@@ -114,7 +125,7 @@ class Lanraragi extends ComicSource {
|
|||||||
add('search[regex]', 'false')
|
add('search[regex]', 'false')
|
||||||
|
|
||||||
const url = `${base}/search?${qp.join('&')}`
|
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}`
|
if (res.status !== 200) throw `Invalid status code: ${res.status}`
|
||||||
const data = JSON.parse(res.body)
|
const data = JSON.parse(res.body)
|
||||||
const list = Array.isArray(data.data) ? data.data : []
|
const list = Array.isArray(data.data) ? data.data : []
|
||||||
@@ -169,7 +180,7 @@ class Lanraragi extends ComicSource {
|
|||||||
add('groupby_tanks', groupby)
|
add('groupby_tanks', groupby)
|
||||||
|
|
||||||
const url = `${base}/api/search?${qp.join('&')}`
|
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}`
|
if (res.status !== 200) throw `Invalid status code: ${res.status}`
|
||||||
const data = JSON.parse(res.body)
|
const data = JSON.parse(res.body)
|
||||||
const all = Array.isArray(data.data) ? data.data : []
|
const all = Array.isArray(data.data) ? data.data : []
|
||||||
@@ -225,7 +236,7 @@ class Lanraragi extends ComicSource {
|
|||||||
comic = {
|
comic = {
|
||||||
loadInfo: async (id) => {
|
loadInfo: async (id) => {
|
||||||
const url = `${this.baseUrl}/api/archives/${id}/metadata`
|
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}`
|
if (res.status !== 200) throw `Invalid status code: ${res.status}`
|
||||||
const data = JSON.parse(res.body)
|
const data = JSON.parse(res.body)
|
||||||
const cover = `${this.baseUrl}/api/archives/${id}/thumbnail`
|
const cover = `${this.baseUrl}/api/archives/${id}/thumbnail`
|
||||||
@@ -237,7 +248,7 @@ class Lanraragi extends ComicSource {
|
|||||||
},
|
},
|
||||||
loadThumbnails: async (id, next) => {
|
loadThumbnails: async (id, next) => {
|
||||||
const metaUrl = `${this.baseUrl}/api/archives/${id}/metadata`
|
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}`
|
if (res.status !== 200) throw `Invalid status code: ${res.status}`
|
||||||
const data = JSON.parse(res.body)
|
const data = JSON.parse(res.body)
|
||||||
const pagecount = data.pagecount || 1
|
const pagecount = data.pagecount || 1
|
||||||
@@ -249,7 +260,7 @@ class Lanraragi extends ComicSource {
|
|||||||
loadEp: async (comicId, epId) => {
|
loadEp: async (comicId, epId) => {
|
||||||
const base = (this.baseUrl || '').replace(/\/$/, '')
|
const base = (this.baseUrl || '').replace(/\/$/, '')
|
||||||
const url = `${base}/api/archives/${comicId}/files?force=false`
|
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}`
|
if (res.status !== 200) throw `Invalid status code: ${res.status}`
|
||||||
const data = JSON.parse(res.body)
|
const data = JSON.parse(res.body)
|
||||||
const images = (data.pages || []).map(p => {
|
const images = (data.pages || []).map(p => {
|
||||||
@@ -260,8 +271,16 @@ class Lanraragi extends ComicSource {
|
|||||||
}).filter(Boolean)
|
}).filter(Boolean)
|
||||||
return { images }
|
return { images }
|
||||||
},
|
},
|
||||||
// onImageLoad: (url, comicId, epId) => ({}),
|
onImageLoad: (url, comicId, epId) => {
|
||||||
// onThumbnailLoad: (url) => ({}),
|
return {
|
||||||
|
headers: this.headers
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onThumbnailLoad: (url) => {
|
||||||
|
return {
|
||||||
|
headers: this.headers
|
||||||
|
}
|
||||||
|
},
|
||||||
// likeComic: async (id, isLike) => {},
|
// likeComic: async (id, isLike) => {},
|
||||||
// loadComments: async (comicId, subId, page, replyTo) => {},
|
// loadComments: async (comicId, subId, page, replyTo) => {},
|
||||||
// sendComment: async (comicId, subId, content, replyTo) => {},
|
// sendComment: async (comicId, subId, content, replyTo) => {},
|
||||||
|
Reference in New Issue
Block a user