Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace minio client with aws sdk #547

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"prepare": "husky install"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.554.0",
"@novnc/novnc": "^1.4.0",
"@types/sax": "^1.2.7",
"@webrecorder/wabac": "^2.16.12",
Expand All @@ -26,7 +27,6 @@
"ioredis": "^5.3.2",
"js-levenshtein": "^1.1.6",
"js-yaml": "^4.1.0",
"minio": "^7.1.3",
"p-queue": "^7.3.4",
"pixelmatch": "^5.3.0",
"pngjs": "^7.0.0",
Expand Down Expand Up @@ -60,5 +60,6 @@
"jest": {
"transform": {},
"testTimeout": 90000
}
},
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
43 changes: 26 additions & 17 deletions src/util/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import child_process from "child_process";
import fs from "fs";
import fsp from "fs/promises";
import util from "util";
import { pipeline } from "stream/promises";
import type { Readable } from "stream";

import os from "os";
import { createHash } from "crypto";

import crc32 from "crc/crc32";

import * as Minio from "minio";
import {
S3Client,
PutObjectCommand,
GetObjectCommand,
} from "@aws-sdk/client-s3";

import { initRedis } from "./redis.js";
import { logger } from "./logger.js";
Expand All @@ -21,7 +27,7 @@ const DEFAULT_REGION = "us-east-1";
// ===========================================================================
export class S3StorageSync {
fullPrefix: string;
client: Minio.Client;
client: S3Client;

bucketName: string;
objectPrefix: string;
Expand Down Expand Up @@ -62,13 +68,12 @@ export class S3StorageSync {

const region = process.env.STORE_REGION || DEFAULT_REGION;

this.client = new Minio.Client({
endPoint: url.hostname,
port: Number(url.port) || (url.protocol === "https:" ? 443 : 80),
useSSL: url.protocol === "https:",
accessKey,
secretKey,
partSize: 100 * 1024 * 1024,
this.client = new S3Client({
credentials: {
accessKeyId: accessKey,
secretAccessKey: secretKey,
},
endpoint: url.href,
region,
});

Expand All @@ -92,10 +97,12 @@ export class S3StorageSync {
};
logger.info("S3 file upload information", fileUploadInfo, "storage");

await this.client.fPutObject(
this.bucketName,
this.objectPrefix + targetFilename,
srcFilename,
await this.client.send(
new PutObjectCommand({
Bucket: this.bucketName,
Key: this.objectPrefix + targetFilename,
Body: fs.createReadStream(srcFilename),
}),
);

const { hash, crc32 } = await checksumFile("sha256", srcFilename);
Expand All @@ -108,11 +115,13 @@ export class S3StorageSync {
}

async downloadFile(srcFilename: string, destFilename: string) {
await this.client.fGetObject(
this.bucketName,
this.objectPrefix + srcFilename,
destFilename,
const res = await this.client.send(
new GetObjectCommand({
Bucket: this.bucketName,
Key: this.objectPrefix + srcFilename,
}),
);
await pipeline(res.Body as Readable, fs.createWriteStream(destFilename));
}

async uploadCollWACZ(
Expand Down
Loading
Loading