Skip to content

Commit

Permalink
Support new board API
Browse files Browse the repository at this point in the history
  • Loading branch information
NeKzor committed May 15, 2024
1 parent 0b8e415 commit eec44b3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docker/compose/autorender.portal2.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ services:
restart: always
links:
- database:autorender.database
networks:
- default
- board-net
external_links:
- board-net
volumes:
- ./docker/volumes/logs/server:/logs/server:rw
- ./docker/volumes/storage:/storage:rw
Expand Down Expand Up @@ -47,6 +52,7 @@ services:
volumes:
- ./docker/volumes/initdb:/docker-entrypoint-initdb.d
- ./docker/volumes/mysql:/var/lib/mysql
- ./docker/volumes/backups:/backups
proxy:
image: nginx:stable-alpine3.17
container_name: "${PROJECT_NAME}-proxy"
Expand All @@ -61,3 +67,6 @@ services:
- ./docker/volumes/ssl:/ssl:r
- ./docker/volumes/nginx:/etc/nginx/templates
- ./docker/volumes/logs/nginx:/var/log/nginx:rw
networks:
board-net:
external: true
3 changes: 3 additions & 0 deletions src/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ AUTORENDER_RUN_DEMO_REPAIR=true
AUTORENDER_RUN_SKIP_COOP_VIDEOS_CHECK=true
COOKIE_SECRET_KEY=""

MEL_BOARD_DOMAIN=board-server
MEL_BOARD_API_TOKEN=""

