Import logos from challenge.json
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
This commit is contained in:
parent
f4188ec289
commit
11a12e1d44
5 changed files with 81 additions and 27 deletions
|
@ -165,6 +165,26 @@ func getDestinationFilePath(URI string) string {
|
|||
return path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:])), path.Base(URI))
|
||||
}
|
||||
|
||||
func importFile(i Importer, URI string, dest string) error {
|
||||
if err := os.MkdirAll(path.Dir(dest), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write file
|
||||
if fdto, err := os.Create(dest); err != nil {
|
||||
return err
|
||||
} else {
|
||||
defer fdto.Close()
|
||||
writer := bufio.NewWriter(fdto)
|
||||
if err := GetFile(i, URI, writer); err != nil {
|
||||
os.Remove(dest)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ImportFile imports the file at the given URI, using helpers of the given Importer.
|
||||
// After import, next is called with relative path where the file has been saved and the original URI.
|
||||
func ImportFile(i Importer, URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
|
||||
|
@ -177,22 +197,10 @@ func ImportFile(i Importer, URI string, next func(string, string) (interface{},
|
|||
}
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(path.Dir(dest), 0755); err != nil {
|
||||
if err := importFile(i, URI, dest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Write file
|
||||
if fdto, err := os.Create(dest); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer fdto.Close()
|
||||
writer := bufio.NewWriter(fdto)
|
||||
if err := GetFile(i, URI, writer); err != nil {
|
||||
os.Remove(dest)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return next(dest, URI)
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue