@@ -212,27 +212,36 @@ func start(_ *cobra.Command, _ []string) {
212212
213213 uiGroup := rootGroup .Group ("/ui" )
214214 uiGroup .Any ("" , nil , addTrailingSlashMiddleware )
215+ uiCache := make (map [string ]string )
215216 uiGroup .GET ("/*" , func (c echo.Context ) error {
216217 prefix := filepath .Join ("/" + strings .TrimPrefix (cfg .BaseURI , "/" ), "/ui/" )
217218 filePath := strings .TrimPrefix (strings .TrimPrefix (c .Request ().URL .Path , prefix ), "/" )
218- file , err := ui .MainFS .Open (filePath )
219- if err != nil {
220- filePath = "index.html"
221- file , _ = ui .MainFS .Open (filePath )
222- }
223- defer file .Close ()
224- buf := new (bytes.Buffer )
225- _ , err = io .Copy (buf , file )
226- if err != nil {
227- return err
228- }
229- newURI , err := neturl .JoinPath ("/BASE_URI/" , "../" + cfg .BaseURI + "/" )
230- if err != nil {
231- return err
219+ modifiedContent , ok := uiCache [filePath ]
220+ if ! ok {
221+ file , err := ui .MainFS .Open (filePath )
222+ if err != nil {
223+ filePath = "index.html"
224+ file , _ = ui .MainFS .Open (filePath )
225+ }
226+ defer file .Close ()
227+ buf := new (bytes.Buffer )
228+ _ , err = io .Copy (buf , file )
229+ if err != nil {
230+ return err
231+ }
232+ newURI , err := neturl .JoinPath ("/BASE_URI/" , "../" + cfg .BaseURI + "/" )
233+ if err != nil {
234+ return err
235+ }
236+ modifiedContent = strings .ReplaceAll (buf .String (), "/BASE_URI/" , newURI )
237+ uiCache [filePath ] = modifiedContent
232238 }
233- modifiedContent := strings .ReplaceAll (buf .String (), "/BASE_URI/" , newURI )
234239 fileParts := strings .Split (filePath , "." )
235- return c .Blob (200 , mime .TypeByExtension ("." + fileParts [len (fileParts )- 1 ]), []byte (modifiedContent ))
240+ mimeType := mime .TypeByExtension ("." + fileParts [len (fileParts )- 1 ])
241+ if mimeType == "" {
242+ mimeType = "text/html; charset=utf-8"
243+ }
244+ return c .Blob (200 , mimeType , []byte (modifiedContent ))
236245 })
237246
238247 if configuration .CurrentConfig .RunServer {
@@ -243,7 +252,6 @@ func start(_ *cobra.Command, _ []string) {
243252 )
244253 }
245254
246- commandGroup := apiGroup .Group ("/command" , checkUserAdmin )
247- commandGroup .DELETE ("/remove-old-links" , url .RemoveOldIds )
248-
255+ commandGroup := apiGroup .Group ("/command" )
256+ commandGroup .DELETE ("/remove-old-links" , url .RemoveUnusedUrls )
249257}
0 commit comments