@@ -1957,6 +1957,8 @@ func HandleDownloadRemoteFiles(resp http.ResponseWriter, request *http.Request)
19571957 Field2 string `json:"field_2"` // Password
19581958 Field3 string `json:"field_3"` // Branch
19591959 Path string `json:"path"`
1960+
1961+ Namespace string `json:"namespace"`
19601962 }
19611963
19621964 var input tmpStruct
@@ -1983,14 +1985,30 @@ func HandleDownloadRemoteFiles(resp http.ResponseWriter, request *http.Request)
19831985 repo := ""
19841986 path := input .Path
19851987
1988+ treeIndex := - 1
1989+ newPath := ""
19861990 for cnt , item := range urlSplit [3 :] {
1991+ // Auto parsing url
1992+ if item == "tree" && treeIndex == - 1 && cnt > 1 {
1993+ treeIndex = cnt
1994+ }
1995+
19871996 if cnt == 0 {
19881997 owner = item
19891998 } else if cnt == 1 {
19901999 repo = item
2000+ } else {
2001+ if treeIndex != - 1 && (path == "" || path == "/" ) && cnt > treeIndex + 1 {
2002+ newPath = fmt .Sprintf ("%s/%s" , newPath , item )
2003+ }
19912004 }
19922005 }
19932006
2007+ if len (newPath ) > 0 {
2008+ newPath = strings .TrimPrefix (newPath , "/" )
2009+ path = newPath
2010+ }
2011+
19942012 log .Printf ("[DEBUG] Loading standard with git: %s/%s/%s" , owner , repo , path )
19952013 files , err := LoadStandardFromGithub (client , owner , repo , path , "" )
19962014 if err != nil {
@@ -2006,13 +2024,21 @@ func HandleDownloadRemoteFiles(resp http.ResponseWriter, request *http.Request)
20062024 files = files [:50 ]
20072025 }
20082026
2027+ // Expects them in the root level... hmm
2028+ // FIXME: Recurse
20092029 for _ , item := range files {
2030+ log .Printf ("[DEBUG] Downloading standard file %s" , * item .Path )
20102031 fileContent , _ , _ , err := client .Repositories .GetContents (ctx , owner , repo , * item .Path , nil )
20112032 if err != nil {
20122033 log .Printf ("[ERROR] Failed getting file %s: %s" , * item .Path , err )
20132034 continue
20142035 }
20152036
2037+ if fileContent == nil || fileContent .Content == nil {
2038+ log .Printf ("[ERROR] No content in file %s" , * item .Path )
2039+ continue
2040+ }
2041+
20162042 // Get the bytes of the file
20172043 decoded , err := base64 .StdEncoding .DecodeString (* fileContent .Content )
20182044 if err != nil {
@@ -2038,12 +2064,17 @@ func HandleDownloadRemoteFiles(resp http.ResponseWriter, request *http.Request)
20382064 DownloadPath : downloadPath ,
20392065 Subflows : []string {},
20402066 StorageArea : "local" ,
2041- Namespace : path ,
2067+ Namespace : strings . ReplaceAll ( strings . ReplaceAll ( path , "/" , "_" ), ".." , "_" ) ,
20422068 Tags : []string {
2043- "standard" ,
2069+ input .URL ,
2070+ path ,
20442071 },
20452072 }
20462073
2074+ if len (input .Namespace ) > 0 {
2075+ file .Namespace = input .Namespace
2076+ }
2077+
20472078 if project .Environment == "cloud" {
20482079 file .StorageArea = "google_storage"
20492080 }
0 commit comments