@galadrim/galadmin 0.1.232 → 0.1.233

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galadrim/galadmin",
3
- "version": "0.1.232",
3
+ "version": "0.1.233",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -16,8 +16,9 @@
16
16
  "@google-cloud/storage": "^7.17.2",
17
17
  "@rollup/plugin-babel": "^5.3.0",
18
18
  "@rollup/plugin-node-resolve": "^13.0.4",
19
+ "@aws-sdk/client-s3": "^3.1114.0",
20
+ "@aws-sdk/s3-request-presigner": "^3.1114.0",
19
21
  "argon2": "^0.31.2",
20
- "aws-sdk": "^2.958.0",
21
22
  "axios": "^0.28.1",
22
23
  "bcryptjs": "^2.4.3",
23
24
  "connect-pg-simple": "^9.0.1",
package/src/api.ts CHANGED
@@ -5,7 +5,8 @@ import * as path from "path";
5
5
  import * as crypto from "crypto";
6
6
  import * as mime from "mime";
7
7
 
8
- import { S3, Endpoint } from "aws-sdk";
8
+ import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
9
+ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
9
10
  import { Storage } from "@google-cloud/storage";
10
11
  import sizeOf from "image-size";
11
12
  import * as serializeJs from "serialize-javascript";
@@ -1280,28 +1281,42 @@ export default (db, config) => {
1280
1281
  Math.random().toString().substr(2) +
1281
1282
  "." +
1282
1283
  extension;
1283
- const s3 = new S3({
1284
- endpoint: new Endpoint(s3Config.host),
1285
- accessKeyId: s3Config.accessKeyId,
1286
- secretAccessKey: s3Config.secretAccessKey,
1284
+ const rawHost = String(s3Config.host || "");
1285
+ const endpoint = /^https?:\/\//i.test(rawHost)
1286
+ ? rawHost
1287
+ : `https://${rawHost}`;
1288
+ const s3 = new S3Client({
1289
+ endpoint,
1287
1290
  region: s3Config.region,
1288
- signatureVersion: "v4",
1291
+ credentials: {
1292
+ accessKeyId: s3Config.accessKeyId,
1293
+ secretAccessKey: s3Config.secretAccessKey,
1294
+ },
1295
+ forcePathStyle: false,
1289
1296
  });
1290
1297
  if (s3Config.signedUrlNeeded) {
1291
- const signedUrl = s3.getSignedUrl("putObject", {
1292
- Bucket: s3Config.bucket,
1293
- Key: path,
1294
- ContentType: contentType,
1295
- Expires: 150,
1296
- });
1297
- axios
1298
- .put(signedUrl, fs.readFileSync(files[fileParamName][0].path), {
1299
- maxContentLength: 100000000000,
1300
- maxBodyLength: 100000000000,
1301
- headers: {
1302
- "Content-Type": contentType,
1303
- },
1304
- })
1298
+ getSignedUrl(
1299
+ s3,
1300
+ new PutObjectCommand({
1301
+ Bucket: s3Config.bucket,
1302
+ Key: path,
1303
+ ContentType: contentType,
1304
+ }),
1305
+ { expiresIn: 150 }
1306
+ )
1307
+ .then((signedUrl) =>
1308
+ axios.put(
1309
+ signedUrl,
1310
+ fs.readFileSync(files[fileParamName][0].path),
1311
+ {
1312
+ maxContentLength: 100000000000,
1313
+ maxBodyLength: 100000000000,
1314
+ headers: {
1315
+ "Content-Type": contentType,
1316
+ },
1317
+ }
1318
+ )
1319
+ )
1305
1320
  .then(() => {
1306
1321
  res.status(200).send({
1307
1322
  path: s3Config.pathTransform
@@ -1315,16 +1330,16 @@ export default (db, config) => {
1315
1330
  res.status(500).send(e);
1316
1331
  });
1317
1332
  } else {
1318
- s3.putObject(
1319
- {
1333
+ s3.send(
1334
+ new PutObjectCommand({
1320
1335
  Body: fs.readFileSync(files[fileParamName][0].path),
1321
1336
  Bucket: s3Config.bucket,
1322
1337
  ContentType: contentType,
1323
1338
  ACL: "public-read",
1324
1339
  Key: path,
1325
- },
1326
- function (err, data) {
1327
- if (err) return res.status(500).send(err);
1340
+ })
1341
+ )
1342
+ .then(() => {
1328
1343
  res.send({
1329
1344
  url: `https://${s3Config.host}/${s3Config.bucket}/${path}`,
1330
1345
  path: s3Config.pathTransform
@@ -1333,8 +1348,8 @@ export default (db, config) => {
1333
1348
  aspectRatio,
1334
1349
  originalFilename,
1335
1350
  });
1336
- }
1337
- );
1351
+ })
1352
+ .catch((err) => res.status(500).send(err));
1338
1353
  }
1339
1354
  }
1340
1355
  });
@@ -0,0 +1,12 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -x "$basedir/node" ]; then
9
+ exec "$basedir/node" "$basedir/../semver/bin/semver.js" "$@"
10
+ else
11
+ exec node "$basedir/../semver/bin/semver.js" "$@"
12
+ fi
@@ -0,0 +1,17 @@
1
+ @ECHO off
2
+ GOTO start
3
+ :find_dp0
4
+ SET dp0=%~dp0
5
+ EXIT /b
6
+ :start
7
+ SETLOCAL
8
+ CALL :find_dp0
9
+
10
+ IF EXIST "%dp0%\node.exe" (
11
+ SET "_prog=%dp0%\node.exe"
12
+ ) ELSE (
13
+ SET "_prog=node"
14
+ SET PATHEXT=%PATHEXT:;.JS;=;%
15
+ )
16
+
17
+ endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\semver\bin\semver.js" %*
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env pwsh
2
+ $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
3
+
4
+ $exe=""
5
+ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
6
+ # Fix case when both the Windows and Linux builds of Node
7
+ # are installed in the same directory
8
+ $exe=".exe"
9
+ }
10
+ $ret=0
11
+ if (Test-Path "$basedir/node$exe") {
12
+ # Support pipeline input
13
+ if ($MyInvocation.ExpectingInput) {
14
+ $input | & "$basedir/node$exe" "$basedir/../semver/bin/semver.js" $args
15
+ } else {
16
+ & "$basedir/node$exe" "$basedir/../semver/bin/semver.js" $args
17
+ }
18
+ $ret=$LASTEXITCODE
19
+ } else {
20
+ # Support pipeline input
21
+ if ($MyInvocation.ExpectingInput) {
22
+ $input | & "node$exe" "$basedir/../semver/bin/semver.js" $args
23
+ } else {
24
+ & "node$exe" "$basedir/../semver/bin/semver.js" $args
25
+ }
26
+ $ret=$LASTEXITCODE
27
+ }
28
+ exit $ret