Migrate to r2

This commit is contained in:
Jordan Eldredge 2022-10-09 19:33:36 -07:00
parent cb9d554806
commit 35542597fd
2 changed files with 12 additions and 7 deletions

View file

@ -11,6 +11,9 @@ import UserContext from "./UserContext";
import TweetModel from "./TweetModel";
import { TweetStatus } from "../types";
// const CDN_URL = "https://cdn.webampskins.org";
const CDN_URL = "https://r2.webampskins.org";
export const SKIN_TYPE = {
CLASSIC: 1,
MODERN: 2,
@ -19,15 +22,15 @@ export const SKIN_TYPE = {
};
export function getSkinUrl(md5: string): string {
return `https://cdn.webampskins.org/skins/${md5}.wsz`;
return `${CDN_URL}/skins/${md5}.wsz`;
}
export function getModernSkinUrl(md5: string): string {
return `https://cdn.webampskins.org/skins/${md5}.wal`;
return `${CDN_URL}/skins/${md5}.wal`;
}
export function getScreenshotUrl(md5: string): string {
return `https://cdn.webampskins.org/screenshots/${md5}.png`;
return `${CDN_URL}/screenshots/${md5}.png`;
}
export async function addSkin({

View file

@ -12,6 +12,9 @@ const s3 = new AWS.S3({
});
const bucketName = "winamp-skins";
// Needed for S3 but not R2
// const acl = { ACL: "public-read" };
const acl = {};
async function configureCors() {
console.log("Going to configure cors");
@ -46,14 +49,13 @@ const s3 = new AWS.S3({
function putSkin(md5, buffer, ext = "wsz") {
return new Promise((resolve, rejectPromise) => {
const bucketName = "cdn.webampskins.org";
const key = `skins/${md5}.${ext}`;
s3.putObject(
{
Bucket: bucketName,
Key: key,
Body: buffer,
ACL: "public-read",
...acl,
},
(err) => {
if (err) {
@ -146,7 +148,7 @@ function putScreenshot(md5, buffer) {
Bucket: bucketName,
Key: key,
Body: buffer,
ACL: "public-read",
...acl,
},
(err) => {
if (err) {
@ -167,7 +169,7 @@ function putTemp(fileName, buffer) {
Bucket: bucketName,
Key: key,
Body: buffer,
ACL: "public-read",
...acl,
},
(err) => {
console.log("Hello...");