Serve and list older versions as well (priority is most recent version)
This commit is contained in:
parent
0a761c2ed0
commit
02db68a6f7
@ -3,6 +3,7 @@ import {NextFunction, Request, Response} from "express";
|
|||||||
import * as https from "https";
|
import * as https from "https";
|
||||||
import config from "config";
|
import config from "config";
|
||||||
import {log} from "swaf/Logger";
|
import {log} from "swaf/Logger";
|
||||||
|
import {NotFoundHttpError} from "swaf/HttpError";
|
||||||
|
|
||||||
export default class GiteaRepoLatestReleaseController extends Controller {
|
export default class GiteaRepoLatestReleaseController extends Controller {
|
||||||
public routes(): void {
|
public routes(): void {
|
||||||
@ -14,7 +15,7 @@ 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();
|
||||||
|
|
||||||
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: {
|
headers: {
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
},
|
},
|
||||||
@ -25,18 +26,25 @@ export default class GiteaRepoLatestReleaseController extends Controller {
|
|||||||
});
|
});
|
||||||
r.on('end', () => {
|
r.on('end', () => {
|
||||||
try {
|
try {
|
||||||
const assets = JSON.parse(data)[0].assets;
|
const releases = JSON.parse(data);
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
for (const asset of assets) {
|
for (const release of releases) {
|
||||||
|
for (const asset of release.assets) {
|
||||||
if (asset.name === file) {
|
if (asset.name === file) {
|
||||||
log.debug('Redirect to', asset.browser_download_url);
|
log.debug('Redirect to', asset.browser_download_url);
|
||||||
return res.redirect(302, asset.browser_download_url);
|
return res.redirect(302, asset.browser_download_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
throw new NotFoundHttpError('Asset', req.url);
|
||||||
} else {
|
} else {
|
||||||
log.debug('List files');
|
log.debug('List files');
|
||||||
return res.render('list-files', {assets: assets});
|
return res.render('list-files', {
|
||||||
|
owner: owner,
|
||||||
|
name: name,
|
||||||
|
releases: releases,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return next(e);
|
return next(e);
|
||||||
|
@ -1,5 +1,26 @@
|
|||||||
<ul>
|
<!DOCTYPE html>
|
||||||
{% for asset in assets %}
|
<html lang="en">
|
||||||
<li>#{{ asset.id }} - <a href="{{ asset.browser_download_url }}">{{ asset.name }}</a> ({{ asset.size }}, {{ asset.download_count }}, {{ asset.uuid }})</li>
|
<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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
</section>
|
||||||
|
{% endfor %}
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user