Skip to content

Commit

Permalink
ADD sorted type field.
Browse files Browse the repository at this point in the history
  • Loading branch information
karminski committed Feb 20, 2024
1 parent 5b730a2 commit 47bc50c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
41 changes: 24 additions & 17 deletions src/actionruntime/illadrive/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func (r *IllaDriveConnector) Run(resourceOptions map[string]interface{}, actionO
switch operation {
case illadrivesdk.DRIVE_API_ACTION_LIST_FILES:
// list files require field "path", "page", "limit", "fileID", "search", "sortedBy", "expirationType", "expiry", "hotlinkProtection"
path, page, limit, fileID, search, sortedBy, expirationType, expiry, hotlinkProtection, errInExtractParam := extractListFileOperationParams(actionOptions)
path, page, limit, fileID, search, sortedBy, sortedType, expirationType, expiry, hotlinkProtection, errInExtractParam := extractListFileOperationParams(actionOptions)
if errInExtractParam != nil {
return res, errInExtractParam
}
ret, errInCallAPI := driveAPI.ListFiles(path, page, limit, fileID, search, sortedBy, expirationType, expiry, hotlinkProtection)
ret, errInCallAPI := driveAPI.ListFiles(path, page, limit, fileID, search, sortedBy, sortedType, expirationType, expiry, hotlinkProtection)
if errInCallAPI != nil {
return res, errInCallAPI
}
Expand Down Expand Up @@ -195,13 +195,14 @@ func (r *IllaDriveConnector) Run(resourceOptions map[string]interface{}, actionO
return res, nil
}

func extractListFileOperationParams(actionOptions map[string]interface{}) (string, int, int, string, string, string, string, string, bool, error) {
func extractListFileOperationParams(actionOptions map[string]interface{}) (string, int, int, string, string, string, string, string, string, bool, error) {
path := "/root"
page := 1
limit := 20
fileID := "" // [OPTIONAL], if fileID given will not use "search" field.
search := "" // [OPTIONAL], search for file name contains
sortedBy := "" // [OPTIONAL], sort result by field
fileID := "" // [OPTIONAL], if fileID given will not use "search" field.
search := "" // [OPTIONAL], search for file name contains
sortedBy := "" // [OPTIONAL], sort result by field
sortedType := "" // [OPTIONAL], sort order
expirationType := "persistent"
expiry := "300s"
hotlinkProtection := true
Expand All @@ -210,60 +211,66 @@ func extractListFileOperationParams(actionOptions map[string]interface{}) (strin
case "path":
valueAsserted, ValueAssertPass := value.(string)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", false, errors.New("field path assert failed")
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field path assert failed")
}
path = valueAsserted
case "page":
valueAsserted, ValueAssertPass := value.(float64)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", false, errors.New("field page assert failed")
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field page assert failed")
}
page = int(valueAsserted)
case "limit":
valueAsserted, ValueAssertPass := value.(float64)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", false, errors.New("field limit assert failed")
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field limit assert failed")
}
limit = int(valueAsserted)
case "fileID":
valueAsserted, ValueAssertPass := value.(string)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", false, errors.New("field fileID assert failed")
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field fileID assert failed")
}
fileID = valueAsserted
case "search":
valueAsserted, ValueAssertPass := value.(string)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", false, errors.New("field search assert failed")
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field search assert failed")
}
search = valueAsserted
case "sortedBy":
valueAsserted, ValueAssertPass := value.(string)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", false, errors.New("field search assert failed")
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field sortedBy assert failed")
}
search = valueAsserted
sortedBy = valueAsserted
case "sortedType":
valueAsserted, ValueAssertPass := value.(string)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field sortedType assert failed")
}
sortedType = valueAsserted
case "expirationType":
valueAsserted, ValueAssertPass := value.(string)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", false, errors.New("field expirationType assert failed")
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field expirationType assert failed")
}
expirationType = valueAsserted
case "expiry":
valueAsserted, ValueAssertPass := value.(string)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", false, errors.New("field expiry assert failed")
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field expiry assert failed")
}
expiry = valueAsserted
case "hotlinkProtection":
valueAsserted, ValueAssertPass := value.(bool)
if !ValueAssertPass {
return "", 0, 0, "", "", "", "", "", false, errors.New("field hotlinkProtection assert failed")
return "", 0, 0, "", "", "", "", "", "", false, errors.New("field hotlinkProtection assert failed")
}
hotlinkProtection = valueAsserted
}
}
return path, page, limit, fileID, search, sortedBy, expirationType, expiry, hotlinkProtection, nil
return path, page, limit, fileID, search, sortedBy, sortedType, expirationType, expiry, hotlinkProtection, nil
}

func extractGetUploadAddressOperationParams(actionOptions map[string]interface{}) (bool, string, string, int64, string, error) {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/illadrivesdk/illa_drive_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *IllaDriveRestAPI) GenerateAccessJWTToken(usage string) (map[string]inte
}, nil
}

func (r *IllaDriveRestAPI) ListFiles(path string, page int, limit int, fileID string, search string, sortedBy string, expirationType string, expiry string, hotlinkProtection bool) (map[string]interface{}, error) {
func (r *IllaDriveRestAPI) ListFiles(path string, page int, limit int, fileID string, search string, sortedBy string, sortedType string, expirationType string, expiry string, hotlinkProtection bool) (map[string]interface{}, error) {
// self-host need skip this method.
if !r.Config.IsCloudMode() {
return nil, nil
Expand Down Expand Up @@ -99,6 +99,9 @@ func (r *IllaDriveRestAPI) ListFiles(path string, page int, limit int, fileID st
if sortedBy != "" {
params += "sortedBy=" + sortedBy + "&"
}
if sortedType != "" {
params += "sortedType=" + sortedType + "&"
}

// get file list
// the HTTP request like:
Expand Down

0 comments on commit 47bc50c

Please sign in to comment.