Improve caching quality for non-Discord non Telegram bots

This commit is contained in:
dangered wolf 2023-11-12 02:08:33 -05:00
parent 91878e91c7
commit 0c2fe9d58b
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58

View file

@ -7,13 +7,15 @@ export const cacheMiddleware = (): MiddlewareHandler => async (c, next) => {
const request = c.req; const request = c.req;
const userAgent = request.header('User-Agent') ?? ''; const userAgent = request.header('User-Agent') ?? '';
// https://developers.cloudflare.com/workers/examples/cache-api/ // https://developers.cloudflare.com/workers/examples/cache-api/
const cacheUrl = new URL( let cacheUrl = new URL(request.url);
userAgent.includes('Telegram')
? `${request.url}&telegram` if (userAgent.includes('Telegram')) {
: userAgent.includes('Discord') cacheUrl = new URL(`${request.url}&telegram`);
? `${request.url}&discord` } else if (userAgent.includes('Discord')) {
: request.url cacheUrl = new URL(`${request.url}&discord`);
); } else if (userAgent.match(Constants.BOT_UA_REGEX)) {
cacheUrl = new URL(`${request.url}&bot`);
}
console.log('cacheUrl', cacheUrl); console.log('cacheUrl', cacheUrl);