Modify file list return data
This commit is contained in:
parent
d0fc2cc8cb
commit
76bc6e68ae
10 changed files with 125 additions and 124 deletions
|
@ -5,7 +5,9 @@ import (
|
|||
"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 {
|
||||
driver.RootID
|
||||
|
@ -13,8 +15,8 @@ type Addition struct {
|
|||
AppKey string `json:"app_key" type:"string" default:"onr2ic0c0m97mxr" 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"`
|
||||
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"`
|
||||
Icon string `json:"icon" type:"string" default:"https://i.pcmag.com/imagery/reviews/02PHW91bUvLOs36qNbBzOiR-12.fit_scale.size_760x427.v1569471162.png"`
|
||||
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:"./img/driver/Dropbox.svg"`
|
||||
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"`
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@ import (
|
|||
"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 {
|
||||
driver.RootID
|
||||
|
@ -16,7 +18,7 @@ type Addition struct {
|
|||
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"`
|
||||
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"`
|
||||
}
|
||||
|
||||
|
|
6
main.go
6
main.go
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/IceWhaleTech/CasaOS-Common/model"
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/constants"
|
||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
util_http "github.com/IceWhaleTech/CasaOS-Common/utils/http"
|
||||
|
||||
|
@ -100,6 +101,9 @@ func main() {
|
|||
v1Router := route.InitV1Router()
|
||||
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()
|
||||
v2DocRouter := route.InitV2DocRouter(_docHTML, _docYAML)
|
||||
|
||||
|
@ -146,7 +150,7 @@ func main() {
|
|||
"/v1/notify",
|
||||
"/v1/socketio",
|
||||
"/v1/driver",
|
||||
"/v1/storage",
|
||||
"/v1/cloud",
|
||||
"/v1/recover",
|
||||
route.V2APIPath,
|
||||
route.V2DocPath,
|
||||
|
|
15
model/req.go
15
model/req.go
|
@ -1,8 +1,8 @@
|
|||
package model
|
||||
|
||||
type PageReq struct {
|
||||
Page int `json:"page" form:"page"`
|
||||
PerPage int `json:"per_page" form:"per_page"`
|
||||
Index int `json:"page" form:"index"`
|
||||
Size int `json:"size" form:"size"`
|
||||
}
|
||||
|
||||
const MaxUint = ^uint(0)
|
||||
|
@ -11,10 +11,13 @@ const MaxInt = int(MaxUint >> 1)
|
|||
const MinInt = -MaxInt - 1
|
||||
|
||||
func (p *PageReq) Validate() {
|
||||
if p.Page < 1 {
|
||||
p.Page = 1
|
||||
if p.Index < 1 {
|
||||
p.Index = 1
|
||||
}
|
||||
if p.PerPage < 1 {
|
||||
p.PerPage = MaxInt
|
||||
if p.Size < 1 {
|
||||
p.Size = 100000
|
||||
}
|
||||
// if p.PerPage < 1 {
|
||||
// p.PerPage = MaxInt
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -17,6 +17,11 @@ type MountList struct {
|
|||
Icon string `json:"Icon"`
|
||||
} `json:"mountPoints"`
|
||||
}
|
||||
type MountPoint struct {
|
||||
MountPoint string `json:"mount_point"`
|
||||
Fs string `json:"fs"`
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
type MountResult struct {
|
||||
Error string `json:"error"`
|
||||
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/pkg/config"
|
||||
v1 "github.com/IceWhaleTech/CasaOS/route/v1"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
|
||||
"github.com/gin-contrib/gzip"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -98,11 +97,11 @@ func InitV1Router() *gin.Engine {
|
|||
// v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
|
||||
|
||||
}
|
||||
v1StorageGroup := v1Group.Group("/storage")
|
||||
v1StorageGroup.Use()
|
||||
v1CloudGroup := v1Group.Group("/cloud")
|
||||
v1CloudGroup.Use()
|
||||
{
|
||||
v1StorageGroup.GET("", v1.ListStorages)
|
||||
v1StorageGroup.DELETE("", v1.DeleteStorage)
|
||||
v1CloudGroup.GET("", v1.ListStorages)
|
||||
v1CloudGroup.DELETE("", v1.DeleteStorage)
|
||||
}
|
||||
v1DriverGroup := v1Group.Group("/driver")
|
||||
v1DriverGroup.Use()
|
||||
|
@ -162,8 +161,8 @@ func InitV1Router() *gin.Engine {
|
|||
}
|
||||
|
||||
// socketio
|
||||
v1Group.GET("/socketio/*any", gin.WrapH(service.SocketServer))
|
||||
v1Group.POST("/socketio/*any", gin.WrapH(service.SocketServer))
|
||||
// v1Group.GET("/socketio/*any", gin.WrapH(service.SocketServer))
|
||||
// v1Group.POST("/socketio/*any", gin.WrapH(service.SocketServer))
|
||||
|
||||
return r
|
||||
}
|
||||
|
|
|
@ -256,40 +256,23 @@ func DirPath(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
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)
|
||||
shares := service.MyService.Shares().GetSharesList()
|
||||
sharesMap := make(map[string]string)
|
||||
for _, v := range shares {
|
||||
sharesMap[v.Path] = fmt.Sprint(v.ID)
|
||||
}
|
||||
|
||||
for i := 0; i < len(info); i++ {
|
||||
// if len(info) <= (req.Page-1)*req.Size {
|
||||
// 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 {
|
||||
ex := make(map[string]interface{})
|
||||
|
||||
shareEx := make(map[string]string)
|
||||
shareEx["shared"] = "true"
|
||||
shareEx["id"] = v
|
||||
|
@ -314,11 +297,10 @@ func DirPath(c *gin.Context) {
|
|||
}
|
||||
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := fileQueue[info[i].Path]; !ok {
|
||||
t := ObjResp{}
|
||||
t.IsDir = info[i].IsDir
|
||||
|
@ -326,15 +308,19 @@ func DirPath(c *gin.Context) {
|
|||
t.Modified = info[i].Date
|
||||
t.Size = info[i].Size
|
||||
t.Path = info[i].Path
|
||||
t.Extensions = info[i].Extensions
|
||||
pathList = append(pathList, t)
|
||||
|
||||
}
|
||||
}
|
||||
flist := FsListResp{
|
||||
Content: pathList,
|
||||
Total: int64(len(pathList)),
|
||||
Readme: "",
|
||||
Write: true,
|
||||
Provider: "local",
|
||||
Total: int64(len(info)),
|
||||
// Readme: "",
|
||||
// Write: true,
|
||||
// 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})
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
type ListReq struct {
|
||||
model.PageReq
|
||||
Path string `json:"path" form:"path"`
|
||||
Refresh bool `json:"refresh"`
|
||||
//Refresh bool `json:"refresh"`
|
||||
}
|
||||
type ObjResp struct {
|
||||
Name string `json:"name"`
|
||||
|
@ -25,13 +25,16 @@ type ObjResp struct {
|
|||
Thumb string `json:"thumb"`
|
||||
Type int `json:"type"`
|
||||
Path string `json:"path"`
|
||||
Extensions map[string]interface{} `json:"extensions"`
|
||||
}
|
||||
type FsListResp struct {
|
||||
Content []ObjResp `json:"content"`
|
||||
Total int64 `json:"total"`
|
||||
Readme string `json:"readme"`
|
||||
Write bool `json:"write"`
|
||||
Provider string `json:"provider"`
|
||||
Readme string `json:"readme,omitempty"`
|
||||
Write bool `json:"write,omitempty"`
|
||||
Provider string `json:"provider,omitempty"`
|
||||
Index int `json:"index"`
|
||||
Size int `json:"size"`
|
||||
}
|
||||
|
||||
func FsList(c *gin.Context) {
|
||||
|
@ -41,7 +44,7 @@ func FsList(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
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 {
|
||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
||||
return
|
||||
|
@ -61,7 +64,7 @@ func FsList(c *gin.Context) {
|
|||
}})
|
||||
}
|
||||
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)
|
||||
start := (pageIndex - 1) * pageSize
|
||||
if start > total {
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS/drivers/dropbox"
|
||||
"github.com/IceWhaleTech/CasaOS/drivers/google_drive"
|
||||
"github.com/IceWhaleTech/CasaOS/internal/op"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
@ -17,45 +15,39 @@ func GetRecoverStorage(c *gin.Context) {
|
|||
t := c.Param("type")
|
||||
currentTime := time.Now().UTC()
|
||||
currentDate := time.Now().UTC().Format("2006-01-02")
|
||||
// timeStr := time.Now().Format("20060102150405")
|
||||
notify := make(map[string]interface{})
|
||||
if t == "GoogleDrive" {
|
||||
|
||||
gd := op.GetDriverInfoMap()[t]
|
||||
|
||||
add := google_drive.Addition{}
|
||||
add.Code = c.Query("code")
|
||||
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
|
||||
}
|
||||
|
||||
add.RootFolderID = "root"
|
||||
for _, v := range gd {
|
||||
if v.Name == "client_id" {
|
||||
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
|
||||
}
|
||||
}
|
||||
add.ClientID = google_drive.CLIENTID
|
||||
add.ClientSecret = google_drive.CLIENTSECRET
|
||||
|
||||
var google_drive google_drive.GoogleDrive
|
||||
google_drive.Addition = add
|
||||
err := google_drive.Init(c)
|
||||
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
|
||||
}
|
||||
|
||||
username, err := google_drive.GetUserInfo(c)
|
||||
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
|
||||
}
|
||||
if len(username) > 0 {
|
||||
|
@ -65,8 +57,11 @@ func GetRecoverStorage(c *gin.Context) {
|
|||
username += "_drive"
|
||||
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
||||
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)
|
||||
notify["status"] = "warn"
|
||||
notify["message"] = "The same configuration has been added"
|
||||
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||
return
|
||||
}
|
||||
dmap := make(map[string]string)
|
||||
|
@ -74,54 +69,42 @@ func GetRecoverStorage(c *gin.Context) {
|
|||
dmap["client_secret"] = add.ClientSecret
|
||||
dmap["scope"] = "drive"
|
||||
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"}`
|
||||
// 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
|
||||
// }
|
||||
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"}`
|
||||
service.MyService.Storage().CreateConfig(dmap, username, "drive")
|
||||
service.MyService.Storage().MountStorage("/mnt/"+username, username+":")
|
||||
notify := make(map[string]interface{})
|
||||
notify["status"] = "success"
|
||||
notify["message"] = "Success"
|
||||
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||
} else if t == "Dropbox" {
|
||||
|
||||
//mountPath += timeStr
|
||||
|
||||
db := op.GetDriverInfoMap()[t]
|
||||
|
||||
add := dropbox.Addition{}
|
||||
add.Code = c.Query("code")
|
||||
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
|
||||
}
|
||||
add.RootFolderID = ""
|
||||
for _, v := range db {
|
||||
if v.Name == "app_key" {
|
||||
add.AppKey = v.Default
|
||||
}
|
||||
if v.Name == "app_secret" {
|
||||
add.AppSecret = v.Default
|
||||
}
|
||||
}
|
||||
add.AppKey = dropbox.APPKEY
|
||||
add.AppSecret = dropbox.APPSECRET
|
||||
var dropbox dropbox.Dropbox
|
||||
dropbox.Addition = add
|
||||
err := dropbox.Init(c)
|
||||
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
|
||||
}
|
||||
username, err := dropbox.GetUserInfo(c)
|
||||
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
|
||||
}
|
||||
if len(username) > 0 {
|
||||
|
@ -131,14 +114,17 @@ func GetRecoverStorage(c *gin.Context) {
|
|||
username += "_dropbox"
|
||||
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
||||
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)
|
||||
notify["status"] = "warn"
|
||||
notify["message"] = "The same configuration has been added"
|
||||
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||
return
|
||||
}
|
||||
dmap := make(map[string]string)
|
||||
dmap["client_id"] = add.AppKey
|
||||
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
|
||||
// data.SetValue(username, "type", "dropbox")
|
||||
// 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().MountStorage("/mnt/"+username, username+":")
|
||||
notify := make(map[string]interface{})
|
||||
|
||||
notify["status"] = "success"
|
||||
notify["message"] = "Success"
|
||||
service.MyService.Notify().SendNotify("recover_status", notify)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/IceWhaleTech/CasaOS/drivers/google_drive"
|
||||
"github.com/IceWhaleTech/CasaOS/model"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
|
@ -52,8 +53,17 @@ func ListStorages(c *gin.Context) {
|
|||
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) {
|
||||
|
|
Loading…
Reference in a new issue