diff --git a/server/ctrl/plugin.go b/server/ctrl/plugin.go index 7b275eb6..0bc595e7 100644 --- a/server/ctrl/plugin.go +++ b/server/ctrl/plugin.go @@ -77,3 +77,16 @@ func PluginStaticHandler(ctx *App, res http.ResponseWriter, req *http.Request) { SendErrorResult(res, err) return } + +func PluginDownloadHandler(ctx *App, res http.ResponseWriter, req *http.Request) { + f, err := os.Open(JoinPath( + GetAbsolutePath(PLUGIN_PATH), + mux.Vars(req)["name"]+".zip", + )) + if err != nil { + SendErrorResult(res, err) + return + } + io.Copy(res, f) + f.Close() +} diff --git a/server/routes.go b/server/routes.go index 25552f5a..d4dee85b 100644 --- a/server/routes.go +++ b/server/routes.go @@ -100,6 +100,7 @@ func Build(r *mux.Router, a App) { r.HandleFunc(WithBase("/sw.js"), http.HandlerFunc(NewMiddlewareChain(ServeFile("/assets/"), middlewares, a))).Methods("GET") r.HandleFunc(WithBase("/favicon.ico"), NewMiddlewareChain(ServeFavicon, middlewares, a)).Methods("GET") r.HandleFunc(WithBase("/plugin/{name}/{path:.+}"), NewMiddlewareChain(PluginStaticHandler, middlewares, a)).Methods("GET") + r.HandleFunc(WithBase("/plugin/{name}.zip"), NewMiddlewareChain(PluginDownloadHandler, middlewares, a)).Methods("GET") } // Other endpoints