Skip to content
Permalink
71381e937b
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
40 lines (37 sloc) 854 Bytes
import { AwsClient } from "aws4fetch";
const contentTypes: { [k: string]: string } = {
gif: "image/gif",
m4v: "video/x-m4v",
mkv: "video/x-matroska",
mov: "video/mp4",
mp4: "video/mp4",
webm: "video/webm",
wmv: "video/x-ms-wmv",
};
export default async function (
env: Env,
path: string,
size: number,
extension: string,
) {
const aws = new AwsClient({
accessKeyId: env.R2_ACCESS_KEY,
secretAccessKey: env.R2_SECRET_KEY,
});
return (
await aws.sign(
`https://car-crushers.${env.R2_ZONE}.r2.cloudflarestorage.com/${path}?X-Amz-Expires=1800`,
{
aws: {
allHeaders: true,
signQuery: true,
},
headers: {
"content-length": size.toString(),
"content-type": contentTypes[extension],
},
method: "PUT",
},
)
).url;
}