From ba85d0bcad07b2a455febcc53c3537bb9b1485ea Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 21 Feb 2024 23:40:25 +0100 Subject: [PATCH] feat(upload-api): do not display error if uploadedFiles.json is not present Signed-off-by: Ettore Di Giacinto --- api/openai/files.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/api/openai/files.go b/api/openai/files.go index 57f5c48d4147..140b41519407 100644 --- a/api/openai/files.go +++ b/api/openai/files.go @@ -17,6 +17,8 @@ import ( var uploadedFiles []File +const uploadedFilesFile = "uploadedFiles.json" + // File represents the structure of a file object from the OpenAI API. type File struct { ID string `json:"id"` // Unique identifier for the file @@ -33,14 +35,22 @@ func saveUploadConfig(uploadDir string) { log.Error().Msgf("Failed to JSON marshal the uploadedFiles: %s", err) } - err = os.WriteFile(filepath.Join(uploadDir, "uploadedFiles.json"), file, 0644) + err = os.WriteFile(filepath.Join(uploadDir, uploadedFilesFile), file, 0644) if err != nil { log.Error().Msgf("Failed to save uploadedFiles to file: %s", err) } } func LoadUploadConfig(uploadPath string) { - file, err := os.ReadFile(filepath.Join(uploadPath, "uploadedFiles.json")) + uploadFilePath := filepath.Join(uploadPath, uploadedFilesFile) + + _, err := os.Stat(uploadFilePath) + if os.IsNotExist(err) { + log.Debug().Msgf("No uploadedFiles file found at %s", uploadFilePath) + return + } + + file, err := os.ReadFile(uploadFilePath) if err != nil { log.Error().Msgf("Failed to read file: %s", err) } else {