Skip to content
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
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

17 changes: 10 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"madge": "npx madge everything.ts --image deptree.svg"
},
"dependencies": {
"@bradenmacdonald/s3-lite-client": "npm:@jsr/bradenmacdonald__s3-lite-client@^0.9.4",
"ansi-colors": "^4.1.3",
"axios": "^1.13.2",
"body-parser": "^1.20.3",
Expand All @@ -46,6 +45,7 @@
"pg-query-stream": "^4.10.3",
"pm2": "^6.0.14",
"protobufjs": "^7.5.4",
"s3mini": "^0.9.1",
"steam-user-odota": "^5.2.11",
"stripe": "^9.16.0",
"vdf-parser": "^1.2.1"
Expand Down
38 changes: 13 additions & 25 deletions svc/store/archive.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import config from "../../config.ts";
import { gzipSync, gunzipSync } from "node:zlib";
import redis, { redisCount } from "./redis.ts";
import {
S3Client,
type S3UploadedObjectInfo,
type S3Errors,
} from "@bradenmacdonald/s3-lite-client";
import { S3mini } from 's3mini';

type ArchiveType = "match" | "player" | "blob";
class Archive {
private endpoint: string = "";
private accessKeyId: string = "";
private secretAccessKey: string = "";
private bucket: string = "";
private client: S3Client | null = null;
private client: S3mini | null = null;
private type: ArchiveType | null = null;
constructor(type: ArchiveType) {
this.endpoint = config.ARCHIVE_S3_ENDPOINT;
Expand All @@ -27,12 +23,11 @@ class Archive {
} else if (type === "blob") {
this.bucket = config.BLOB_ARCHIVE_S3_BUCKET;
}
this.client = new S3Client({
endPoint: this.endpoint,
this.client = new S3mini({
endpoint: this.endpoint + '/' + this.bucket,
region: "local",
bucket: this.bucket,
accessKey: this.accessKeyId,
secretKey: this.secretAccessKey,
accessKeyId: this.accessKeyId,
secretAccessKey: this.secretAccessKey,
// put the bucket name in the path rather than the domain to avoid DNS issues with minio
// forcePathStyle: true,
});
Expand Down Expand Up @@ -66,15 +61,14 @@ class Archive {
throw new Error("[ARCHIVE] s3 client not available");
}
try {
const data = await this.client.getObject(key);
buffer = Buffer.from(await data.arrayBuffer());
} catch (e: unknown) {
const error = e as S3Errors.ServerError;
if (error.statusCode === 404) {
const data = await this.client.getObjectArrayBuffer(key);
if (data == null) {
// expected response if key not valid
redisCount("archive_miss");
return null;
}
buffer = Buffer.from(data);
} catch (e: unknown) {
redisCount("archive_get_error");
throw e;
}
Expand All @@ -96,7 +90,7 @@ class Archive {
key: string,
blob: Buffer,
noCache = false,
): Promise<S3UploadedObjectInfo | null> => {
): Promise<Response> => {
if (!this.client) {
throw new Error("[ARCHIVE] s3 client not available");
}
Expand All @@ -106,21 +100,15 @@ class Archive {
);
}
const zip = gzipSync(blob);
let result;
let result: Response;
try {
// if (ifNotExists) {
// // May not be implemented by some s3 providers
// options.IfNoneMatch = '*';
// }
result = await this.client.putObject(key, zip);
} catch (e: unknown) {
const error = e as S3Errors.ServerError;
console.log(
"[ARCHIVE] put error [key: %s] (%s): %s",
key,
error.code,
error.message,
);
// const error = err as ErrorWithCode;
// if (ifNotExists && e.Code === 'PreconditionFailed') {
// // Expected error if ifNotExists was passed
// return { message: 'already exists' };
Expand Down
24 changes: 11 additions & 13 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import db, { upsertPlayer } from "../svc/store/db.ts";
import cassandra from "../svc/store/cassandra.ts";
import c from "ansi-colors";
import { suite, test, before, beforeEach, after } from "node:test";
import { S3Client } from "@bradenmacdonald/s3-lite-client";
import { averageMedal } from "../svc/util/utility.ts";
import { addReliableJob } from "../svc/store/queue.ts";
import { S3mini } from 's3mini';

const { RETRIEVER_HOST, POSTGRES_URL, CASSANDRA_URL } = config;
const initPostgresHost = POSTGRES_URL.replace("/yasp_test", "/postgres");
Expand Down Expand Up @@ -133,26 +133,24 @@ async function initCassandra() {
}

async function initMinio() {
const client = new S3Client({
endPoint: config.ARCHIVE_S3_ENDPOINT,
const client = new S3mini({
endpoint: config.ARCHIVE_S3_ENDPOINT + '/' + config.BLOB_ARCHIVE_S3_BUCKET,
region: "local",
accessKey: config.ARCHIVE_S3_KEY_ID,
secretKey: config.ARCHIVE_S3_KEY_SECRET,
bucket: config.BLOB_ARCHIVE_S3_BUCKET,
accessKeyId: config.ARCHIVE_S3_KEY_ID,
secretAccessKey: config.ARCHIVE_S3_KEY_SECRET,
});
// Make a new test bucket with a new name
// There's no good way to delete the test bucket automatically since we can't delete nonempty buckets
console.log("create minio test bucket");
await client.makeBucket(config.BLOB_ARCHIVE_S3_BUCKET);
await client.createBucket();
// Put a test blob
await client.putObject("test", "test");
// Assert we can read without exception
const result = await client.getObject("test");
assert.equal(await result.text(), "test");
// Assert it rejects when reading invalid key
assert.rejects(async () => {
await client.getObject("invalid");
});
let result = await client.getObjectArrayBuffer("test");
assert.equal(Buffer.from(result!).toString(), "test");
// Assert it's null when reading invalid key
result = await client.getObjectArrayBuffer("invalid");
assert.equal(result, null);
}

async function startServices() {
Expand Down