mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-30 19:46:38 +08:00
重构核心模块并同步更新项目配置与相关实现
This commit is contained in:
+17
-3
@@ -210,22 +210,36 @@ export type ImageURLOptions =
|
||||
| {
|
||||
refreshCache?: boolean
|
||||
retryFailed?: boolean
|
||||
maxWidth?: number
|
||||
maxHeight?: number
|
||||
quality?: number
|
||||
}
|
||||
|
||||
export function imageURL(remote?: string, version?: string, options: ImageURLOptions = false): string {
|
||||
if (!remote) return ''
|
||||
const versionQuery = version ? `v=${encodeURIComponent(version)}` : ''
|
||||
const retryFailed = typeof options === 'boolean' ? options : Boolean(options.retryFailed)
|
||||
const refreshCache = typeof options === 'boolean' ? false : Boolean(options.refreshCache)
|
||||
const opts: Exclude<ImageURLOptions, boolean> = typeof options === 'boolean' ? {} : options
|
||||
const retryFailed = typeof options === 'boolean' ? options : Boolean(opts.retryFailed)
|
||||
const refreshCache = typeof options === 'boolean' ? false : Boolean(opts.refreshCache)
|
||||
const retryQuery = retryFailed ? 'retry=1' : ''
|
||||
const refreshQuery = refreshCache ? 'refresh=1' : ''
|
||||
const imageQuery = [versionQuery, retryQuery, refreshQuery].filter(Boolean).join('&')
|
||||
const resizeQuery = [
|
||||
positiveDimensionQuery('maxWidth', opts.maxWidth),
|
||||
positiveDimensionQuery('maxHeight', opts.maxHeight),
|
||||
positiveDimensionQuery('quality', opts.quality, 100),
|
||||
].filter(Boolean).join('&')
|
||||
const imageQuery = [versionQuery, retryQuery, refreshQuery, resizeQuery].filter(Boolean).join('&')
|
||||
if (remote.startsWith('/api/img')) return withQuery(withoutAuthQuery(remote), imageQuery)
|
||||
if (remote.startsWith('/api/cloud/play/')) return withQuery(withoutAuthQuery(remote), imageQuery)
|
||||
if (remote.startsWith('/api/')) return withQuery(withQuery(remote, tokenQuery()), imageQuery)
|
||||
return withQuery(`/api/img?url=${encodeURIComponent(remote)}`, imageQuery)
|
||||
}
|
||||
|
||||
function positiveDimensionQuery(name: string, value?: number, max = 10_000): string {
|
||||
if (!Number.isFinite(value) || !value || value <= 0) return ''
|
||||
return `${name}=${Math.min(Math.round(value), max)}`
|
||||
}
|
||||
|
||||
function withQuery(url: string, query: string): string {
|
||||
if (!query) return url
|
||||
return `${url}${url.includes('?') ? '&' : '?'}${query}`
|
||||
|
||||
+16
-3
@@ -105,6 +105,7 @@ export const libraryAPI = {
|
||||
.get<LibraryWithPreview[]>('/libraries', {
|
||||
params: {
|
||||
with_preview: 1,
|
||||
include_total: 0,
|
||||
preview_limit: previewLimit,
|
||||
ids: ids.join(','),
|
||||
},
|
||||
@@ -160,22 +161,34 @@ export const libraryAPI = {
|
||||
scrape: (id: string, options?: ScrapeOptions) =>
|
||||
api.post(`/libraries/${id}/scrape`, options ?? null, { timeout: BATCH_REQUEST_TIMEOUT }).then((r) => r.data),
|
||||
|
||||
listMedia: (id: string, page = 1, pageSize = 50, options?: { groupVersions?: boolean }) =>
|
||||
listMedia: (
|
||||
id: string,
|
||||
page = 1,
|
||||
pageSize = 50,
|
||||
options?: { groupVersions?: boolean; sort?: string; order?: 'asc' | 'desc' },
|
||||
) =>
|
||||
api
|
||||
.get<MediaPage>(`/libraries/${id}/media`, {
|
||||
params: {
|
||||
page,
|
||||
page_size: pageSize,
|
||||
group_versions: options?.groupVersions === false ? 0 : undefined,
|
||||
sort: options?.sort,
|
||||
order: options?.order,
|
||||
},
|
||||
timeout: LONG_REQUEST_TIMEOUT,
|
||||
})
|
||||
.then((r) => r.data),
|
||||
|
||||
listSeries: (id: string, page = 1, pageSize = 500) =>
|
||||
listSeries: (
|
||||
id: string,
|
||||
page = 1,
|
||||
pageSize = 500,
|
||||
options?: { sort?: string; order?: 'asc' | 'desc' },
|
||||
) =>
|
||||
api
|
||||
.get<SeriesPage>(`/libraries/${id}/series`, {
|
||||
params: { page, page_size: pageSize },
|
||||
params: { page, page_size: pageSize, sort: options?.sort, order: options?.order },
|
||||
timeout: LONG_REQUEST_TIMEOUT,
|
||||
})
|
||||
.then((r) => r.data),
|
||||
|
||||
Reference in New Issue
Block a user