From 760c165be04c8e1f344bed8d0711c68cfc0f1796 Mon Sep 17 00:00:00 2001 From: cdle Date: Sun, 11 Jun 2023 15:15:38 +0800 Subject: [PATCH] x --- core/common/function.go | 7 ++++--- core/plugin_subscribe.go | 3 +++ core/web.go | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/common/function.go b/core/common/function.go index b1b9a85..7ee1dc6 100644 --- a/core/common/function.go +++ b/core/common/function.go @@ -32,9 +32,10 @@ type Function struct { Encrypt bool `json:"encrypt"` OnStart bool `json:"on_start"` PluginPublisher - Running bool `json:"-"` - Http *Http `json:"-"` - Reply *Reply `json:"-"` + Running bool `json:"-"` + Http *Http `json:"-"` + Reply *Reply `json:"-"` + Downloads int `json:"downloads"` } type Filter struct { BlackMode bool diff --git a/core/plugin_subscribe.go b/core/plugin_subscribe.go index f0bea30..213b218 100644 --- a/core/plugin_subscribe.go +++ b/core/plugin_subscribe.go @@ -105,6 +105,8 @@ func initPluginList() { // } } +var plugin_downloads = MakeBucket("plugin_downloads") + func initWebPluginList() { storage.Watch(sillyGirl, "plugin_subcribe_addresses", func(old, new, key string) *storage.Final { plugin_subcribe_addresses = new @@ -187,6 +189,7 @@ func GetPublicResponse() *RequestPluginResult { for _, f := range Functions { if f.Public { fs = append(fs, f) + f.Downloads = plugin_downloads.GetInt(f.UUID) } } rr.Total = len(fs) diff --git a/core/web.go b/core/web.go index dd12ce3..8fcea14 100644 --- a/core/web.go +++ b/core/web.go @@ -66,10 +66,12 @@ func init() { Server.Use(gzip.Gzip(gzip.DefaultCompression)) Server.GET("/api/file/:filename", FindFile) Server.GET("/api/decode/:random", Base642Binary) + Server.GET("/api/plugins/download", func(c *gin.Context) { uuid := c.Query("uuid") for _, f := range Functions { if f.UUID == uuid && f.Public { + plugin_downloads.Set(f.UUID, plugin_downloads.GetInt(f.UUID)+1) c.String(200, publicScript(plugins.GetString(f.UUID))) return } @@ -79,6 +81,7 @@ func init() { uuid := c.Param("uuid") for _, f := range Functions { if f.UUID == uuid && f.Public { + plugin_downloads.Set(f.UUID, plugin_downloads.GetInt(f.UUID)+1) c.String(200, publicScript(plugins.GetString(f.UUID))) return }