Skip to content

Commit

Permalink
fix(trainbit): remove unnecessary operation (#3881)
Browse files Browse the repository at this point in the history
  • Loading branch information
NightSpaceC authored Mar 18, 2023
1 parent 8b109cf commit 0231072
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
2 changes: 1 addition & 1 deletion drivers/trainbit/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (d *Trainbit) Put(ctx context.Context, dstDir model.Obj, stream model.FileS
query := &url.Values{}
query.Add("q", strings.Split(dstDir.GetID(), "_")[1])
query.Add("guid", guid)
query.Add("name", url.QueryEscape(local2provider(stream.GetName(), false)))
query.Add("name", url.QueryEscape(local2provider(stream.GetName(), false) + "."))
endpoint.RawQuery = query.Encode()
var total int64
total = 0
Expand Down
26 changes: 4 additions & 22 deletions drivers/trainbit/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,36 +88,18 @@ func getToken(apiKey string, AUSHELLPORTAL string) (string, string, error) {
}

func local2provider(filename string, isFolder bool) string {
filename = strings.Replace(filename, "%", url.QueryEscape("%"), -1)
filename = strings.Replace(filename, "/", url.QueryEscape("/"), -1)
filename = strings.Replace(filename, ":", url.QueryEscape(":"), -1)
filename = strings.Replace(filename, "*", url.QueryEscape("*"), -1)
filename = strings.Replace(filename, "?", url.QueryEscape("?"), -1)
filename = strings.Replace(filename, "\"", url.QueryEscape("\""), -1)
filename = strings.Replace(filename, "<", url.QueryEscape("<"), -1)
filename = strings.Replace(filename, ">", url.QueryEscape(">"), -1)
filename = strings.Replace(filename, "|", url.QueryEscape("|"), -1)
if isFolder {
return filename
}
return strings.Join([]string{filename, ".delete_suffix."}, "")
return filename + ".delete_suffix"
}

func provider2local(filename string) string {
index := strings.LastIndex(filename, ".delete_suffix.")
index := strings.LastIndex(filename, ".delete_suffix")
if index != -1 {
filename = filename[:index]
}
rawName := strings.Replace(filename, url.QueryEscape("/"), "/", -1)
rawName = strings.Replace(rawName, url.QueryEscape(":"), ":", -1)
rawName = strings.Replace(rawName, url.QueryEscape("*"), "*", -1)
rawName = strings.Replace(rawName, url.QueryEscape("?"), "?", -1)
rawName = strings.Replace(rawName, url.QueryEscape("\""), "\"", -1)
rawName = strings.Replace(rawName, url.QueryEscape("<"), "<", -1)
rawName = strings.Replace(rawName, url.QueryEscape(">"), ">", -1)
rawName = strings.Replace(rawName, url.QueryEscape("|"), "|", -1)
rawName = strings.Replace(rawName, url.QueryEscape("%"), "%", -1)
return rawName
return filename
}

func parseRawFileObject(rawObject []any) ([]model.Obj, error) {
Expand All @@ -132,7 +114,7 @@ func parseRawFileObject(rawObject []any) ([]model.Obj, error) {
if isFolder {
name = object["name"].(string)
} else {
name = strings.Join([]string{object["name"].(string), object["ext"].(string)}, ".")
name = object["name"].(string) + object["ext"].(string)
}
modified, err := time.Parse("2006/01/02 15:04:05", object["modified"].(string))
if err != nil {
Expand Down

0 comments on commit 0231072

Please sign in to comment.