aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2023-08-08 02:46:10 +0200
committerGitHub <noreply@github.com>2023-08-08 00:46:10 +0000
commit0c6ae61229bce9d9ad3d359cee927464968a2dd1 (patch)
treee7322e6b8ad0a34868e8d9cae445ffc24a3ca191 /routers
parentc2b6897e35ccdebc4b49cfc7fb165ee654c8e55d (diff)
downloadgitea-0c6ae61229bce9d9ad3d359cee927464968a2dd1.tar.gz
gitea-0c6ae61229bce9d9ad3d359cee927464968a2dd1.zip
Allow package cleanup from admin page (#25307)
Until now expired package data gets deleted daily by a cronjob. The admin page shows the size of all packages and the size of unreferenced data. The users (#25035, #20631) expect the deletion of this data if they run the cronjob from the admin page but the job only deletes data older than 24h. This PR adds a new button which deletes all expired data. ![grafik](https://github.com/go-gitea/gitea/assets/1666336/b3e35d73-9496-4fa7-a20c-e5d30b1f6850) --------- Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/admin/packages.go12
-rw-r--r--routers/web/web.go1
2 files changed, 13 insertions, 0 deletions
diff --git a/routers/web/admin/packages.go b/routers/web/admin/packages.go
index 8e4b8a373e..8d4c29813e 100644
--- a/routers/web/admin/packages.go
+++ b/routers/web/admin/packages.go
@@ -6,6 +6,7 @@ package admin
import (
"net/http"
"net/url"
+ "time"
"code.gitea.io/gitea/models/db"
packages_model "code.gitea.io/gitea/models/packages"
@@ -14,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
packages_service "code.gitea.io/gitea/services/packages"
+ packages_cleanup_service "code.gitea.io/gitea/services/packages/cleanup"
)
const (
@@ -99,3 +101,13 @@ func DeletePackageVersion(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("packages.settings.delete.success"))
ctx.JSONRedirect(setting.AppSubURL + "/admin/packages?page=" + url.QueryEscape(ctx.FormString("page")) + "&q=" + url.QueryEscape(ctx.FormString("q")) + "&type=" + url.QueryEscape(ctx.FormString("type")))
}
+
+func CleanupExpiredData(ctx *context.Context) {
+ if err := packages_cleanup_service.CleanupExpiredData(ctx, time.Duration(0)); err != nil {
+ ctx.ServerError("CleanupExpiredData", err)
+ return
+ }
+
+ ctx.Flash.Success(ctx.Tr("packages.cleanup.success"))
+ ctx.Redirect(setting.AppSubURL + "/admin/packages")
+}
diff --git a/routers/web/web.go b/routers/web/web.go
index aa3d830f94..2c2309e827 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -597,6 +597,7 @@ func registerRoutes(m *web.Route) {
m.Group("/packages", func() {
m.Get("", admin.Packages)
m.Post("/delete", admin.DeletePackageVersion)
+ m.Post("/cleanup", admin.CleanupExpiredData)
}, packagesEnabled)
m.Group("/hooks", func() {