Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
fern committed Dec 30, 2024
1 parent 6cc4b9c commit 8e70c76
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions servers/fdr/src/services/s3/S3Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
PutObjectCommandInput,
S3Client,
} from "@aws-sdk/client-s3";
import { createPresignedPost } from "@aws-sdk/s3-presigned-post";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
import {
APIV1Write,
DocsV1Write,
Expand Down Expand Up @@ -42,7 +42,7 @@ const ALLOWED_FILE_TYPES = new Set<string>([
"font/woff",
"font/woff2",
"font/otf",
"font/ttf"
"font/ttf",
]);

export interface S3DocsFileInfo {
Expand Down Expand Up @@ -191,8 +191,10 @@ export class S3ServiceImpl implements S3Service {
const time: string = new Date().toISOString();
for (let i = 0; i < filepaths.length; i++) {
const filepath = filepaths[i];
const filesize = typeof filesizes === "undefined" ? undefined : filesizes[i];
const mimeType = typeof mimeTypes === "undefined" ? undefined : mimeTypes[i];
const filesize =
typeof filesizes === "undefined" ? undefined : filesizes[i];
const mimeType =
typeof mimeTypes === "undefined" ? undefined : mimeTypes[i];
if (typeof filepath === "undefined") continue;

const { url, key } =
Expand All @@ -202,7 +204,7 @@ export class S3ServiceImpl implements S3Service {
filepath,
isPrivate,
filesize,
mimeType
mimeType,
});
result[filepath] = {
presignedUrl: {
Expand All @@ -216,8 +218,14 @@ export class S3ServiceImpl implements S3Service {
for (let i = 0; i < images.length; i++) {
const image = images[i];
// expected sizes for images + files are concatenated in the filesize/mimeType array
const filesize = typeof filesizes === "undefined" ? undefined : filesizes[i + filepaths.length];
const mimeType = typeof mimeTypes === "undefined" ? undefined : mimeTypes[i + filepaths.length];
const filesize =
typeof filesizes === "undefined"
? undefined
: filesizes[i + filepaths.length];
const mimeType =
typeof mimeTypes === "undefined"
? undefined
: mimeTypes[i + filepaths.length];
if (typeof image === "undefined") continue;

const { url, key } =
Expand All @@ -227,7 +235,7 @@ export class S3ServiceImpl implements S3Service {
filepath: image.filePath,
isPrivate,
filesize,
mimeType
mimeType,
});
result[image.filePath] = {
presignedUrl: {
Expand Down Expand Up @@ -269,13 +277,13 @@ export class S3ServiceImpl implements S3Service {

let conditions: any[] | undefined = [];
if (typeof filesize !== "undefined") {
conditions.push(['content-length-range', filesize, filesize]);
conditions.push(["content-length-range", filesize, filesize]);
}
if (typeof mimeType !== "undefined") {
if (!ALLOWED_FILE_TYPES.has(mimeType)) {
throw new Error("Invalid mime-type: " + mimeType); // TODO: are these generated somewhere?
}
conditions.push(['eq', '$Content-Type', mimeType]);
conditions.push(["eq", "$Content-Type", mimeType]);
}
if (conditions.length === 0) {
conditions = undefined;
Expand All @@ -289,9 +297,9 @@ export class S3ServiceImpl implements S3Service {
});

return {
url,
url,
key,
}
};
}

async getPresignedApiDefinitionSourceDownloadUrl({
Expand Down

0 comments on commit 8e70c76

Please sign in to comment.