Skip to content

Commit 1a4da6e

Browse files
authored
chore: use local minio when possible (#76)
1 parent 8b81360 commit 1a4da6e

5 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/configs/s3.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export default (): {
88
secret: process.env.S3_SECRET,
99
bucket: process.env.S3_BUCKET,
1010
db_backup_bucket: process.env.S3_DB_BACKUP_BUCKET || "5stack-db-backups",
11-
endpoint: process.env.S3_ENDPOINT || process.env.DEMOS_DOMAIN,
12-
useSSL: process.env.S3_USE_SSL === "false" ? false : true,
13-
port: process.env.S3_PORT || "443",
11+
endpoint: process.env.S3_ENDPOINT || "minio",
12+
useSSL: process.env.S3_USE_SSL === "true" ? true : false,
13+
port: process.env.S3_PORT || "9000",
1414
},
1515
});

src/dedicated-servers/dedicated-servers.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export class DedicatedServersService {
299299
type: "DirectoryOrCreate",
300300
path: `/opt/5stack/servers/${server.id}`,
301301
},
302-
}
302+
},
303303
],
304304
},
305305
},

src/demos/demos.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class DemosController {
8686
) {
8787
const { matchId } = request.params;
8888
const { mapId, demo } = request.body;
89+
const isGameServerNode = request.query["game-server-node"] === "true";
8990

9091
if (!matchId || !mapId || !demo) {
9192
return response.status(400).json({
@@ -156,6 +157,10 @@ export class DemosController {
156157

157158
const presignedUrl = await this.s3.getPresignedUrl(
158159
`${matchId}/${mapId}/demos/${demo}`,
160+
undefined,
161+
undefined,
162+
undefined,
163+
isGameServerNode,
159164
);
160165

161166
return response.status(200).json({

src/s3/s3.controller.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ export class S3Controller {
1919
try {
2020
const data = `world : ${new Date().toISOString()}`;
2121
const putResponse = await fetch(
22-
await this.s3.getPresignedUrl("hello.txt"),
22+
await this.s3.getPresignedUrl(
23+
"hello.txt",
24+
undefined,
25+
undefined,
26+
undefined,
27+
true,
28+
),
2329
{
2430
method: "PUT",
2531
body: Buffer.from(data),
@@ -49,10 +55,6 @@ export class S3Controller {
4955
@HasuraAction()
5056
public async getTestUploadLink() {
5157
try {
52-
const data = await fetch(
53-
await this.s3.getPresignedUrl("hello.txt", undefined, 60, "get"),
54-
);
55-
5658
return {
5759
link: await this.s3.getPresignedUrl("hello.txt", undefined, 60, "get"),
5860
};

src/s3/s3.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,13 @@ export class S3Service {
116116
}
117117
}
118118

119-
public getClientEndpoint() {
120-
return `${this.config.endpoint}:${this.config.port}`;
121-
}
122-
123119
public async getPresignedUrl(
124120
key: string,
125121
bucket: string = this.bucket,
126122
// 5 minutes
127123
expires = 60 * 5,
128124
type: "put" | "get" = "put",
125+
useLocal: boolean = false,
129126
) {
130127
let presignedUrl: string;
131128

@@ -135,6 +132,13 @@ export class S3Service {
135132
presignedUrl = await this.client.presignedGetObject(bucket, key, expires);
136133
}
137134

135+
if (!useLocal && this.config.endpoint === "minio") {
136+
presignedUrl = presignedUrl.replace(
137+
`http://minio:9000`,
138+
`https://${process.env.DEMOS_DOMAIN}`,
139+
);
140+
}
141+
138142
return presignedUrl;
139143
}
140144
}

0 commit comments

Comments
 (0)