Added an automatic assets folder creator, fixed some naming issues

This commit is contained in:
Nabil Ould Hamou 2024-01-16 18:07:52 +01:00
parent f5738e39f5
commit ff59c394f4
No known key found for this signature in database
GPG key ID: 2B1AE73E9B6014EF
4 changed files with 33 additions and 1 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/assets/
/assets/*
.env

View file

@ -19,7 +19,7 @@ func UploadFile(c *gin.Context) {
}
f := models.File{
Location: path,
FileName: path,
}
result := initializers.DB.Create(&f)

28
initializers/assets.go Normal file
View file

@ -0,0 +1,28 @@
package initializers
import (
"log"
"os"
)
func CreateAssetsFolder() {
if _, err := os.Stat("assets/images"); os.IsNotExist(err) {
if err := os.MkdirAll("assets/images", os.ModePerm); err != nil {
log.Fatal(err)
}
}
if _, err := os.Stat("assets/audios"); os.IsNotExist(err) {
if err := os.MkdirAll("assets/audios", os.ModePerm); err != nil {
log.Fatal(err)
}
}
if _, err := os.Stat("assets/videos"); os.IsNotExist(err) {
if err := os.MkdirAll("assets/videos", os.ModePerm); err != nil {
log.Fatal(err)
}
}
}

View file

@ -11,6 +11,7 @@ import (
func init() {
initializers.LoadEnv()
initializers.CreateAssetsFolder()
initializers.ConnectToDB()
}