Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 76854fb

Browse files
committed
chore: update uploads to read from correct env
1 parent 6d0c35b commit 76854fb

File tree

9 files changed

+22
-20
lines changed

9 files changed

+22
-20
lines changed

modules/uploads/scripts/complete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function run(
1919
ctx: ScriptContext,
2020
req: Request,
2121
): Promise<Response> {
22-
const config = getConfig(ctx.config);
22+
const config = getConfig(ctx);
2323

2424
const newUpload = await ctx.db.$transaction(async (db) => {
2525
// Find the upload by ID

modules/uploads/scripts/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export async function run(
1515
ctx: ScriptContext,
1616
req: Request,
1717
): Promise<Response> {
18-
const config = getConfig(ctx.config);
18+
const config = getConfig(ctx);
1919

2020
const bytesDeleted = await ctx.db.$transaction(async (db) => {
2121
const upload = await db.upload.findFirst({

modules/uploads/scripts/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function run(
1919
ctx: ScriptContext,
2020
req: Request,
2121
): Promise<Response> {
22-
getConfig(ctx.config);
22+
getConfig(ctx);
2323

2424
// Find uploads that match the IDs in the request
2525
const dbUploads = await ctx.db.upload.findMany({

modules/uploads/scripts/get_public_file_urls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function run(
1717
ctx: ScriptContext,
1818
req: Request,
1919
): Promise<Response> {
20-
const config = getConfig(ctx.config);
20+
const config = getConfig(ctx);
2121

2222
const dbFiles = await ctx.db.files.findMany({
2323
where: {

modules/uploads/scripts/prepare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function run(
2424
ctx: ScriptContext,
2525
req: Request,
2626
): Promise<Response> {
27-
const config = getConfig(ctx.config);
27+
const config = getConfig(ctx);
2828

2929
// Ensure there are files in the upload
3030
if (req.files.length === 0) {

modules/uploads/tests/e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { faker } from "https://deno.land/x/deno_faker@v1.0.3/mod.ts";
77
import { getS3EnvConfig } from "../utils/env.ts";
88

99
test("e2e", async (ctx: TestContext) => {
10-
if (!getS3EnvConfig()) {
10+
if (!getS3EnvConfig(ctx)) {
1111
ctx.log.warn("s3 not configured");
1212
return;
1313
}

modules/uploads/tests/multipart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function randomBuffer(size: number): Uint8Array {
1919
}
2020

2121
test("multipart uploads", async (ctx: TestContext) => {
22-
if (!getS3EnvConfig()) {
22+
if (!getS3EnvConfig(ctx)) {
2323
ctx.log.warn("s3 not configured");
2424
return;
2525
}

modules/uploads/utils/config_defaults.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RuntimeError } from "../module.gen.ts";
1+
import { RuntimeError, ScriptContext } from "../module.gen.ts";
22
import { Config as UserConfig } from "../config.ts";
33
import { getS3EnvConfig, S3Config } from "./env.ts";
44

@@ -13,17 +13,17 @@ interface Config {
1313
s3: S3Config;
1414
}
1515

16-
export function getConfig(config: UserConfig): Required<Config> {
17-
const s3 = getS3EnvConfig();
16+
export function getConfig(ctx: ScriptContext): Required<Config> {
17+
const s3 = getS3EnvConfig(ctx);
1818
if (!s3) throw new RuntimeError("s3_not_configured");
1919

2020
const nonOptionalConfig = {
21-
maxUploadSize: config.maxUploadSize ?? defaults.DEFAULT_MAX_UPLOAD_SIZE,
22-
maxMultipartUploadSize: config.maxMultipartUploadSize ??
21+
maxUploadSize: ctx.config.maxUploadSize ?? defaults.DEFAULT_MAX_UPLOAD_SIZE,
22+
maxMultipartUploadSize: ctx.config.maxMultipartUploadSize ??
2323
defaults.DEFAULT_MAX_MULTIPART_UPLOAD_SIZE,
24-
maxFilesPerUpload: config.maxFilesPerUpload ??
24+
maxFilesPerUpload: ctx.config.maxFilesPerUpload ??
2525
defaults.DEFAULT_MAX_FILES_PER_UPLOAD,
26-
defaultMultipartChunkSize: config.defaultMultipartChunkSize ??
26+
defaultMultipartChunkSize: ctx.config.defaultMultipartChunkSize ??
2727
defaults.DEFAULT_MULTIPART_CHUNK_SIZE,
2828
s3,
2929
};

modules/uploads/utils/env.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ModuleContext, ScriptContext } from "../module.gen.ts";
2+
13
export interface S3EnvConfig {
24
S3_ENDPOINT: string;
35
S3_REGION: string;
@@ -14,12 +16,12 @@ export interface S3Config {
1416
secretAccessKey: string;
1517
}
1618

17-
export function getS3EnvConfig(): S3Config | null {
18-
const endpoint = Deno.env.get("S3_ENDPOINT");
19-
const region = Deno.env.get("S3_REGION");
20-
const bucket = Deno.env.get("S3_BUCKET");
21-
const accessKeyId = Deno.env.get("S3_ACCESS_KEY_ID");
22-
const secretAccessKey = Deno.env.get("S3_SECRET_ACCESS_KEY");
19+
export function getS3EnvConfig(ctx: ScriptContext): S3Config | null {
20+
const endpoint = ctx.environment.get("S3_ENDPOINT");
21+
const region = ctx.environment.get("S3_REGION");
22+
const bucket = ctx.environment.get("S3_BUCKET");
23+
const accessKeyId = ctx.environment.get("S3_ACCESS_KEY_ID");
24+
const secretAccessKey = ctx.environment.get("S3_SECRET_ACCESS_KEY");
2325

2426
if (
2527
!endpoint || !region || !bucket || !accessKeyId || !secretAccessKey

0 commit comments

Comments
 (0)