mirror of
https://github.com/ZSCGR/CloudFlare-ImgBed.git
synced 2026-08-13 04:03:42 +08:00
Cloudflare Workers and Pages already provide the Fetch/Web APIs needed for WebDAV verbs, so the storage integration uses a small local helper instead of adding a Node-oriented WebDAV client. The channel now participates in upload, read, delete, move, rename, channel listing, and runtime config, with chunked uploads explicitly guarded because WebDAV has no portable server-side compose primitive. Constraint: Preserve Pages Functions and generated Worker deployment paths Constraint: No new npm dependency for WebDAV client behavior Rejected: Add a WebDAV npm client | likely Node API/compatibility and package-lock churn Rejected: Treat WebDAV as External URL only | not a complete storage channel lifecycle Confidence: high Scope-risk: moderate Directive: WebDAV here is third-party storage; keep it distinct from the built-in /dav server settings Tested: npm test; node worker/generate-routes.js; npx wrangler deploy --dry-run --config worker/wrangler.toml; git diff --cached --check Not-tested: Live third-party WebDAV provider credentials; Digest-only WebDAV authentication
77 lines
2.6 KiB
JavaScript
77 lines
2.6 KiB
JavaScript
// 获取上传渠道列表 API
|
|
import { fetchUploadConfig } from '../utils/sysConfig.js';
|
|
import { getUploadConfig } from './manage/sysConfig/upload.js';
|
|
import { getDatabase } from '../utils/databaseAdapter.js';
|
|
import { dualAuthCheck } from '../utils/auth/dualAuth.js';
|
|
|
|
export async function onRequest(context) {
|
|
const { request, env } = context;
|
|
|
|
if (request.method !== 'GET') {
|
|
return new Response('Method Not Allowed', { status: 405 });
|
|
}
|
|
|
|
// 双重鉴权检查
|
|
const url = new URL(request.url);
|
|
const { authorized } = await dualAuthCheck(env, url, request);
|
|
if (!authorized) {
|
|
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
|
|
status: 401,
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
}
|
|
|
|
try {
|
|
const includeDisabled = url.searchParams.get('includeDisabled') === 'true';
|
|
|
|
let uploadConfig;
|
|
if (includeDisabled) {
|
|
// 获取所有上传配置(包括禁用的渠道)
|
|
const db = getDatabase(env);
|
|
uploadConfig = await getUploadConfig(db, env);
|
|
} else {
|
|
// 获取上传配置(已过滤禁用的渠道)
|
|
uploadConfig = await fetchUploadConfig(env, context);
|
|
}
|
|
|
|
// 构建渠道列表,返回渠道名称和实际的 Channel 类型
|
|
const channels = {
|
|
telegram: uploadConfig.telegram.channels.map(ch => ({
|
|
name: ch.name,
|
|
type: 'TelegramNew'
|
|
})),
|
|
cfr2: uploadConfig.cfr2.channels.map(ch => ({
|
|
name: ch.name,
|
|
type: 'CloudflareR2'
|
|
})),
|
|
s3: uploadConfig.s3.channels.map(ch => ({
|
|
name: ch.name,
|
|
type: 'S3'
|
|
})),
|
|
discord: uploadConfig.discord.channels.map(ch => ({
|
|
name: ch.name,
|
|
type: 'Discord'
|
|
})),
|
|
huggingface: uploadConfig.huggingface.channels.map(ch => ({
|
|
name: ch.name,
|
|
type: 'HuggingFace'
|
|
})),
|
|
webdav: uploadConfig.webdav.channels.map(ch => ({
|
|
name: ch.name,
|
|
type: 'WebDAV'
|
|
}))
|
|
};
|
|
|
|
return new Response(JSON.stringify(channels), {
|
|
status: 200,
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
} catch (error) {
|
|
console.error('Failed to get channels:', error);
|
|
return new Response(JSON.stringify({ error: 'Failed to get channels' }), {
|
|
status: 500,
|
|
headers: { 'Content-Type': 'application/json' }
|
|
});
|
|
}
|
|
}
|