@@ -8,7 +8,7 @@ import cors from '@koa/cors'
88import bodyParser from 'koa-bodyparser'
99
1010import { HTTPServerConfig , LoggerInstance , stringifyError , first } from '@sofie-package-manager/api'
11- import { BadResponse , Storage , isBadResponse } from './storage/storage'
11+ import { BadResponse , PackageInfo , Storage , isBadResponse } from './storage/storage'
1212import { FileStorage } from './storage/fileStorage'
1313import { CTX , PACKAGE_JSON_VERSION , valueOrFirst } from './lib'
1414import { parseFormData } from 'pechkin'
@@ -90,6 +90,9 @@ export class PackageProxyServer {
9090 this . router . get ( '/packages' , async ( ctx ) => {
9191 await this . handleStorage ( ctx , async ( ) => this . storage . listPackages ( ctx ) )
9292 } )
93+ this . router . get ( '/list' , async ( ctx ) => {
94+ await this . handleStorageHTMLList ( ctx , async ( ) => this . storage . listPackages ( ctx ) )
95+ } )
9396 this . router . get ( '/package/:path+' , async ( ctx ) => {
9497 await this . handleStorage ( ctx , async ( ) => this . storage . getPackage ( ctx . params . path , ctx ) )
9598 } )
@@ -175,4 +178,50 @@ export class PackageProxyServer {
175178 ctx . body = 'Internal server error'
176179 }
177180 }
181+ private async handleStorageHTMLList (
182+ ctx : CTX ,
183+ storageFcn : ( ) => Promise < { packages : PackageInfo [ ] } | BadResponse >
184+ ) {
185+ try {
186+ const result = await storageFcn ( )
187+ if ( isBadResponse ( result ) ) {
188+ ctx . response . status = result . code
189+ ctx . body = result . reason
190+ } else {
191+ const packages = result . packages
192+
193+ ctx . set ( 'Content-Type' , 'text/html' )
194+ ctx . body = `<!DOCTYPE html>
195+ <html>
196+ <head>
197+ <style>
198+ body { font-family: Arial, sans-serif; }
199+ table { border-collapse: collapse; width: 100%; }
200+ th, td { border: 1px solid #ddd; padding: 8px; }
201+
202+ </style>
203+ </head>
204+ <body>
205+ <h1>Packages</h1>
206+ <table>
207+ ${ packages
208+ . map (
209+ ( pkg ) =>
210+ `<tr>
211+ <td><a href="/package/${ pkg . path } ">${ pkg . path } </a></td>
212+ <td>${ pkg . size } </td>
213+ <td>${ pkg . modified } </td>
214+ </tr>`
215+ )
216+ . join ( '' ) }
217+ </table>
218+ </body>
219+ </html>`
220+ }
221+ } catch ( err ) {
222+ this . logger . error ( `Error in handleStorage: ${ stringifyError ( err ) } ` )
223+ ctx . response . status = 500
224+ ctx . body = 'Internal server error'
225+ }
226+ }
178227}
0 commit comments