Add file save and delete api endpoints

This commit is contained in:
2024-09-26 15:34:24 +02:00
parent b2e99fa39e
commit 9faa212043
3 changed files with 53 additions and 0 deletions

View File

@@ -58,3 +58,19 @@ func (fs *FileSystem) GetFileContent(filePath string) ([]byte, error) {
fullPath := filepath.Join(fs.RootDir, filePath)
return os.ReadFile(fullPath)
}
func (fs *FileSystem) SaveFile(filePath string, content []byte) error {
fullPath := filepath.Join(fs.RootDir, filePath)
dir := filepath.Dir(fullPath)
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
return os.WriteFile(fullPath, content, 0644)
}
func (fs *FileSystem) DeleteFile(filePath string) error {
fullPath := filepath.Join(fs.RootDir, filePath)
return os.Remove(fullPath)
}