mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-02-01 22:47:37 +00:00
Feat:访客图库体验优化;Discord渠道访问优化
This commit is contained in:
1
css/289.f7890ec7.css
Normal file
1
css/289.f7890ec7.css
Normal file
File diff suppressed because one or more lines are too long
BIN
css/289.f7890ec7.css.gz
Normal file
BIN
css/289.f7890ec7.css.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
BIN
css/667.a3c83e09.css.gz
Normal file
BIN
css/667.a3c83e09.css.gz
Normal file
Binary file not shown.
Binary file not shown.
@@ -5,7 +5,7 @@ export function isDomainAllowed(context) {
|
||||
const { Referer, securityConfig, url } = context;
|
||||
|
||||
const allowedDomains = securityConfig.access.allowedDomains;
|
||||
|
||||
|
||||
if (Referer) {
|
||||
try {
|
||||
const refererUrl = new URL(Referer);
|
||||
@@ -17,7 +17,7 @@ export function isDomainAllowed(context) {
|
||||
let domainPattern = new RegExp(`(^|\\.)${domain.replace('.', '\\.')}$`); // Escape dot in domain
|
||||
return domainPattern.test(refererUrl.hostname);
|
||||
});
|
||||
|
||||
|
||||
if (!isAllowed) {
|
||||
return false;
|
||||
}
|
||||
@@ -30,19 +30,37 @@ export function isDomainAllowed(context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 判断请求是否来自公开图库页面 (/browse 或 /browse/*)
|
||||
export function isFromPublicBrowse(Referer, origin) {
|
||||
if (!Referer) return false;
|
||||
try {
|
||||
const refererUrl = new URL(Referer);
|
||||
// 检查是否来自同源的 /browse 或 /browse/* 路径
|
||||
if (refererUrl.origin === origin) {
|
||||
const pathname = refererUrl.pathname;
|
||||
if (pathname === '/browse' || pathname.startsWith('/browse/')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 公共响应头设置函数
|
||||
export function setCommonHeaders(headers, encodedFileName, fileType, Referer, url) {
|
||||
headers.set('Content-Disposition', `inline; filename="${encodedFileName}"; filename*=UTF-8''${encodedFileName}`);
|
||||
headers.set('Access-Control-Allow-Origin', '*');
|
||||
headers.set('Accept-Ranges', 'bytes');
|
||||
headers.set('Vary', 'Range');
|
||||
|
||||
|
||||
if (fileType) {
|
||||
headers.set('Content-Type', fileType);
|
||||
}
|
||||
|
||||
// 根据Referer设置CDN缓存策略
|
||||
if (Referer && Referer.includes(url.origin)) {
|
||||
|
||||
// 根据Referer设置CDN缓存策略(排除公开图库页面的请求)
|
||||
if (Referer && Referer.includes(url.origin) && !isFromPublicBrowse(Referer, url.origin)) {
|
||||
headers.set('Cache-Control', 'private, max-age=86400'); // 本地缓存 1天
|
||||
} else {
|
||||
headers.set('Cache-Control', 'public, max-age=2592000'); // CDN缓存 30天
|
||||
@@ -59,7 +77,7 @@ export function setRangeHeaders(headers, rangeStart, rangeEnd, totalSize) {
|
||||
// 处理HEAD请求的公共函数
|
||||
export function handleHeadRequest(headers, etag = null) {
|
||||
const responseHeaders = new Headers();
|
||||
|
||||
|
||||
// 复制关键头部
|
||||
responseHeaders.set('Content-Length', headers.get('Content-Length') || '0');
|
||||
responseHeaders.set('Content-Type', headers.get('Content-Type') || 'application/octet-stream');
|
||||
@@ -67,11 +85,11 @@ export function handleHeadRequest(headers, etag = null) {
|
||||
responseHeaders.set('Access-Control-Allow-Origin', headers.get('Access-Control-Allow-Origin') || '*');
|
||||
responseHeaders.set('Accept-Ranges', headers.get('Accept-Ranges') || 'bytes');
|
||||
responseHeaders.set('Cache-Control', headers.get('Cache-Control') || 'public, max-age=2592000');
|
||||
|
||||
|
||||
if (etag) {
|
||||
responseHeaders.set('ETag', etag);
|
||||
}
|
||||
|
||||
|
||||
return new Response(null, {
|
||||
status: 200,
|
||||
headers: responseHeaders,
|
||||
@@ -112,8 +130,9 @@ export async function returnWithCheck(context, imgRecord) {
|
||||
|
||||
const response = new Response('success', { status: 200 });
|
||||
|
||||
// Referer header equal to the dashboard page or upload page
|
||||
if (request.headers.get('Referer') && request.headers.get('Referer').includes(url.origin)) {
|
||||
// Referer header equal to the dashboard page or upload page (排除公开图库页面的请求)
|
||||
const referer = request.headers.get('Referer');
|
||||
if (referer && referer.includes(url.origin) && !isFromPublicBrowse(referer, url.origin)) {
|
||||
//show the image
|
||||
return response;
|
||||
}
|
||||
@@ -139,7 +158,7 @@ export async function returnWithCheck(context, imgRecord) {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// other cases
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -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.d2aa04d7.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.41abafbc.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
BIN
js/289.8c3b6ce7.js.gz
Normal file
BIN
js/289.8c3b6ce7.js.gz
Normal file
Binary file not shown.
1
js/289.8c3b6ce7.js.map
Normal file
1
js/289.8c3b6ce7.js.map
Normal file
File diff suppressed because one or more lines are too long
BIN
js/289.8c3b6ce7.js.map.gz
Normal file
BIN
js/289.8c3b6ce7.js.map.gz
Normal file
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
2
js/667.bbd60d43.js
Normal file
2
js/667.bbd60d43.js
Normal file
File diff suppressed because one or more lines are too long
BIN
js/667.bbd60d43.js.gz
Normal file
BIN
js/667.bbd60d43.js.gz
Normal file
Binary file not shown.
1
js/667.bbd60d43.js.map
Normal file
1
js/667.bbd60d43.js.map
Normal file
File diff suppressed because one or more lines are too long
BIN
js/667.bbd60d43.js.map.gz
Normal file
BIN
js/667.bbd60d43.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.
File diff suppressed because one or more lines are too long
BIN
js/app.41abafbc.js.gz
Normal file
BIN
js/app.41abafbc.js.gz
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
BIN
js/app.41abafbc.js.map.gz
Normal file
BIN
js/app.41abafbc.js.map.gz
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user