Files
cardverse-be/internal/pkg/utils/file.go

29 lines
621 B
Go
Raw Normal View History

2026-07-30 09:51:25 +07:00
package utils
import (
"os"
"path/filepath"
"strings"
)
// DeleteLocalFile menghapus file lokal jika file tersebut berada di folder ./public
func DeleteLocalFile(relPath string) {
if relPath == "" || strings.HasPrefix(relPath, "http://") || strings.HasPrefix(relPath, "https://") {
return
}
cleaned := filepath.Clean(relPath)
var localPath string
if strings.HasPrefix(cleaned, "/images/") {
localPath = "./public" + cleaned
} else if strings.HasPrefix(cleaned, "/public/") {
localPath = "." + cleaned
} else {
return
}
if _, err := os.Stat(localPath); err == nil {
_ = os.Remove(localPath)
}
}