Skip to content

Commit

Permalink
Update to new S3 bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashoneyman committed Nov 28, 2023
1 parent 1d9e28b commit 0b9e006
Show file tree
Hide file tree
Showing 3 changed files with 1,506 additions and 407 deletions.
2 changes: 1 addition & 1 deletion foreign/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"private": true,
"license": "BSD-3-Clause",
"dependencies": {
"@aws-sdk/client-s3": "^3.461.0",
"@octokit/plugin-retry": "^3.0.9",
"@octokit/plugin-throttling": "^3.7.0",
"@octokit/rest": "^18.12.0",
"aws-sdk": "^2.1050.0",
"better-sqlite3": "^8.5.2",
"fast-glob": "^3.2.11",
"fs-extra": "^10.0.0",
Expand Down
64 changes: 24 additions & 40 deletions foreign/src/Foreign/S3.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,32 @@
import aws from "aws-sdk";
import {
DeleteObjectCommand,
ListObjectsCommand,
PutObjectCommand,
S3,
} from "@aws-sdk/client-s3";

export const connectImpl = ({ key, secret }, endpoint) => {
const spacesEndpoint = new aws.Endpoint(endpoint);
return new aws.S3({
endpoint: spacesEndpoint,
accessKeyId: key,
secretAccessKey: secret,
export const connectImpl = ({ key, secret }, endpoint) =>
new S3({
forcePathStyle: false,
endpoint,
region: "us-east-1",
credentials: {
accessKeyId: key,
secretAccessKey: secret,
},
});
};

// TODO: we should switch to v3 of the SDK:
// https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/listobjectsv2command.html
export const listObjectsImpl = (s3, params) => {
return new Promise(function (resolve, reject) {
s3.listObjectsV2(params, function (err, data) {
if (err) {
reject(err);
} else {
resolve(data["Contents"]);
}
});
});
export const listObjectsImpl = async (s3, params) => {
const data = await s3.send(new ListObjectsCommand(params));
return data["Contents"];
};

export const putObjectImpl = (s3, params) => {
return new Promise(function (resolve, reject) {
s3.putObject(params, function (err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
export const putObjectImpl = async (s3, params) => {
const data = await s3.send(new PutObjectCommand(params));
return data;
};

export const deleteObjectImpl = (s3, params) => {
return new Promise(function (resolve, reject) {
s3.deleteObject(params, function (err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
export const deleteObjectImpl = async (s3, params) => {
const data = await s3.send(new DeleteObjectCommand(params));
return data;
};
Loading

0 comments on commit 0b9e006

Please sign in to comment.