Merge branch 'develop'
This commit is contained in:
commit
8fc6010214
@ -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>",
|
||||
|
@ -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) {
|
||||
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);
|
||||
|
@ -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>
|
||||
<!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>
|
||||
</ul>
|
||||
</section>
|
||||
{% endfor %}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user