Merge branch 'develop'

This commit is contained in:
Alice Gaudon 2020-11-17 13:35:48 +01:00
commit 8fc6010214
3 changed files with 42 additions and 13 deletions

View File

@ -1,6 +1,6 @@
{
"name": "eternae.ink.update",
"version": "1.0.2",
"version": "1.1.0",
"description": "A simple redirection to serve a gitea instance's repositories' latest release files as an http file server. (302 redirections)",
"repository": "https://eternae.ink/arisu/update.eternae.ink",
"author": "Alice Gaudon <alice@gaudon.pro>",

View File

@ -3,6 +3,7 @@ import {NextFunction, Request, Response} from "express";
import * as https from "https";
import config from "config";
import {log} from "swaf/Logger";
import {NotFoundHttpError} from "swaf/HttpError";
export default class GiteaRepoLatestReleaseController extends Controller {
public routes(): void {
@ -14,7 +15,7 @@ export default class GiteaRepoLatestReleaseController extends Controller {
const {owner, name, file} = req.params;
if (!owner || !name) return next();
https.get(`${config.get('gitea_instance_url')}/api/v1/repos/${owner}/${name}/releases?limit=1`, {
https.get(`${config.get('gitea_instance_url')}/api/v1/repos/${owner}/${name}/releases`, {
headers: {
'Accept': 'application/json',
},
@ -25,18 +26,25 @@ export default class GiteaRepoLatestReleaseController extends Controller {
});
r.on('end', () => {
try {
const assets = JSON.parse(data)[0].assets;
const releases = JSON.parse(data);
if (file) {
for (const asset of assets) {
if (asset.name === file) {
log.debug('Redirect to', asset.browser_download_url);
return res.redirect(302, asset.browser_download_url);
for (const release of releases) {
for (const asset of release.assets) {
if (asset.name === file) {
log.debug('Redirect to', asset.browser_download_url);
return res.redirect(302, asset.browser_download_url);
}
}
}
throw new NotFoundHttpError('Asset', req.url);
} else {
log.debug('List files');
return res.render('list-files', {assets: assets});
return res.render('list-files', {
owner: owner,
name: name,
releases: releases,
});
}
} catch (e) {
return next(e);

View File

@ -1,5 +1,26 @@
<ul>
{% for asset in assets %}
<li>#{{ asset.id }} - <a href="{{ asset.browser_download_url }}">{{ asset.name }}</a> ({{ asset.size }}, {{ asset.download_count }}, {{ asset.uuid }})</li>
{% endfor %}
</ul>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ owner }}/{{ name }} - releases</title>
</head>
<body>
<main>
<h1>{{ owner }}/{{ name }} - releases</h1>
{% for release in releases %}
<section>
<h2>{{ release.name }}</h2>
<ul>
{% for asset in release.assets %}
<li>#{{ asset.id }} - <a href="{{ asset.browser_download_url }}">{{ asset.name }}</a>
({{ asset.size }}, {{ asset.download_count }}, {{ asset.uuid }})
</li>
{% endfor %}
</ul>
</section>
{% endfor %}
</main>
</body>
</html>