mirror of
https://github.com/xzeldon/whisper-api-server.git
synced 2024-12-26 05:55:48 +00:00
Ensure the existence of the temp directory in the binary root
This commit is contained in:
parent
b36fe91b5c
commit
482616fb4c
@ -22,9 +22,14 @@ func saveFormFile(name string, c echo.Context) (string, error) {
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
tmpDir, err := ensureDir("tmp")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ext := filepath.Ext(file.Filename)
|
||||
filename := time.Now().Format(time.RFC3339)
|
||||
filename = "./tmp/" + sanitizeFilename(filename) + ext
|
||||
filename = tmpDir + "/" + sanitizeFilename(filename) + ext
|
||||
|
||||
dst, err := os.Create(filename)
|
||||
if err != nil {
|
||||
@ -46,3 +51,14 @@ func sanitizeFilename(filename string) string {
|
||||
}
|
||||
return filename
|
||||
}
|
||||
|
||||
func ensureDir(dirPath string) (string, error) {
|
||||
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
|
||||
err := os.MkdirAll(dirPath, 0700)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
return dirPath, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user