B2_ENABLED=false
B2_BUCKET_ID=none
B2_KEY_ID=none
Expand Down
4 changes: 2 additions & 2 deletions src/server/deno.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"tasks": {
"dev": "deno task dev:stale & deno task dev:processing & deno run --import-map=../import_map.json --no-prompt --allow-env --allow-read=.env,.env.defaults,.env.example,app/assets,/logs/server,/storage --allow-write=/logs/server,/storage --allow-run=ffprobe --allow-net --watch main.ts",
"dev": "deno task dev:stale & deno task dev:processing & deno run --import-map=../import_map.json --no-prompt --allow-env --allow-read=.env,.env.defaults,.env.example,app/assets,/logs/server,/storage --allow-write=/logs/server,/storage --allow-run=ffprobe --allow-net --unsafely-ignore-certificate-errors=board-server --watch main.ts",
"prod": "deno task stale & deno task board & deno task processing & deno run --import-map=../import_map.json --no-prompt --allow-env --allow-read=.env,.env.defaults,.env.example,app/assets,/logs/server,/storage --allow-write=/logs/server,/storage --allow-run=ffprobe --allow-net main.ts",
"test": "deno test --import-map=../import_map.json --allow-net --allow-read --allow-env --unsafely-ignore-certificate-errors=autorender.portal2.local",
"test": "deno test --import-map=../import_map.json --allow-net --allow-read --allow-env --unsafely-ignore-certificate-errors=autorender.portal2.local,board-server",
"perm": "deno run --import-map=../import_map.json --no-prompt --allow-env --allow-read=.env,.env.defaults,.env.example --allow-net=autorender.database:3307 tasks/perm.ts",
"migrate": "deno run --import-map=../import_map.json --no-prompt --allow-env --allow-read=.env,.env.defaults,.env.example,/logs/server/migrate_info.log,/logs/server/migrate_error.log,/storage --allow-write=/logs/server/migrate_info.log,/logs/server/migrate_error.log --allow-write=/logs/server/migrate_info.log,/logs/server/migrate_error.log,/storage --allow-net=autorender.database:3307,autorender.portal2.sr,board.portal2.sr,mel.board.portal2.sr tasks/migrate.ts",
"stale": "deno run --import-map=../import_map.json --no-prompt --allow-env --allow-read=.env,.env.defaults,.env.example,/logs/server/stale_info.log,/logs/server/stale_error.log --allow-write=/logs/server/stale_info.log,/logs/server/stale_error.log --allow-net=autorender.database:3307 tasks/stale.ts",
Expand Down
1 change: 1 addition & 0 deletions src/server/deno.lock

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

36 changes: 35 additions & 1 deletion src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ const AUTORENDER_BOT_TOKEN_HASH = await bcrypt.hash(
const AUTORENDER_MAX_DEMO_FILE_SIZE = Number(Deno.env.get('AUTORENDER_MAX_DEMO_FILE_SIZE')) * 1_000_000;
const AUTORENDER_MAX_VIDEO_FILE_SIZE = Number(Deno.env.get('AUTORENDER_MAX_VIDEO_FILE_SIZE')) * 1_000_000;
const DISCORD_BOARD_INTEGRATION_WEBHOOK_URL = Deno.env.get('DISCORD_BOARD_INTEGRATION_WEBHOOK_URL')!;
const MEL_BOARD_DOMAIN = Deno.env.get('MEL_BOARD_DOMAIN')!;
const MEL_BOARD_API_TOKEN = Deno.env.get('MEL_BOARD_API_TOKEN')!;
const B2_ENABLED = Deno.env.get('B2_ENABLED')!.toLowerCase() === 'true';
const B2_BUCKET_ID = Deno.env.get('B2_BUCKET_ID')!;
const BOARD_INTEGRATION_START_DATE = '2023-08-25';
Expand Down Expand Up @@ -623,6 +625,38 @@ apiV1
return;
}

try {
if (video.board_changelog_id && video.board_source === BoardSource.Mel && MEL_BOARD_API_TOKEN) {
logger.info(`Sending autorender to ${MEL_BOARD_DOMAIN}`, video.share_id);

const res = await fetch(`https://${MEL_BOARD_DOMAIN}/api-v3/set-autorender`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${MEL_BOARD_API_TOKEN}`,
'Content-Type': 'application/json',
'User-Agent': Deno.env.get('USER_AGENT')!,
},
body: JSON.stringify({
changelog_id: video.board_changelog_id,
autorender_id: video.share_id,
}),
});

logger.info(`Sent autorender to ${MEL_BOARD_DOMAIN} for`, video.video_id, ':', res.statusText);

if (!res.ok) {
logger.error(
`Failed to send autorender to ${MEL_BOARD_DOMAIN} for video`,
video.video_id,
':',
await res.text(),
);
}
}
} catch (err) {
logger.error(err);
}

try {
if (video.board_changelog_id !== null) {
if (video.board_rank === 1) {
Expand Down Expand Up @@ -995,7 +1029,7 @@ apiV1
})
// Get the video of a leaderboard run.
.get('/video/:boardChangelogId(\\d+)/video', async (ctx) => {
const source = Number(ctx.request.url.searchParams.get('source')) ?? BoardSource.Portal2;
const source = Number(ctx.request.url.searchParams.get('source') ?? BoardSource.Portal2);
if (isNaN(source) || ![BoardSource.Portal2, BoardSource.Mel].includes(source)) {
return Err(ctx, Status.BadRequest, 'Bad value for source parameter.');
}
Expand Down
35 changes: 35 additions & 0 deletions src/server/tests/mel_board_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2023-2024, NeKz
*
* SPDX-License-Identifier: MIT
*/

import { assert } from 'testing/asserts.ts';

const MEL_BOARD_DOMAIN = Deno.env.get('MEL_BOARD_DOMAIN')!;
const MEL_BOARD_API_TOKEN = Deno.env.get('MEL_BOARD_API_TOKEN')!;

Deno.test('Can set autorender on board.portal2.local', async () => {
if (!MEL_BOARD_API_TOKEN) {
return console.log('Mel board disabled. Skipped test.');
}

const res = await fetch(`https://${MEL_BOARD_DOMAIN}/api-v3/set-autorender`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${MEL_BOARD_API_TOKEN}`,
'Content-Type': 'application/json',
'User-Agent': Deno.env.get('USER_AGENT')!,
},
body: JSON.stringify({
changelog_id: -1,
autorender_id: '0123456789A',
}),
});

assert(res.ok);

const status = await res.json();
assert(status);
assert(status.affected === 0);
});

0 comments on commit eec44b3

Please sign in to comment.