mirror of
https://github.com/ZSCGR/CloudFlare-ImgBed.git
synced 2026-08-19 15:13:44 +08:00
fix: prevent cached manage API mutations
This commit is contained in:
@@ -1,10 +1,32 @@
|
||||
import { authenticate, AUTH_SCOPE } from "../../utils/auth/authCore.js";
|
||||
|
||||
const DEFAULT_MANAGE_CACHE_CONTROL = 'private, no-store, max-age=0';
|
||||
|
||||
function withDefaultCacheControl(response) {
|
||||
if (response.headers.has('Cache-Control')) {
|
||||
return response;
|
||||
}
|
||||
|
||||
const headers = new Headers(response.headers);
|
||||
headers.set('Cache-Control', DEFAULT_MANAGE_CACHE_CONTROL);
|
||||
|
||||
return new Response(response.body, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers,
|
||||
});
|
||||
}
|
||||
|
||||
async function errorHandling(context) {
|
||||
try {
|
||||
return await context.next();
|
||||
return withDefaultCacheControl(await context.next());
|
||||
} catch (err) {
|
||||
return new Response(`${err.message}\n${err.stack}`, { status: 500 });
|
||||
return new Response(`${err.message}\n${err.stack}`, {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Cache-Control': DEFAULT_MANAGE_CACHE_CONTROL,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user