Skip to content

Commit

Permalink
fix: can not start server when no s3 config
Browse files Browse the repository at this point in the history
  • Loading branch information
OXeu committed Jun 7, 2024
1 parent 9559924 commit 32eeb56
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions server/src/services/storage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
import Elysia, { t } from "elysia";
import path from "node:path";
import type { DB } from "../_worker";
import type { Env } from "../db/db";
import { setup } from "../setup";
import path from "node:path"

function buf2hex(buffer: ArrayBuffer) {
return [...new Uint8Array(buffer)]
Expand All @@ -19,18 +19,6 @@ export const StorageService = (db: DB, env: Env) => {
const accessHost = env.S3_ACCESS_HOST || endpoint;
const bucket = env.S3_BUCKET;
const folder = env.S3_FOLDER || '';
if (!endpoint) {
throw new Error('S3_ENDPOINT is not defined');
}
if (!accessKeyId) {
throw new Error('S3_ACCESS_KEY_ID is not defined');
}
if (!secretAccessKey) {
throw new Error('S3_SECRET_ACCESS_KEY is not defined');
}
if (!bucket) {
throw new Error('S3_BUCKET is not defined');
}
const s3 = new S3Client({
region: region,
endpoint: endpoint,
Expand All @@ -44,6 +32,23 @@ export const StorageService = (db: DB, env: Env) => {
.group('/storage', (group) =>
group
.post('/', async ({ uid, set, body: { key, file } }) => {

if (!endpoint) {
set.status = 500;
return 'S3_ENDPOINT is not defined'
}
if (!accessKeyId) {
set.status = 500;
return 'S3_ACCESS_KEY_ID is not defined'
}
if (!secretAccessKey) {
set.status = 500;
return 'S3_SECRET_ACCESS_KEY is not defined'
}
if (!bucket) {
set.status = 500;
return 'S3_BUCKET is not defined'
}
if (!uid) {
set.status = 401;
return 'Unauthorized';
Expand Down

0 comments on commit 32eeb56

Please sign in to comment.