-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
162 additions
and
351 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,6 @@ func start() { | |
log.Errorf("初始化数据库出现错误,启动失败.") | ||
return | ||
} | ||
InitCache() | ||
InitCron() | ||
server() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package controllers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.