Skip to content

Commit

Permalink
Modify file list return data
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Feb 2, 2023
1 parent d0fc2cc commit 76bc6e6
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 124 deletions.
8 changes: 5 additions & 3 deletions drivers/dropbox/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ 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
RefreshToken string `json:"refresh_token" required:"true" omit:"true"`
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"`
}

Expand Down
6 changes: 4 additions & 2 deletions drivers/google_drive/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}

Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -146,7 +150,7 @@ func main() {
"/v1/notify",
"/v1/socketio",
"/v1/driver",
"/v1/storage",
"/v1/cloud",
"/v1/recover",
route.V2APIPath,
route.V2DocPath,
Expand Down
15 changes: 9 additions & 6 deletions model/req.go
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
// }
}
5 changes: 5 additions & 0 deletions pkg/utils/httper/drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 6 additions & 7 deletions route/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
52 changes: 19 additions & 33 deletions route/v1/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -314,27 +297,30 @@ 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
t.Name = info[i].Name
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",
Content: pathList,
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})
}
Expand Down
33 changes: 18 additions & 15 deletions route/v1/file_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,28 @@ import (

type ListReq struct {
model.PageReq
Path string `json:"path" form:"path"`
Refresh bool `json:"refresh"`
Path string `json:"path" form:"path"`
//Refresh bool `json:"refresh"`
}
type ObjResp struct {
Name string `json:"name"`
Size int64 `json:"size"`
IsDir bool `json:"is_dir"`
Modified time.Time `json:"modified"`
Sign string `json:"sign"`
Thumb string `json:"thumb"`
Type int `json:"type"`
Path string `json:"path"`
Name string `json:"name"`
Size int64 `json:"size"`
IsDir bool `json:"is_dir"`
Modified time.Time `json:"modified"`
Sign string `json:"sign"`
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) {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 76bc6e6

Please sign in to comment.