Skip to content

Commit

Permalink
➖ 去除缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Mar 7, 2021
1 parent 443067b commit b677d6a
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 351 deletions.
16 changes: 0 additions & 16 deletions bootstrap/cache.go

This file was deleted.

1 change: 0 additions & 1 deletion bootstrap/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func start() {
log.Errorf("初始化数据库出现错误,启动失败.")
return
}
InitCache()
InitCron()
server()
}
Expand Down
6 changes: 0 additions & 6 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ type Config struct {
Static string `yaml:"static"`
SiteUrl string `yaml:"site_url" json:"site_url"` //网站url
} `yaml:"server"`
Cache struct {
Enable bool `yaml:"enable"`
Expiration int `yaml:"expiration"`
CleanupInterval int `yaml:"cleanup_interval"`
RefreshPassword string `yaml:"refresh_password"`
}
AliDrive struct {
ApiUrl string `yaml:"api_url"` //阿里云盘api
RootFolder string `yaml:"root_folder"` //根目录id
Expand Down
3 changes: 0 additions & 3 deletions conf/const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package conf

import (
"github.com/patrickmn/go-cache"
"gorm.io/gorm"
"net/http"
)
Expand All @@ -16,8 +15,6 @@ var (
Client *http.Client // request client
Authorization string // authorization string

Cache *cache.Cache // cache

DB *gorm.DB

Origins []string // allow origins
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/robfig/cron/v3 v3.0.0
github.com/sirupsen/logrus v1.7.0
github.com/ugorji/go v1.2.2 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLD
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
84 changes: 84 additions & 0 deletions server/controllers/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package controllers

import (
"github.com/Xhofe/alist/alidrive"
"github.com/Xhofe/alist/server/models"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"path/filepath"
)

// get request bean
type GetReq struct {
File string `json:"file"`
Password string `json:"password"`
}

// handle list request
func Get(c *gin.Context) {
var get GetReq
if err := c.ShouldBindJSON(&get); err != nil {
c.JSON(200, MetaResponse(400, "Bad Request."))
return
}
log.Debugf("list:%+v", get)
dir, name := filepath.Split(get.File)
file, err := models.GetFileByParentPathAndName(dir, name)
if err != nil {
if file == nil {
c.JSON(200, MetaResponse(404, "File not found."))
return
}
c.JSON(200, MetaResponse(500, err.Error()))
return
}
if file.Password != "" && file.Password != get.Password {
if get.Password == "" {
c.JSON(200, MetaResponse(401, "need password."))
} else {
c.JSON(200, MetaResponse(401, "wrong password."))
}
return
}
c.JSON(200, DataResponse(file))
}

type DownReq struct {
Password string `form:"pw"`
}

// handle download request
func Down(c *gin.Context) {
filePath := c.Param("file")
var down DownReq
if err := c.ShouldBindQuery(&down); err != nil {
c.JSON(200, MetaResponse(400, "Bad Request."))
return
}
log.Debugf("down:%s", filePath)
dir, name := filepath.Split(filePath)
fileModel, err := models.GetFileByParentPathAndName(dir, name)
if err != nil {
if fileModel == nil {
c.JSON(200, MetaResponse(404, "File not found."))
return
}
c.JSON(200, MetaResponse(500, err.Error()))
return
}
if fileModel.Password != "" && fileModel.Password != down.Password {
if down.Password == "" {
c.JSON(200, MetaResponse(401, "need password."))
} else {
c.JSON(200, MetaResponse(401, "wrong password."))
}
return
}
file, err := alidrive.GetDownLoadUrl(fileModel.FileId)
if err != nil {
c.JSON(200, MetaResponse(500, err.Error()))
return
}
c.Redirect(301, file.Url)
return
}
51 changes: 51 additions & 0 deletions server/controllers/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package controllers

import (
"github.com/Xhofe/alist/server/models"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"path/filepath"
)

// list request bean
type ListReq struct {
Path string `json:"path"`
Password string `json:"password"`
}

// handle list request
func List(c *gin.Context) {
var list ListReq
if err := c.ShouldBindJSON(&list); err != nil {
c.JSON(200, MetaResponse(400, "Bad Request."))
return
}
log.Debugf("list:%+v", list)
// find folder model
dir, file := filepath.Split(list.Path)
fileModel, err := models.GetFileByParentPathAndName(dir, file)
if err != nil {
// folder model not exist
if fileModel == nil {
c.JSON(200, MetaResponse(404, "folder not found."))
return
}
c.JSON(200, MetaResponse(500, err.Error()))
return
}
// check password
if fileModel.Password != "" && fileModel.Password != list.Password {
if list.Password == "" {
c.JSON(200, MetaResponse(401, "need password."))
} else {
c.JSON(200, MetaResponse(401, "wrong password."))
}
return
}
files, err := models.GetFilesByParentPath(list.Path + "/")
if err != nil {
c.JSON(200, MetaResponse(500, err.Error()))
return
}
c.JSON(200, DataResponse(files))
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package v1
package controllers

import (
"github.com/Xhofe/alist/alidrive"
"github.com/Xhofe/alist/server/controllers"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
Expand All @@ -11,14 +10,14 @@ import (
func OfficePreview(c *gin.Context) {
var req alidrive.OfficePreviewUrlReq
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(200, controllers.MetaResponse(400, "Bad Request"))
c.JSON(200, MetaResponse(400, "Bad Request"))
return
}
log.Debugf("preview_req:%+v", req)
preview, err := alidrive.GetOfficePreviewUrl(req.FileId)
if err != nil {
c.JSON(200, controllers.MetaResponse(500, err.Error()))
c.JSON(200, MetaResponse(500, err.Error()))
return
}
c.JSON(200, controllers.DataResponse(preview))
c.JSON(200, DataResponse(preview))
}
1 change: 1 addition & 0 deletions server/controllers/search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package controllers
16 changes: 0 additions & 16 deletions server/controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,6 @@ 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 {
if password == conf.Conf.Cache.RefreshPassword {
conf.Cache.Flush()
c.JSON(200, MetaResponse(200, "flush success."))
return
}
c.JSON(200, MetaResponse(401, "wrong password."))
return
}
c.JSON(200, MetaResponse(400, "disabled cache."))
return
}

// rebuild tree
func RebuildTree(c *gin.Context) {
if err := models.Clear(); err != nil {
Expand Down
76 changes: 0 additions & 76 deletions server/controllers/v1/get.go

This file was deleted.

0 comments on commit b677d6a

Please sign in to comment.