coderank-server-data/scripts/upload.ts
2026-01-28 13:30:30 +01:00

39 lines
883 B
TypeScript

import s3UploadFile from "../utils/s3-upload";
const cliArgs = [...process.argv];
const bucketDstName = cliArgs.pop();
const filePath = cliArgs.pop();
if (!filePath || !bucketDstName) {
console.error("Usage: bun upload.ts <file-path> <bucket/destination>");
process.exit(1);
}
const timeSeriesR2Name = bucketDstName
.split("/")
.map((p, i, arr) => {
if (arr.length - 1 !== i) return p;
const fileNameArr = p.split(".");
const fileName = fileNameArr.shift();
if (!fileName) return p;
const newName = `${fileName}-${Date.now()}.${fileNameArr.filter((n) => Boolean(n.match(/./))).join(".")}`;
return newName;
})
.join("/");
await s3UploadFile({
fileName: bucketDstName,
filePath,
});
await s3UploadFile({
fileName: timeSeriesR2Name,
filePath,
});
console.log(`✅ Uploaded ${filePath}`);