diff --git a/bun.lockb b/bun.lockb index 62e448d..68ff44b 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index e0758b4..00a0156 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "kysely": "^0.27.4", "pg": "^8.13.1", "readable-to-ms": "^1.0.3", - "rolling-rate-limiter": "^0.4.2", - "ultralight-s3": "^0.0.7" + "rolling-rate-limiter": "^0.4.2" } } \ No newline at end of file diff --git a/src/utils/upload.ts b/src/utils/upload.ts index 7c6b0d9..fd15fec 100644 --- a/src/utils/upload.ts +++ b/src/utils/upload.ts @@ -1,36 +1,37 @@ -import { S3 } from 'ultralight-s3'; import * as fs from 'node:fs' - const keys = JSON.parse(fs.readFileSync('s3.json', 'utf-8')) -const videos3 = new S3({ - endpoint: keys.endpoint, - accessKeyId: keys.videos[0].access, - secretAccessKey: keys.videos[0].secret, - bucketName: keys.videos[0].bucket -}) - -const images3 = new S3({ - endpoint: keys.endpoint, - accessKeyId: keys.images[0].access, - secretAccessKey: keys.images[0].secret, - bucketName: keys.images[0].bucket -}); async function uploadVideo(video: string) { - const videoFile = fs.readFileSync(video) - const uploaded = await videos3.put(video.split('/')[2], videoFile) + const uploaded = await fetch(`${keys.endpoint}/${video.split('/')[2]}`, { + method: 'PUT', + headers: { + 'x-authtoken': keys.videos[0].secret + }, + body: await Bun.file(video).arrayBuffer() + }) return uploaded.url.replace(keys.endpoint, 'https://s4.archive.party') } async function uploadImage(id: string, url: string) { const response = await fetch(url) - const buffer = Buffer.from(await response.arrayBuffer()) - const bufferHash = Bun.hash(buffer).toString() + const arrayBuffer = await response.arrayBuffer() + const bufferHash = Bun.hash(Buffer.from(arrayBuffer)).toString() - const exists = await images3.fileExists(`${id}-${bufferHash}.webp`) - if (exists) return `${keys.images[0].url}${id}-${bufferHash}.webp` + const exists = await fetch(`${keys.endpoint}/${id}-${bufferHash}.webp`, { + method: 'HEAD', + headers: { + 'x-authtoken': keys.videos[0].secret + } + }) + if (exists.status == 200) return `${keys.images[0].url}${id}-${bufferHash}.webp` - const uploaded = await images3.put(`${id}-${bufferHash}.webp`, buffer) + const uploaded = await fetch(`${keys.endpoint}/${id}-${bufferHash}.webp`, { + method: 'PUT', + headers: { + 'x-authtoken': keys.videos[0].secret + }, + body: await response.arrayBuffer() + }) return uploaded.url.replace(keys.endpoint, 'https://s4.archive.party') }