Skip to content

Commit 9a0c738

Browse files
committed
feature: cloudflare worker to download demos
1 parent 5079c0d commit 9a0c738

4 files changed

Lines changed: 40 additions & 3 deletions

File tree

hasura/functions/match/maps/match_map_demo_download_url.sql

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,26 @@ RETURNS text
33
LANGUAGE plpgsql STABLE
44
AS $$
55
DECLARE
6-
download_url text;
6+
worker_url text;
7+
filenames text[];
8+
demos_domain text;
79
BEGIN
8-
download_url := CONCAT('demos/', match_map.match_id, '/map/', match_map.id);
9-
RETURN download_url;
10+
SELECT value INTO worker_url
11+
FROM settings
12+
WHERE name = 'cloudflare_worker_url';
13+
14+
IF worker_url IS NOT NULL THEN
15+
SELECT array_agg(file) INTO filenames
16+
FROM match_map_demos
17+
WHERE match_map_id = match_map.id;
18+
19+
RETURN CONCAT(worker_url, '/demos?matchId=', match_map.match_id, '&mapId=', match_map.id, '&files=', array_to_string(filenames, ','));
20+
END IF;
21+
22+
SELECT value INTO demos_domain
23+
FROM settings
24+
WHERE name = 'demos_domain';
25+
26+
RETURN CONCAT(demos_domain, '/demos/', match_map.match_id, '/map/', match_map.id);
1027
END;
1128
$$;

src/game-server-node/jobs/MarkGameServerNodeOffline.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export class MarkGameServerNodeOffline extends WorkerHost {
3333
},
3434
});
3535

36+
if (process.env.DEV) {
37+
return;
38+
}
39+
3640
this.notifications.send("GameNodeStatus", {
3741
message: `Game Server Node (${update_game_server_nodes_by_pk.label || job.data.node}) is Offline.`,
3842
title: "Game Server Node Offline",

src/game-server-node/jobs/MarkGameServerOffline.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export class MarkGameServerOffline extends WorkerHost {
3838
return;
3939
}
4040

41+
if (process.env.DEV) {
42+
return;
43+
}
44+
4145
this.notifications.send("DedicatedServerStatus", {
4246
message: `Dedicated Server (${update_servers_by_pk.label || job.data.serverId}) is Offline.`,
4347
title: "Dedicated Server Offline",

src/hasura/hasura.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ import fs from "fs";
1515
import path from "path";
1616
import crypto from "crypto";
1717
import { PostgresService } from "../postgres/postgres.service";
18+
import { AppConfig } from "../configs/types/AppConfig";
1819

1920
@Injectable()
2021
export class HasuraService {
2122
private config: HasuraConfig;
23+
private appConfig: AppConfig;
2224

2325
constructor(
2426
protected readonly logger: Logger,
2527
protected readonly cache: CacheService,
2628
protected readonly configService: ConfigService,
2729
protected readonly postgresService: PostgresService,
2830
) {
31+
this.appConfig = configService.get<AppConfig>("app");
2932
this.config = configService.get<HasuraConfig>("hasura");
3033
}
3134

@@ -108,6 +111,15 @@ export class HasuraService {
108111
await this.apply(path.resolve("./hasura/functions"));
109112
await this.apply(path.resolve("./hasura/views"));
110113
await this.apply(path.resolve("./hasura/triggers"));
114+
115+
await this.updateSettings();
116+
}
117+
118+
private async updateSettings() {
119+
await this.postgresService.query(
120+
"insert into settings (name, value) values ('demos_domain', $1) on conflict (name) do update set value = $1",
121+
[this.appConfig.demosDomain],
122+
);
111123
}
112124

113125
private async applyMigrations(path: string): Promise<number> {

0 commit comments

Comments
 (0)