feat: add hash

This commit is contained in:
熊潇 2025-05-12 23:02:11 +08:00
parent 3938a0f87e
commit 30589e3347

View File

@ -16,6 +16,7 @@ const getAiProxy = async (req: IncomingMessage, res: ServerResponse, opts: Proxy
const pathname = _u.pathname; const pathname = _u.pathname;
const params = _u.searchParams; const params = _u.searchParams;
const password = params.get('p'); const password = params.get('p');
const hash = params.get('hash');
let objectName = ''; let objectName = '';
let owner = ''; let owner = '';
const { user, app } = getUserFromRequest(req); const { user, app } = getUserFromRequest(req);
@ -42,6 +43,11 @@ const getAiProxy = async (req: IncomingMessage, res: ServerResponse, opts: Proxy
if (!checkPermission.success) { if (!checkPermission.success) {
return createNotFoundPage('no permission'); return createNotFoundPage('no permission');
} }
if (hash && stat.etag === hash) {
res.writeHead(304); // not modified
res.end('not modified')
return true;
}
const filterMetaData = filterKeys(stat.metaData, ['size', 'etag', 'last-modified']); const filterMetaData = filterKeys(stat.metaData, ['size', 'etag', 'last-modified']);
const contentLength = stat.size; const contentLength = stat.size;
const etag = stat.etag; const etag = stat.etag;