From 47bc50c4c6831d2be54654035eab80bb5cff7b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=97=AD=E7=BA=A2=20=28karminski-=E7=89=99?= =?UTF-8?q?=E5=8C=BB=29?= Date: Tue, 20 Feb 2024 18:01:39 +0800 Subject: [PATCH] ADD sorted type field. --- src/actionruntime/illadrive/services.go | 41 ++++++++++++++---------- src/utils/illadrivesdk/illa_drive_api.go | 5 ++- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/actionruntime/illadrive/services.go b/src/actionruntime/illadrive/services.go index d2527a57..2e1b63a0 100644 --- a/src/actionruntime/illadrive/services.go +++ b/src/actionruntime/illadrive/services.go @@ -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 } @@ -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 @@ -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) { diff --git a/src/utils/illadrivesdk/illa_drive_api.go b/src/utils/illadrivesdk/illa_drive_api.go index 1d148398..8abc6f60 100644 --- a/src/utils/illadrivesdk/illa_drive_api.go +++ b/src/utils/illadrivesdk/illa_drive_api.go @@ -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 @@ -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: