📝 add notes

This commit is contained in:
微凉
2021-02-04 10:02:34 +08:00
parent 3b2a729dc6
commit e146054679
26 changed files with 91 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ package controllers
import "github.com/gin-gonic/gin"
// common meta response
func MetaResponse(code int, msg string) gin.H {
return gin.H{
"meta":gin.H{
@@ -11,6 +12,7 @@ func MetaResponse(code int, msg string) gin.H {
}
}
// common data response
func DataResponse(data interface{}) gin.H {
return gin.H{
"meta":gin.H{

View File

@@ -7,8 +7,8 @@ import (
"strings"
)
// handle get request
// 因为下载地址有时效,所以去掉了文件请求和直链的缓存
func Get(c *gin.Context) {
var get alidrive.GetReq
if err := c.ShouldBindJSON(&get); err != nil {

View File

@@ -9,11 +9,13 @@ import (
log "github.com/sirupsen/logrus"
)
// list request bean
type ListReq struct {
Password string `json:"password"`
alidrive.ListReq
}
// handle list request
func List(c *gin.Context) {
var list ListReq
if err := c.ShouldBindJSON(&list);err!=nil {
@@ -65,7 +67,7 @@ func List(c *gin.Context) {
return
}
files.Paths=*paths
files.Readme=alidrive.HasReadme(files)
//files.Readme=alidrive.HasReadme(files)
if conf.Conf.Cache.Enable {
conf.Cache.Set(cacheKey,files,cache.DefaultExpiration)
}

View File

@@ -6,6 +6,7 @@ import (
log "github.com/sirupsen/logrus"
)
// handle office_preview request
func OfficePreview(c *gin.Context) {
var req alidrive.OfficePreviewUrlReq
if err := c.ShouldBindJSON(&req); err != nil {

View File

@@ -9,6 +9,7 @@ import (
log "github.com/sirupsen/logrus"
)
// handle search request
func Search(c *gin.Context) {
if !conf.Conf.Server.Search {
c.JSON(200, MetaResponse(403,"Not allow search."))

View File

@@ -5,10 +5,12 @@ import (
"github.com/gin-gonic/gin"
)
// handle info request
func Info(c *gin.Context) {
c.JSON(200, DataResponse(conf.Conf.Info))
}
// handle refresh_cache request
func RefreshCache(c *gin.Context) {
password:=c.Param("password")
if conf.Conf.Cache.Enable {

View File

@@ -7,7 +7,8 @@ import (
"github.com/gin-gonic/gin"
)
func CrosHandler() gin.HandlerFunc {
// handle cors request
func CorsHandler() gin.HandlerFunc {
return func(context *gin.Context) {
origin:=context.GetHeader("Origin")
// 同源

View File

@@ -8,17 +8,19 @@ import (
log "github.com/sirupsen/logrus"
)
// init router
func InitRouter(engine *gin.Engine) {
log.Infof("初始化路由...")
engine.Use(CrosHandler())
InitApiRouter(engine)
}
func InitApiRouter(engine *gin.Engine) {
engine.Use(CorsHandler())
engine.Use(static.Serve("/",static.LocalFile(conf.Conf.Server.Static,false)))
engine.NoRoute(func(c *gin.Context) {
c.File(conf.Conf.Server.Static+"/index.html")
})
InitApiRouter(engine)
}
// init api router
func InitApiRouter(engine *gin.Engine) {
v2:=engine.Group("/api")
{
v2.GET("/info",controllers.Info)