Modify file list return data
This commit is contained in:
parent
d0fc2cc8cb
commit
76bc6e68ae
|
@ -5,7 +5,9 @@ import (
|
||||||
"github.com/IceWhaleTech/CasaOS/internal/op"
|
"github.com/IceWhaleTech/CasaOS/internal/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ICONURL = "https://i.pcmag.com/imagery/reviews/02PHW91bUvLOs36qNbBzOiR-12.fit_scale.size_760x427.v1569471162.png"
|
const ICONURL = "./img/driver/Dropbox.svg"
|
||||||
|
const APPKEY = "onr2ic0c0m97mxr"
|
||||||
|
const APPSECRET = "nd3cjtikbxyj3pz"
|
||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
driver.RootID
|
driver.RootID
|
||||||
|
@ -13,8 +15,8 @@ type Addition struct {
|
||||||
AppKey string `json:"app_key" type:"string" default:"onr2ic0c0m97mxr" omit:"true"`
|
AppKey string `json:"app_key" type:"string" default:"onr2ic0c0m97mxr" omit:"true"`
|
||||||
AppSecret string `json:"app_secret" type:"string" default:"nd3cjtikbxyj3pz" omit:"true"`
|
AppSecret string `json:"app_secret" type:"string" default:"nd3cjtikbxyj3pz" omit:"true"`
|
||||||
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" omit:"true"`
|
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" omit:"true"`
|
||||||
AuthUrl string `json:"auth_url" type:"string" default:"https://www.dropbox.com/oauth2/authorize?client_id=onr2ic0c0m97mxr&redirect_uri=https://test-get.casaos.io&response_type=code&token_access_type=offline&state=${HOST}%2Fv1%2Frecover%2FDropbox"`
|
AuthUrl string `json:"auth_url" type:"string" default:"https://www.dropbox.com/oauth2/authorize?client_id=onr2ic0c0m97mxr&redirect_uri=https://test-get.casaos.io&response_type=code&token_access_type=offline&state=${HOST}%2Fv1%2Frecover%2FDropbox&&force_reapprove=true&force_reauthentication=true"`
|
||||||
Icon string `json:"icon" type:"string" default:"https://i.pcmag.com/imagery/reviews/02PHW91bUvLOs36qNbBzOiR-12.fit_scale.size_760x427.v1569471162.png"`
|
Icon string `json:"icon" type:"string" default:"./img/driver/Dropbox.svg"`
|
||||||
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"`
|
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,9 @@ import (
|
||||||
"github.com/IceWhaleTech/CasaOS/internal/op"
|
"github.com/IceWhaleTech/CasaOS/internal/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ICONURL = "https://i.pcmag.com/imagery/reviews/02PHW91bUvLOs36qNbBzOiR-12.fit_scale.size_760x427.v1569471162.png"
|
const ICONURL = "./img/driver/GoogleDrive.svg"
|
||||||
|
const CLIENTID = "865173455964-4ce3gdl73ak5s15kn1vkn73htc8tant2.apps.googleusercontent.com"
|
||||||
|
const CLIENTSECRET = "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"
|
||||||
|
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
driver.RootID
|
driver.RootID
|
||||||
|
@ -16,7 +18,7 @@ type Addition struct {
|
||||||
ClientSecret string `json:"client_secret" required:"true" default:"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" omit:"true"`
|
ClientSecret string `json:"client_secret" required:"true" default:"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" omit:"true"`
|
||||||
ChunkSize int64 `json:"chunk_size" type:"number" help:"chunk size while uploading (unit: MB)" omit:"true"`
|
ChunkSize int64 `json:"chunk_size" type:"number" help:"chunk size while uploading (unit: MB)" omit:"true"`
|
||||||
AuthUrl string `json:"auth_url" type:"string" default:"https://accounts.google.com/o/oauth2/auth/oauthchooseaccount?response_type=code&client_id=865173455964-4ce3gdl73ak5s15kn1vkn73htc8tant2.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Ftest-get.casaos.io&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=offline&approval_prompt=force&state=${HOST}%2Fv1%2Frecover%2FGoogleDrive&service=lso&o2v=1&flowName=GeneralOAuthFlow"`
|
AuthUrl string `json:"auth_url" type:"string" default:"https://accounts.google.com/o/oauth2/auth/oauthchooseaccount?response_type=code&client_id=865173455964-4ce3gdl73ak5s15kn1vkn73htc8tant2.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Ftest-get.casaos.io&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=offline&approval_prompt=force&state=${HOST}%2Fv1%2Frecover%2FGoogleDrive&service=lso&o2v=1&flowName=GeneralOAuthFlow"`
|
||||||
Icon string `json:"icon" type:"string" default:"https://i.pcmag.com/imagery/reviews/02PHW91bUvLOs36qNbBzOiR-12.fit_scale.size_760x427.v1569471162.png"`
|
Icon string `json:"icon" type:"string" default:"./img/driver/GoogleDrive.svg"`
|
||||||
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"`
|
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
main.go
6
main.go
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/IceWhaleTech/CasaOS-Common/model"
|
"github.com/IceWhaleTech/CasaOS-Common/model"
|
||||||
"github.com/IceWhaleTech/CasaOS-Common/utils/constants"
|
"github.com/IceWhaleTech/CasaOS-Common/utils/constants"
|
||||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
util_http "github.com/IceWhaleTech/CasaOS-Common/utils/http"
|
util_http "github.com/IceWhaleTech/CasaOS-Common/utils/http"
|
||||||
|
|
||||||
|
@ -100,6 +101,9 @@ func main() {
|
||||||
v1Router := route.InitV1Router()
|
v1Router := route.InitV1Router()
|
||||||
defer service.SocketServer.Close()
|
defer service.SocketServer.Close()
|
||||||
|
|
||||||
|
v1Router.GET("/v1/socketio/*any", gin.WrapH(service.SocketServer))
|
||||||
|
v1Router.POST("/v1/socketio/*any", gin.WrapH(service.SocketServer))
|
||||||
|
|
||||||
v2Router := route.InitV2Router()
|
v2Router := route.InitV2Router()
|
||||||
v2DocRouter := route.InitV2DocRouter(_docHTML, _docYAML)
|
v2DocRouter := route.InitV2DocRouter(_docHTML, _docYAML)
|
||||||
|
|
||||||
|
@ -146,7 +150,7 @@ func main() {
|
||||||
"/v1/notify",
|
"/v1/notify",
|
||||||
"/v1/socketio",
|
"/v1/socketio",
|
||||||
"/v1/driver",
|
"/v1/driver",
|
||||||
"/v1/storage",
|
"/v1/cloud",
|
||||||
"/v1/recover",
|
"/v1/recover",
|
||||||
route.V2APIPath,
|
route.V2APIPath,
|
||||||
route.V2DocPath,
|
route.V2DocPath,
|
||||||
|
|
15
model/req.go
15
model/req.go
|
@ -1,8 +1,8 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
type PageReq struct {
|
type PageReq struct {
|
||||||
Page int `json:"page" form:"page"`
|
Index int `json:"page" form:"index"`
|
||||||
PerPage int `json:"per_page" form:"per_page"`
|
Size int `json:"size" form:"size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const MaxUint = ^uint(0)
|
const MaxUint = ^uint(0)
|
||||||
|
@ -11,10 +11,13 @@ const MaxInt = int(MaxUint >> 1)
|
||||||
const MinInt = -MaxInt - 1
|
const MinInt = -MaxInt - 1
|
||||||
|
|
||||||
func (p *PageReq) Validate() {
|
func (p *PageReq) Validate() {
|
||||||
if p.Page < 1 {
|
if p.Index < 1 {
|
||||||
p.Page = 1
|
p.Index = 1
|
||||||
}
|
}
|
||||||
if p.PerPage < 1 {
|
if p.Size < 1 {
|
||||||
p.PerPage = MaxInt
|
p.Size = 100000
|
||||||
}
|
}
|
||||||
|
// if p.PerPage < 1 {
|
||||||
|
// p.PerPage = MaxInt
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,11 @@ type MountList struct {
|
||||||
Icon string `json:"Icon"`
|
Icon string `json:"Icon"`
|
||||||
} `json:"mountPoints"`
|
} `json:"mountPoints"`
|
||||||
}
|
}
|
||||||
|
type MountPoint struct {
|
||||||
|
MountPoint string `json:"mount_point"`
|
||||||
|
Fs string `json:"fs"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
}
|
||||||
type MountResult struct {
|
type MountResult struct {
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
Input struct {
|
Input struct {
|
||||||
|
|
13
route/v1.go
13
route/v1.go
|
@ -7,7 +7,6 @@ import (
|
||||||
"github.com/IceWhaleTech/CasaOS-Common/utils/jwt"
|
"github.com/IceWhaleTech/CasaOS-Common/utils/jwt"
|
||||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||||
v1 "github.com/IceWhaleTech/CasaOS/route/v1"
|
v1 "github.com/IceWhaleTech/CasaOS/route/v1"
|
||||||
"github.com/IceWhaleTech/CasaOS/service"
|
|
||||||
|
|
||||||
"github.com/gin-contrib/gzip"
|
"github.com/gin-contrib/gzip"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -98,11 +97,11 @@ func InitV1Router() *gin.Engine {
|
||||||
// v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
|
// v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
|
||||||
|
|
||||||
}
|
}
|
||||||
v1StorageGroup := v1Group.Group("/storage")
|
v1CloudGroup := v1Group.Group("/cloud")
|
||||||
v1StorageGroup.Use()
|
v1CloudGroup.Use()
|
||||||
{
|
{
|
||||||
v1StorageGroup.GET("", v1.ListStorages)
|
v1CloudGroup.GET("", v1.ListStorages)
|
||||||
v1StorageGroup.DELETE("", v1.DeleteStorage)
|
v1CloudGroup.DELETE("", v1.DeleteStorage)
|
||||||
}
|
}
|
||||||
v1DriverGroup := v1Group.Group("/driver")
|
v1DriverGroup := v1Group.Group("/driver")
|
||||||
v1DriverGroup.Use()
|
v1DriverGroup.Use()
|
||||||
|
@ -162,8 +161,8 @@ func InitV1Router() *gin.Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
// socketio
|
// socketio
|
||||||
v1Group.GET("/socketio/*any", gin.WrapH(service.SocketServer))
|
// v1Group.GET("/socketio/*any", gin.WrapH(service.SocketServer))
|
||||||
v1Group.POST("/socketio/*any", gin.WrapH(service.SocketServer))
|
// v1Group.POST("/socketio/*any", gin.WrapH(service.SocketServer))
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,40 +256,23 @@ func DirPath(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.Validate()
|
req.Validate()
|
||||||
storage, _, _ := service.MyService.StoragePath().GetStorageAndActualPath(req.Path)
|
|
||||||
if storage != nil {
|
|
||||||
req.Validate()
|
|
||||||
objs, err := service.MyService.FsService().FList(c, req.Path, req.Refresh)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
total, objs := pagination(objs, &req.PageReq)
|
|
||||||
provider := "unknown"
|
|
||||||
storage, err := service.MyService.FsService().GetStorage(req.Path)
|
|
||||||
if err == nil {
|
|
||||||
provider = storage.GetStorage().Driver
|
|
||||||
}
|
|
||||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: FsListResp{
|
|
||||||
Content: toObjsResp(objs, req.Path, false),
|
|
||||||
Total: int64(total),
|
|
||||||
Readme: "",
|
|
||||||
Write: false,
|
|
||||||
Provider: provider,
|
|
||||||
}})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
info := service.MyService.System().GetDirPath(req.Path)
|
info := service.MyService.System().GetDirPath(req.Path)
|
||||||
shares := service.MyService.Shares().GetSharesList()
|
shares := service.MyService.Shares().GetSharesList()
|
||||||
sharesMap := make(map[string]string)
|
sharesMap := make(map[string]string)
|
||||||
for _, v := range shares {
|
for _, v := range shares {
|
||||||
sharesMap[v.Path] = fmt.Sprint(v.ID)
|
sharesMap[v.Path] = fmt.Sprint(v.ID)
|
||||||
}
|
}
|
||||||
|
// if len(info) <= (req.Page-1)*req.Size {
|
||||||
for i := 0; i < len(info); i++ {
|
// c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: "page out of range"})
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
forEnd := req.Index * req.Size
|
||||||
|
if forEnd > len(info) {
|
||||||
|
forEnd = len(info)
|
||||||
|
}
|
||||||
|
for i := (req.Index - 1) * req.Size; i < forEnd; i++ {
|
||||||
if v, ok := sharesMap[info[i].Path]; ok {
|
if v, ok := sharesMap[info[i].Path]; ok {
|
||||||
ex := make(map[string]interface{})
|
ex := make(map[string]interface{})
|
||||||
|
|
||||||
shareEx := make(map[string]string)
|
shareEx := make(map[string]string)
|
||||||
shareEx["shared"] = "true"
|
shareEx["shared"] = "true"
|
||||||
shareEx["id"] = v
|
shareEx["id"] = v
|
||||||
|
@ -314,11 +297,10 @@ func DirPath(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pathList := []ObjResp{}
|
pathList := []ObjResp{}
|
||||||
for i := 0; i < len(info); i++ {
|
for i := (req.Index - 1) * req.Size; i < forEnd; i++ {
|
||||||
if info[i].Name == ".temp" && info[i].IsDir {
|
if info[i].Name == ".temp" && info[i].IsDir {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := fileQueue[info[i].Path]; !ok {
|
if _, ok := fileQueue[info[i].Path]; !ok {
|
||||||
t := ObjResp{}
|
t := ObjResp{}
|
||||||
t.IsDir = info[i].IsDir
|
t.IsDir = info[i].IsDir
|
||||||
|
@ -326,15 +308,19 @@ func DirPath(c *gin.Context) {
|
||||||
t.Modified = info[i].Date
|
t.Modified = info[i].Date
|
||||||
t.Size = info[i].Size
|
t.Size = info[i].Size
|
||||||
t.Path = info[i].Path
|
t.Path = info[i].Path
|
||||||
|
t.Extensions = info[i].Extensions
|
||||||
pathList = append(pathList, t)
|
pathList = append(pathList, t)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flist := FsListResp{
|
flist := FsListResp{
|
||||||
Content: pathList,
|
Content: pathList,
|
||||||
Total: int64(len(pathList)),
|
Total: int64(len(info)),
|
||||||
Readme: "",
|
// Readme: "",
|
||||||
Write: true,
|
// Write: true,
|
||||||
Provider: "local",
|
// Provider: "local",
|
||||||
|
Index: req.Index,
|
||||||
|
Size: req.Size,
|
||||||
}
|
}
|
||||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: flist})
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: flist})
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,25 +13,28 @@ import (
|
||||||
|
|
||||||
type ListReq struct {
|
type ListReq struct {
|
||||||
model.PageReq
|
model.PageReq
|
||||||
Path string `json:"path" form:"path"`
|
Path string `json:"path" form:"path"`
|
||||||
Refresh bool `json:"refresh"`
|
//Refresh bool `json:"refresh"`
|
||||||
}
|
}
|
||||||
type ObjResp struct {
|
type ObjResp struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
IsDir bool `json:"is_dir"`
|
IsDir bool `json:"is_dir"`
|
||||||
Modified time.Time `json:"modified"`
|
Modified time.Time `json:"modified"`
|
||||||
Sign string `json:"sign"`
|
Sign string `json:"sign"`
|
||||||
Thumb string `json:"thumb"`
|
Thumb string `json:"thumb"`
|
||||||
Type int `json:"type"`
|
Type int `json:"type"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
|
Extensions map[string]interface{} `json:"extensions"`
|
||||||
}
|
}
|
||||||
type FsListResp struct {
|
type FsListResp struct {
|
||||||
Content []ObjResp `json:"content"`
|
Content []ObjResp `json:"content"`
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
Readme string `json:"readme"`
|
Readme string `json:"readme,omitempty"`
|
||||||
Write bool `json:"write"`
|
Write bool `json:"write,omitempty"`
|
||||||
Provider string `json:"provider"`
|
Provider string `json:"provider,omitempty"`
|
||||||
|
Index int `json:"index"`
|
||||||
|
Size int `json:"size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func FsList(c *gin.Context) {
|
func FsList(c *gin.Context) {
|
||||||
|
@ -41,7 +44,7 @@ func FsList(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.Validate()
|
req.Validate()
|
||||||
objs, err := service.MyService.FsService().FList(c, req.Path, req.Refresh)
|
objs, err := service.MyService.FsService().FList(c, req.Path, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
||||||
return
|
return
|
||||||
|
@ -61,7 +64,7 @@ func FsList(c *gin.Context) {
|
||||||
}})
|
}})
|
||||||
}
|
}
|
||||||
func pagination(objs []model.Obj, req *model.PageReq) (int, []model.Obj) {
|
func pagination(objs []model.Obj, req *model.PageReq) (int, []model.Obj) {
|
||||||
pageIndex, pageSize := req.Page, req.PerPage
|
pageIndex, pageSize := req.Index, req.Size
|
||||||
total := len(objs)
|
total := len(objs)
|
||||||
start := (pageIndex - 1) * pageSize
|
start := (pageIndex - 1) * pageSize
|
||||||
if start > total {
|
if start > total {
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/IceWhaleTech/CasaOS/drivers/dropbox"
|
"github.com/IceWhaleTech/CasaOS/drivers/dropbox"
|
||||||
"github.com/IceWhaleTech/CasaOS/drivers/google_drive"
|
"github.com/IceWhaleTech/CasaOS/drivers/google_drive"
|
||||||
"github.com/IceWhaleTech/CasaOS/internal/op"
|
|
||||||
"github.com/IceWhaleTech/CasaOS/service"
|
"github.com/IceWhaleTech/CasaOS/service"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
@ -17,45 +15,39 @@ func GetRecoverStorage(c *gin.Context) {
|
||||||
t := c.Param("type")
|
t := c.Param("type")
|
||||||
currentTime := time.Now().UTC()
|
currentTime := time.Now().UTC()
|
||||||
currentDate := time.Now().UTC().Format("2006-01-02")
|
currentDate := time.Now().UTC().Format("2006-01-02")
|
||||||
// timeStr := time.Now().Format("20060102150405")
|
notify := make(map[string]interface{})
|
||||||
if t == "GoogleDrive" {
|
if t == "GoogleDrive" {
|
||||||
|
|
||||||
gd := op.GetDriverInfoMap()[t]
|
|
||||||
|
|
||||||
add := google_drive.Addition{}
|
add := google_drive.Addition{}
|
||||||
add.Code = c.Query("code")
|
add.Code = c.Query("code")
|
||||||
if len(add.Code) == 0 {
|
if len(add.Code) == 0 {
|
||||||
c.String(200, `<p>code cannot be empty</p>`)
|
c.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||||
|
notify["status"] = "fail"
|
||||||
|
notify["message"] = "Code cannot be empty"
|
||||||
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
add.RootFolderID = "root"
|
add.RootFolderID = "root"
|
||||||
for _, v := range gd {
|
add.ClientID = google_drive.CLIENTID
|
||||||
if v.Name == "client_id" {
|
add.ClientSecret = google_drive.CLIENTSECRET
|
||||||
add.ClientID = v.Default
|
|
||||||
}
|
|
||||||
if v.Name == "client_secret" {
|
|
||||||
add.ClientSecret = v.Default
|
|
||||||
}
|
|
||||||
if v.Name == "chunk_size" {
|
|
||||||
cs, err := strconv.ParseInt(v.Default, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
cs = 5
|
|
||||||
}
|
|
||||||
add.ChunkSize = cs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var google_drive google_drive.GoogleDrive
|
var google_drive google_drive.GoogleDrive
|
||||||
google_drive.Addition = add
|
google_drive.Addition = add
|
||||||
err := google_drive.Init(c)
|
err := google_drive.Init(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(200, `<p>Initialization failure:`+err.Error()+`</p>`)
|
c.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
|
notify["status"] = "fail"
|
||||||
|
notify["message"] = "Initialization failure"
|
||||||
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
username, err := google_drive.GetUserInfo(c)
|
username, err := google_drive.GetUserInfo(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p>`)
|
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
|
notify["status"] = "fail"
|
||||||
|
notify["message"] = "Failed to get user information"
|
||||||
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(username) > 0 {
|
if len(username) > 0 {
|
||||||
|
@ -65,8 +57,11 @@ func GetRecoverStorage(c *gin.Context) {
|
||||||
username += "_drive"
|
username += "_drive"
|
||||||
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
||||||
if len(dataMap) > 0 {
|
if len(dataMap) > 0 {
|
||||||
c.String(200, `<p>The same configuration has been added</p>`)
|
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
||||||
service.MyService.Storage().CheckAndMountByName(username)
|
service.MyService.Storage().CheckAndMountByName(username)
|
||||||
|
notify["status"] = "warn"
|
||||||
|
notify["message"] = "The same configuration has been added"
|
||||||
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dmap := make(map[string]string)
|
dmap := make(map[string]string)
|
||||||
|
@ -74,54 +69,42 @@ func GetRecoverStorage(c *gin.Context) {
|
||||||
dmap["client_secret"] = add.ClientSecret
|
dmap["client_secret"] = add.ClientSecret
|
||||||
dmap["scope"] = "drive"
|
dmap["scope"] = "drive"
|
||||||
dmap["mount_point"] = "/mnt/" + username
|
dmap["mount_point"] = "/mnt/" + username
|
||||||
dmap["token"] = `{"access_token":"` + google_drive.AccessToken + `","token_type":"Bearer","refresh_token":"` + google_drive.RefreshToken + `","expiry":"` + currentDate + `T` + currentTime.Add(time.Hour*1).Format("15:04:05") + `Z"}`
|
dmap["token"] = `{"access_token":"` + google_drive.AccessToken + `","token_type":"Bearer","refresh_token":"` + google_drive.RefreshToken + `","expiry":"` + currentDate + `T` + currentTime.Add(time.Hour*1).Add(time.Minute*50).Format("15:04:05") + `Z"}`
|
||||||
// data.SetValue(username, "type", "drive")
|
|
||||||
// data.SetValue(username, "client_id", "865173455964-4ce3gdl73ak5s15kn1vkn73htc8tant2.apps.googleusercontent.com")
|
|
||||||
// data.SetValue(username, "client_secret", "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")
|
|
||||||
// data.SetValue(username, "scope", "drive")
|
|
||||||
// data.SetValue(username, "mount_point", "/mnt/"+username)
|
|
||||||
// data.SetValue(username, "token", `{"access_token":"`+google_drive.AccessToken+`","token_type":"Bearer","refresh_token":"`+google_drive.RefreshToken+`","expiry":"`+currentDate+`T`+currentTime.Add(time.Hour*1).Format("15:04:05")+`Z"}`)
|
|
||||||
// e = data.Save()
|
|
||||||
// if e != nil {
|
|
||||||
// c.String(200, `<p>保存配置失败:`+e.Error()+`</p>`)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
service.MyService.Storage().CreateConfig(dmap, username, "drive")
|
service.MyService.Storage().CreateConfig(dmap, username, "drive")
|
||||||
service.MyService.Storage().MountStorage("/mnt/"+username, username+":")
|
service.MyService.Storage().MountStorage("/mnt/"+username, username+":")
|
||||||
notify := make(map[string]interface{})
|
notify := make(map[string]interface{})
|
||||||
notify["status"] = "success"
|
notify["status"] = "success"
|
||||||
|
notify["message"] = "Success"
|
||||||
service.MyService.Notify().SendNotify("recover_status", notify)
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
} else if t == "Dropbox" {
|
} else if t == "Dropbox" {
|
||||||
|
|
||||||
//mountPath += timeStr
|
|
||||||
|
|
||||||
db := op.GetDriverInfoMap()[t]
|
|
||||||
|
|
||||||
add := dropbox.Addition{}
|
add := dropbox.Addition{}
|
||||||
add.Code = c.Query("code")
|
add.Code = c.Query("code")
|
||||||
if len(add.Code) == 0 {
|
if len(add.Code) == 0 {
|
||||||
c.String(200, `<p>code cannot be empty</p>`)
|
c.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||||
|
notify["status"] = "fail"
|
||||||
|
notify["message"] = "Code cannot be empty"
|
||||||
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
add.RootFolderID = ""
|
add.RootFolderID = ""
|
||||||
for _, v := range db {
|
add.AppKey = dropbox.APPKEY
|
||||||
if v.Name == "app_key" {
|
add.AppSecret = dropbox.APPSECRET
|
||||||
add.AppKey = v.Default
|
|
||||||
}
|
|
||||||
if v.Name == "app_secret" {
|
|
||||||
add.AppSecret = v.Default
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var dropbox dropbox.Dropbox
|
var dropbox dropbox.Dropbox
|
||||||
dropbox.Addition = add
|
dropbox.Addition = add
|
||||||
err := dropbox.Init(c)
|
err := dropbox.Init(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(200, `<p>Initialization failure:`+err.Error()+`</p>`)
|
c.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
|
notify["status"] = "fail"
|
||||||
|
notify["message"] = "Initialization failure"
|
||||||
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
username, err := dropbox.GetUserInfo(c)
|
username, err := dropbox.GetUserInfo(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p>`)
|
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
|
notify["status"] = "fail"
|
||||||
|
notify["message"] = "Failed to get user information"
|
||||||
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(username) > 0 {
|
if len(username) > 0 {
|
||||||
|
@ -131,14 +114,17 @@ func GetRecoverStorage(c *gin.Context) {
|
||||||
username += "_dropbox"
|
username += "_dropbox"
|
||||||
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
||||||
if len(dataMap) > 0 {
|
if len(dataMap) > 0 {
|
||||||
c.String(200, `<p>The same configuration has been added</p>`)
|
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
||||||
service.MyService.Storage().CheckAndMountByName(username)
|
service.MyService.Storage().CheckAndMountByName(username)
|
||||||
|
notify["status"] = "warn"
|
||||||
|
notify["message"] = "The same configuration has been added"
|
||||||
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dmap := make(map[string]string)
|
dmap := make(map[string]string)
|
||||||
dmap["client_id"] = add.AppKey
|
dmap["client_id"] = add.AppKey
|
||||||
dmap["client_secret"] = add.AppSecret
|
dmap["client_secret"] = add.AppSecret
|
||||||
dmap["token"] = `{"access_token":"` + dropbox.AccessToken + `","token_type":"bearer","refresh_token":"` + dropbox.Addition.RefreshToken + `","expiry":"` + currentDate + `T` + currentTime.Add(time.Hour*3).Format("15:04:05") + `.780385354Z"}`
|
dmap["token"] = `{"access_token":"` + dropbox.AccessToken + `","token_type":"bearer","refresh_token":"` + dropbox.Addition.RefreshToken + `","expiry":"` + currentDate + `T` + currentTime.Add(time.Hour*3).Add(time.Minute*50).Format("15:04:05") + `.780385354Z"}`
|
||||||
dmap["mount_point"] = "/mnt/" + username
|
dmap["mount_point"] = "/mnt/" + username
|
||||||
// data.SetValue(username, "type", "dropbox")
|
// data.SetValue(username, "type", "dropbox")
|
||||||
// data.SetValue(username, "client_id", add.AppKey)
|
// data.SetValue(username, "client_id", add.AppKey)
|
||||||
|
@ -154,8 +140,9 @@ func GetRecoverStorage(c *gin.Context) {
|
||||||
// }
|
// }
|
||||||
service.MyService.Storage().CreateConfig(dmap, username, "dropbox")
|
service.MyService.Storage().CreateConfig(dmap, username, "dropbox")
|
||||||
service.MyService.Storage().MountStorage("/mnt/"+username, username+":")
|
service.MyService.Storage().MountStorage("/mnt/"+username, username+":")
|
||||||
notify := make(map[string]interface{})
|
|
||||||
notify["status"] = "success"
|
notify["status"] = "success"
|
||||||
|
notify["message"] = "Success"
|
||||||
service.MyService.Notify().SendNotify("recover_status", notify)
|
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/IceWhaleTech/CasaOS/drivers/google_drive"
|
"github.com/IceWhaleTech/CasaOS/drivers/google_drive"
|
||||||
"github.com/IceWhaleTech/CasaOS/model"
|
"github.com/IceWhaleTech/CasaOS/model"
|
||||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
||||||
|
"github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
|
||||||
"github.com/IceWhaleTech/CasaOS/service"
|
"github.com/IceWhaleTech/CasaOS/service"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -52,8 +53,17 @@ func ListStorages(c *gin.Context) {
|
||||||
r.MountPoints[i].Icon = dropbox.ICONURL
|
r.MountPoints[i].Icon = dropbox.ICONURL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
list := []httper.MountPoint{}
|
||||||
|
|
||||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: r})
|
for _, v := range r.MountPoints {
|
||||||
|
list = append(list, httper.MountPoint{
|
||||||
|
Fs: v.Fs,
|
||||||
|
Icon: v.Icon,
|
||||||
|
MountPoint: v.MountPoint,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: list})
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateStorage(c *gin.Context) {
|
func UpdateStorage(c *gin.Context) {
|
||||||
|
|
Loading…
Reference in a new issue