This commit is contained in:
cdle
2021-09-27 09:51:18 +08:00
parent 70d98c4566
commit 13d58917a5
2 changed files with 85 additions and 2 deletions
+41 -2
View File
@@ -1,13 +1,52 @@
package dwz
import (
"fmt"
"net/http"
"github.com/cdle/sillyGirl/core"
"github.com/gin-gonic/gin"
)
var dwz = core.NewBucket("dwz")
func init() {
core.Server.GET("/dwz", func(c *gin.Context) {
addr := c.Param("addr")
c.String(200, addr)
url := c.Query("url")
dwz := getDwz(url)
c.String(200, dwz)
})
core.Server.GET("/d:id", func(c *gin.Context) {
id := c.Param("id")
c.Redirect(http.StatusMovedPermanently, getWz(id))
})
core.AddCommand("", []core.Function{
{
Rules: []string{"dwz ?"},
Handle: func(s core.Sender) interface{} {
return getDwz(s.Get())
},
},
})
}
type ShortUrl struct {
ID int
Url string
}
func getDwz(url string) string {
su := &ShortUrl{
Url: url,
}
dwz.Create(su)
return dwz.Get("address", "https://4co.cc"+"/d"+fmt.Sprint(su.ID))
}
func getWz(id string) string {
su := &ShortUrl{
ID: core.Int(id),
}
dwz.First(su)
return fmt.Sprint(su.Url)
}