diff --git a/package.json b/package.json index a6f6159..92f07ff 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/controllers/GiteaRepoLatestReleaseController.ts b/src/controllers/GiteaRepoLatestReleaseController.ts index d284677..62dabb6 100644 --- a/src/controllers/GiteaRepoLatestReleaseController.ts +++ b/src/controllers/GiteaRepoLatestReleaseController.ts @@ -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); diff --git a/views/list-files.njk b/views/list-files.njk index d1ab4b0..9f8a98c 100644 --- a/views/list-files.njk +++ b/views/list-files.njk @@ -1,5 +1,26 @@ - + + + + + {{ owner }}/{{ name }} - releases + + + +
+

{{ owner }}/{{ name }} - releases

+ + {% for release in releases %} +
+

{{ release.name }}

+
    + {% for asset in release.assets %} +
  • #{{ asset.id }} - {{ asset.name }} + ({{ asset.size }}, {{ asset.download_count }}, {{ asset.uuid }}) +
  • + {% endfor %} +
+
+ {% endfor %} +
+ +