Add global user redirections

This commit is contained in:
Alice Gaudon 2021-03-06 18:38:29 +01:00
parent 827d3c3f65
commit 0c00ef85b9
3 changed files with 13 additions and 0 deletions

View File

@ -12,4 +12,7 @@
cache: false, cache: false,
}, },
assets_base_dir: 'downloads', assets_base_dir: 'downloads',
user_redirections: [
{from: 'arisu', to: 'ashpie'}
],
} }

View File

@ -2,4 +2,5 @@
log_level: "DEBUG", log_level: "DEBUG",
db_log_level: "ERROR", db_log_level: "ERROR",
public_url: "https://update.eternae.ink", public_url: "https://update.eternae.ink",
user_redirections: [],
} }

View File

@ -9,6 +9,7 @@ import path from "path";
import sendRanges, {SendRangeGetStreamFn} from "send-ranges"; import sendRanges, {SendRangeGetStreamFn} from "send-ranges";
import mime from "mime"; import mime from "mime";
import {logger} from "swaf/Logger"; import {logger} from "swaf/Logger";
import {ParsedUrlQueryInput} from "querystring";
export const ASSETS_BASE_DIR = config.get<string>('assets_base_dir'); export const ASSETS_BASE_DIR = config.get<string>('assets_base_dir');
@ -22,6 +23,14 @@ export default class GiteaRepoLatestReleaseController extends Controller {
const {owner, name, file} = req.params; const {owner, name, file} = req.params;
if (!owner || !name) return next(); 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`, { const httpRequest = https.get(`${config.get('gitea_instance_url')}/api/v1/repos/${owner}/${name}/releases`, {
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',