Skip to content
Permalink
056c6b84f3
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
25 lines (24 sloc) 767 Bytes
export async function onRequestGet(context: RequestContext) {
const attachment = context.params.id as string;
const unsignedURL = `https://mediaproxy.carcrushers.cc/${attachment}?Expires=${(
Math.round(Date.now() / 1000) + 1800
).toString()}`;
const signingKey = await crypto.subtle.importKey(
"raw",
new TextEncoder().encode(atob(context.env.URL_SIGNING_KEY)),
{ hash: "SHA-1", name: "HMAC" },
false,
["sign"],
);
const signature = await crypto.subtle.sign(
"HMAC",
signingKey,
new TextEncoder().encode(unsignedURL),
);
return Response.redirect(
`${unsignedURL}&Signature=${btoa(new TextDecoder().decode(signature))
.replaceAll("+", "-")
.replaceAll("/", "_")
.replaceAll("=", "")}`,
);
}