@arkyn/server 1.4.10 → 1.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,7 +5,11 @@ type AWSConfig = {
|
|
|
5
5
|
AWS_SECRET_ACCESS_KEY: string;
|
|
6
6
|
AWS_S3_BUCKET: string;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
type Config = {
|
|
9
|
+
maxPartSize?: number;
|
|
10
|
+
fileName?: string;
|
|
11
|
+
};
|
|
12
|
+
declare function sendFileToS3(props: ActionFunctionArgs, awsS3Config: AWSConfig, config?: Config): Promise<{
|
|
9
13
|
error: string;
|
|
10
14
|
url?: undefined;
|
|
11
15
|
} | {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendFileToS3.d.ts","sourceRoot":"","sources":["../../src/services/sendFileToS3.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,iBAAiB,CAAC;AAOzB,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAmDF,iBAAe,YAAY,
|
|
1
|
+
{"version":3,"file":"sendFileToS3.d.ts","sourceRoot":"","sources":["../../src/services/sendFileToS3.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,iBAAiB,CAAC;AAOzB,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,MAAM,GAAG;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAmDF,iBAAe,YAAY,CACzB,KAAK,EAAE,kBAAkB,EACzB,WAAW,EAAE,SAAS,EACtB,MAAM,GAAE,MAGP;;;;;;GA2CF;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -39,20 +39,25 @@ async function s3_upload(fileStream, contentType, awsS3Config) {
|
|
|
39
39
|
location: `https://${AWS_S3_BUCKET}.s3.amazonaws.com/${uploadParams.Key}`,
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
async function sendFileToS3(props, awsS3Config
|
|
42
|
+
async function sendFileToS3(props, awsS3Config, config = {
|
|
43
|
+
maxPartSize: 5_000_000,
|
|
44
|
+
fileName: "file",
|
|
45
|
+
}) {
|
|
46
|
+
const { fileName = "file", maxPartSize = 5_000_000 } = config;
|
|
43
47
|
const { request } = props;
|
|
44
48
|
const uploadHandler = composeUploadHandlers(createFileUploadHandler({
|
|
45
|
-
maxPartSize
|
|
49
|
+
maxPartSize,
|
|
46
50
|
file: ({ filename }) => filename,
|
|
47
51
|
}));
|
|
48
52
|
const formData = await parseMultipartFormData(request, uploadHandler);
|
|
49
|
-
const file = formData.get(
|
|
53
|
+
const file = formData.get(fileName);
|
|
50
54
|
if (!file)
|
|
51
55
|
throw new BadRequestError("No file uploaded");
|
|
52
56
|
const filterParams = getScopedParams(request);
|
|
53
57
|
const width = filterParams.get("w");
|
|
54
58
|
const height = filterParams.get("h");
|
|
55
|
-
|
|
59
|
+
const isImage = file.type.startsWith("image");
|
|
60
|
+
if (isImage && width && height) {
|
|
56
61
|
const image = sharp(file.getFilePath());
|
|
57
62
|
const metadata = await image.metadata();
|
|
58
63
|
if (metadata.width && metadata.height) {
|
package/package.json
CHANGED
|
@@ -19,6 +19,11 @@ type AWSConfig = {
|
|
|
19
19
|
AWS_S3_BUCKET: string;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
type Config = {
|
|
23
|
+
maxPartSize?: number;
|
|
24
|
+
fileName?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
22
27
|
async function s3_upload(
|
|
23
28
|
fileStream: fs.ReadStream,
|
|
24
29
|
contentType: string,
|
|
@@ -68,18 +73,26 @@ async function s3_upload(
|
|
|
68
73
|
};
|
|
69
74
|
}
|
|
70
75
|
|
|
71
|
-
async function sendFileToS3(
|
|
76
|
+
async function sendFileToS3(
|
|
77
|
+
props: ActionFunctionArgs,
|
|
78
|
+
awsS3Config: AWSConfig,
|
|
79
|
+
config: Config = {
|
|
80
|
+
maxPartSize: 5_000_000,
|
|
81
|
+
fileName: "file",
|
|
82
|
+
}
|
|
83
|
+
) {
|
|
84
|
+
const { fileName = "file", maxPartSize = 5_000_000 } = config;
|
|
72
85
|
const { request } = props;
|
|
73
86
|
|
|
74
87
|
const uploadHandler = composeUploadHandlers(
|
|
75
88
|
createFileUploadHandler({
|
|
76
|
-
maxPartSize
|
|
89
|
+
maxPartSize,
|
|
77
90
|
file: ({ filename }) => filename,
|
|
78
91
|
})
|
|
79
92
|
);
|
|
80
93
|
|
|
81
94
|
const formData = await parseMultipartFormData(request, uploadHandler);
|
|
82
|
-
const file = formData.get(
|
|
95
|
+
const file = formData.get(fileName) as unknown as NodeOnDiskFile;
|
|
83
96
|
|
|
84
97
|
if (!file) throw new BadRequestError("No file uploaded");
|
|
85
98
|
|
|
@@ -87,7 +100,9 @@ async function sendFileToS3(props: ActionFunctionArgs, awsS3Config: AWSConfig) {
|
|
|
87
100
|
const width = filterParams.get("w");
|
|
88
101
|
const height = filterParams.get("h");
|
|
89
102
|
|
|
90
|
-
|
|
103
|
+
const isImage = file.type.startsWith("image");
|
|
104
|
+
|
|
105
|
+
if (isImage && width && height) {
|
|
91
106
|
const image = sharp(file.getFilePath());
|
|
92
107
|
const metadata = await image.metadata();
|
|
93
108
|
|