mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-01-31 09:03:19 +08:00
Feat:优化访客图库展示效果,支持根目录展示;Bug:修复Telegram渠道无法关闭服务端压缩重试的问题
This commit is contained in:
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
BIN
css/543.fbbed345.css.gz
Normal file
BIN
css/543.fbbed345.css.gz
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
@@ -16,24 +16,34 @@ const corsHeaders = {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isAllowedDirectory(dir, allowedDirs) {
|
||||
// 如果允许目录列表为空,视为允许所有目录(包括根目录)
|
||||
if (!allowedDirs || allowedDirs.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 标准化目录格式
|
||||
const normalizedDir = dir.replace(/^\/+/, '').replace(/\/+$/, '');
|
||||
|
||||
|
||||
for (const allowed of allowedDirs) {
|
||||
const normalizedAllowed = allowed.trim().replace(/^\/+/, '').replace(/\/+$/, '');
|
||||
|
||||
// 空字符串表示允许所有
|
||||
if (normalizedAllowed === '') {
|
||||
|
||||
// "*" 或空字符串表示允许所有目录(包括根目录)
|
||||
if (normalizedAllowed === '*' || normalizedAllowed === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// 根目录访问:如果请求的是空目录,需要精确匹配
|
||||
if (normalizedDir === '' && normalizedAllowed !== '') {
|
||||
continue; // 根目录不匹配具体目录名
|
||||
}
|
||||
|
||||
// 精确匹配或子目录匹配
|
||||
if (normalizedDir === normalizedAllowed ||
|
||||
if (normalizedDir === normalizedAllowed ||
|
||||
normalizedDir.startsWith(normalizedAllowed + '/')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -72,19 +82,11 @@ export async function onRequest(context) {
|
||||
|
||||
// 解析允许的目录
|
||||
const allowedDirStr = publicBrowse.allowedDir || '';
|
||||
const allowedDirs = allowedDirStr.split(',').filter(d => d.trim());
|
||||
|
||||
// 如果没有配置任何允许的目录,拒绝访问
|
||||
if (allowedDirs.length === 0) {
|
||||
return new Response(JSON.stringify({ error: 'No public directories configured' }), {
|
||||
status: 403,
|
||||
headers: { 'Content-Type': 'application/json', ...corsHeaders }
|
||||
});
|
||||
}
|
||||
let allowedDirs = allowedDirStr.split(',').map(d => d.trim()).filter(d => d);
|
||||
|
||||
// 获取请求的目录
|
||||
let dir = url.searchParams.get('dir') || '';
|
||||
|
||||
|
||||
// 检查目录权限
|
||||
if (!isAllowedDirectory(dir, allowedDirs)) {
|
||||
return new Response(JSON.stringify({ error: 'Directory not allowed' }), {
|
||||
|
||||
@@ -758,14 +758,35 @@ async function tryRetry(err, context, uploadChannel, fullId, metadata, fileExt,
|
||||
const errMessages = {};
|
||||
errMessages[uploadChannel] = 'Error: ' + uploadChannel + err;
|
||||
|
||||
// 先用原渠道再试一次(关闭服务端压缩)
|
||||
url.searchParams.set('serverCompress', 'false');
|
||||
let retryRes = null;
|
||||
if (uploadChannel === 'CloudflareR2') {
|
||||
retryRes = await uploadFileToCloudflareR2(context, fullId, metadata, returnLink);
|
||||
} else if (uploadChannel === 'TelegramNew') {
|
||||
retryRes = await uploadFileToTelegram(context, fullId, metadata, fileExt, fileName, fileType, returnLink);
|
||||
} else if (uploadChannel === 'S3') {
|
||||
retryRes = await uploadFileToS3(context, fullId, metadata, returnLink);
|
||||
} else if (uploadChannel === 'HuggingFace') {
|
||||
retryRes = await uploadFileToHuggingFace(context, fullId, metadata, returnLink);
|
||||
} else if (uploadChannel === 'Discord') {
|
||||
retryRes = await uploadFileToDiscord(context, fullId, metadata, returnLink);
|
||||
}
|
||||
|
||||
// 原渠道重试成功,直接返回
|
||||
if (retryRes && retryRes.status === 200) {
|
||||
return retryRes;
|
||||
} else if (retryRes) {
|
||||
errMessages[uploadChannel + '_retry'] = 'Error: ' + uploadChannel + ' retry - ' + await retryRes.text();
|
||||
}
|
||||
|
||||
// 原渠道重试失败,切换到其他渠道
|
||||
for (let i = 0; i < channelList.length; i++) {
|
||||
if (channelList[i] !== uploadChannel) {
|
||||
let res = null;
|
||||
if (channelList[i] === 'CloudflareR2') {
|
||||
res = await uploadFileToCloudflareR2(context, fullId, metadata, returnLink);
|
||||
} else if (channelList[i] === 'TelegramNew') {
|
||||
// 重试时禁用服务端压缩,避免压缩导致的问题
|
||||
url.searchParams.set('serverCompress', 'false');
|
||||
res = await uploadFileToTelegram(context, fullId, metadata, fileExt, fileName, fileType, returnLink);
|
||||
} else if (channelList[i] === 'S3') {
|
||||
res = await uploadFileToS3(context, fullId, metadata, returnLink);
|
||||
|
||||
@@ -1 +1 @@
|
||||
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/logo.png"><link rel="apple-touch-icon" href="/logo.png"><link rel="mask-icon" href="/logo.png" color="#f4b400"><meta name="description" content="Sanyue ImgHub - A modern file hosting platform"><meta name="keywords" content="Sanyue, ImgHub, file hosting, image hosting, cloud storage"><meta name="author" content="SanyueQi"><title>Sanyue ImgHub</title><script defer="defer" src="/js/chunk-vendors.780b6559.js"></script><script defer="defer" src="/js/app.830eeb78.js"></script><link href="/css/chunk-vendors.4363ed49.css" rel="stylesheet"><link href="/css/app.14879ca1.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but sanyue_imghub doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/logo.png"><link rel="apple-touch-icon" href="/logo.png"><link rel="mask-icon" href="/logo.png" color="#f4b400"><meta name="description" content="Sanyue ImgHub - A modern file hosting platform"><meta name="keywords" content="Sanyue, ImgHub, file hosting, image hosting, cloud storage"><meta name="author" content="SanyueQi"><title>Sanyue ImgHub</title><script defer="defer" src="/js/chunk-vendors.780b6559.js"></script><script defer="defer" src="/js/app.3ce2c999.js"></script><link href="/css/chunk-vendors.4363ed49.css" rel="stylesheet"><link href="/css/app.14879ca1.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but sanyue_imghub doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||
BIN
index.html.gz
BIN
index.html.gz
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
BIN
js/538.2f17dc35.js.gz
Normal file
BIN
js/538.2f17dc35.js.gz
Normal file
Binary file not shown.
1
js/538.2f17dc35.js.map
Normal file
1
js/538.2f17dc35.js.map
Normal file
File diff suppressed because one or more lines are too long
BIN
js/538.2f17dc35.js.map.gz
Normal file
BIN
js/538.2f17dc35.js.map.gz
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
BIN
js/543.bc47e44b.js.gz
Normal file
BIN
js/543.bc47e44b.js.gz
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
BIN
js/543.bc47e44b.js.map.gz
Normal file
BIN
js/543.bc47e44b.js.map.gz
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
2
js/app.3ce2c999.js
Normal file
2
js/app.3ce2c999.js
Normal file
File diff suppressed because one or more lines are too long
BIN
js/app.3ce2c999.js.gz
Normal file
BIN
js/app.3ce2c999.js.gz
Normal file
Binary file not shown.
1
js/app.3ce2c999.js.map
Normal file
1
js/app.3ce2c999.js.map
Normal file
File diff suppressed because one or more lines are too long
BIN
js/app.3ce2c999.js.map.gz
Normal file
BIN
js/app.3ce2c999.js.map.gz
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 1006 KiB After Width: | Height: | Size: 4.0 MiB |
Reference in New Issue
Block a user