IdkWhatever69
IdkWhatever69
Explore posts from servers
CDCloudflare Developers
Created by IdkWhatever69 on 4/13/2024 in #general-help
cant call my api hosted on cf workers from python
No description
3 replies
CDCloudflare Developers
Created by IdkWhatever69 on 12/9/2023 in #general-help
confusion about cf workers CPU limit
No description
16 replies
CDCloudflare Developers
Created by IdkWhatever69 on 9/7/2023 in #general-help
caches.default.match() always returns undefined. even after caches.default.put() is executed.
export async function FITThetaTauEvents(ctx: ExecutionContext) {
const events_list = await (async () => {
const events_discord_url = `${RouteBases.api}${Routes.guildScheduledEvents("12345678901234")}?with_user_count=true`;

//check for cache
const cache_res = await caches.default.match(events_discord_url);
if (exists(cache_res)) { //always returns udefined here some how <<<<<<<<<<<<<<<-----
const now = Date.now();
const cached_time = (new Date(cache_res.headers.get('X-Cached-At')!)).getTime();

if ((now - cached_time) <= 300000)
return await cache_res.clone().json() as RESTGetAPIGuildScheduledEventsResult;
}

//else fetch
const proto_res = await fetch(
events_discord_url,
{
body: null,
method: 'GET',
headers: {
'Authorization': `Bot ${FITThetaTauRESTBot_credentials.token}`,
'Content-Type': `application/json`
}
}
);

if (!proto_res.ok) return null;

if (exists(proto_res.clone().body)) {
const cache_header = new Headers(proto_res.headers);
cache_header.append('X-Cached-At', new Date().toUTCString());

ctx.waitUntil(caches.default.put(
events_discord_url,
new Response(proto_res.clone().body, {
headers: cache_header,
status: proto_res.status,
statusText: proto_res.statusText
})
))

return await proto_res.json() as RESTGetAPIGuildScheduledEventsResult|undefined;
} else {
return null;
}
})();
export async function FITThetaTauEvents(ctx: ExecutionContext) {
const events_list = await (async () => {
const events_discord_url = `${RouteBases.api}${Routes.guildScheduledEvents("12345678901234")}?with_user_count=true`;

//check for cache
const cache_res = await caches.default.match(events_discord_url);
if (exists(cache_res)) { //always returns udefined here some how <<<<<<<<<<<<<<<-----
const now = Date.now();
const cached_time = (new Date(cache_res.headers.get('X-Cached-At')!)).getTime();

if ((now - cached_time) <= 300000)
return await cache_res.clone().json() as RESTGetAPIGuildScheduledEventsResult;
}

//else fetch
const proto_res = await fetch(
events_discord_url,
{
body: null,
method: 'GET',
headers: {
'Authorization': `Bot ${FITThetaTauRESTBot_credentials.token}`,
'Content-Type': `application/json`
}
}
);

if (!proto_res.ok) return null;

if (exists(proto_res.clone().body)) {
const cache_header = new Headers(proto_res.headers);
cache_header.append('X-Cached-At', new Date().toUTCString());

ctx.waitUntil(caches.default.put(
events_discord_url,
new Response(proto_res.clone().body, {
headers: cache_header,
status: proto_res.status,
statusText: proto_res.statusText
})
))

return await proto_res.json() as RESTGetAPIGuildScheduledEventsResult|undefined;
} else {
return null;
}
})();
5 replies