generated from nhcarrigan/template
This commit is contained in:
+3
-2
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"lint": "eslint src --max-warnings 0",
|
||||
"start": "node prod/index.js",
|
||||
"start": "op run --env-file=prod.env --no-masking -- tsx",
|
||||
"test": "echo \"Error: no test specified\" && exit 0"
|
||||
},
|
||||
"keywords": [],
|
||||
@@ -15,6 +15,8 @@
|
||||
"license": "ISC",
|
||||
"packageManager": "pnpm@10.15.0",
|
||||
"devDependencies": {
|
||||
"@aws-sdk/client-s3": "3.940.0",
|
||||
"@inquirer/prompts": "7.8.6",
|
||||
"@nhcarrigan/eslint-config": "5.2.0",
|
||||
"@nhcarrigan/typescript-config": "4.0.0",
|
||||
"@types/node": "24.3.0",
|
||||
@@ -23,7 +25,6 @@
|
||||
"typescript": "5.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@inquirer/prompts": "7.8.6",
|
||||
"@octokit/rest": "22.0.0",
|
||||
"@types/cli-progress": "3.11.6",
|
||||
"cli-progress": "3.12.0"
|
||||
|
||||
Generated
+1216
-3
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
AWS_ACCESS_KEY_ID="op://Private/Hetzner/S3 Access Key ID"
|
||||
AWS_SECRET_ACCESS_KEY="op://Private/Hetzner/S3 Secret Access Key"
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
||||
import { input } from "@inquirer/prompts";
|
||||
|
||||
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
||||
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
||||
|
||||
if (accessKeyId === undefined || secretAccessKey === undefined) {
|
||||
throw new Error("AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY is not set");
|
||||
}
|
||||
|
||||
const fileName = await input({
|
||||
message: "Enter the ABSOLUTE PATH of the file to upload",
|
||||
});
|
||||
if (fileName === "") {
|
||||
throw new Error("File name is not set");
|
||||
}
|
||||
|
||||
const file = await readFile(fileName);
|
||||
|
||||
const uploadPath = await input({
|
||||
message: "Enter the PATH to upload the file to",
|
||||
});
|
||||
if (uploadPath === "") {
|
||||
throw new Error("Upload path is not set");
|
||||
}
|
||||
|
||||
const s3 = new S3Client({
|
||||
credentials: { accessKeyId, secretAccessKey },
|
||||
endpoint: "https://hel1.your-objectstorage.com",
|
||||
region: "hel1",
|
||||
});
|
||||
|
||||
const command = new PutObjectCommand({
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- AWS SDK
|
||||
Body: file,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- AWS SDK
|
||||
Bucket: "nhcarrigan",
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- AWS SDK
|
||||
Key: uploadPath,
|
||||
});
|
||||
|
||||
await s3.send(command);
|
||||
|
||||
console.log(`Uploaded ${fileName} to ${uploadPath}`);
|
||||
Reference in New Issue
Block a user