From 0c00ef85b9215af608f3744cb2a789e7417212f0 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Sat, 6 Mar 2021 18:38:29 +0100 Subject: [PATCH] Add global user redirections --- config/default.json5 | 3 +++ config/production.json5 | 1 + src/controllers/GiteaRepoLatestReleaseController.ts | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/config/default.json5 b/config/default.json5 index 206a77b..2792068 100644 --- a/config/default.json5 +++ b/config/default.json5 @@ -12,4 +12,7 @@ cache: false, }, assets_base_dir: 'downloads', + user_redirections: [ + {from: 'arisu', to: 'ashpie'} + ], } diff --git a/config/production.json5 b/config/production.json5 index 68dad4d..0dc0cb0 100644 --- a/config/production.json5 +++ b/config/production.json5 @@ -2,4 +2,5 @@ log_level: "DEBUG", db_log_level: "ERROR", public_url: "https://update.eternae.ink", + user_redirections: [], } diff --git a/src/controllers/GiteaRepoLatestReleaseController.ts b/src/controllers/GiteaRepoLatestReleaseController.ts index e52ee25..3e0507e 100644 --- a/src/controllers/GiteaRepoLatestReleaseController.ts +++ b/src/controllers/GiteaRepoLatestReleaseController.ts @@ -9,6 +9,7 @@ import path from "path"; import sendRanges, {SendRangeGetStreamFn} from "send-ranges"; import mime from "mime"; import {logger} from "swaf/Logger"; +import {ParsedUrlQueryInput} from "querystring"; export const ASSETS_BASE_DIR = config.get('assets_base_dir'); @@ -22,6 +23,14 @@ export default class GiteaRepoLatestReleaseController extends Controller { const {owner, name, file} = req.params; if (!owner || !name) return next(); + // User redirections + const userRedirections = config.get<{ from: string, to: string }[]>('user_redirections'); + for (const redirection of userRedirections) { + if (owner === redirection.from) { + return res.redirect(Controller.route('get-repo-release-file', [redirection.to, name, file], req.query as ParsedUrlQueryInput)); + } + } + const httpRequest = https.get(`${config.get('gitea_instance_url')}/api/v1/repos/${owner}/${name}/releases`, { headers: { 'Accept': 'application/json',