maj
This commit is contained in:
parent
561649d325
commit
4dd0484b80
@ -2,6 +2,7 @@ package library
|
||||
|
||||
import (
|
||||
"app/shelfly/internal/models"
|
||||
"app/shelfly/query"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -12,12 +13,11 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func ScanFolder(db *gorm.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@ -42,10 +42,8 @@ func ScanFolder(db *gorm.DB)http.HandlerFunc {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
|
||||
fmt.Printf("dir: %v: name: %s\n", info.IsDir(), path)
|
||||
if(!info.IsDir()){
|
||||
if !info.IsDir() {
|
||||
//log.Fatalf("Lancement get info")
|
||||
|
||||
fmt.Printf("%s", info.Name()+"\n")
|
||||
@ -81,7 +79,7 @@ func ScanFolder(db *gorm.DB)http.HandlerFunc {
|
||||
// overview := movie["overview"]
|
||||
|
||||
//fmt.Printf("Titre: %v, Date de sortie: %v, Résumé: %v\n", title, releaseDate, overview)
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -152,11 +150,9 @@ func ScanFolder(db *gorm.DB)http.HandlerFunc {
|
||||
}
|
||||
fmt.Println("Film inserted successfully!")
|
||||
|
||||
|
||||
}
|
||||
// api
|
||||
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@ -182,3 +178,30 @@ func cleanMovieName(filename string) string {
|
||||
|
||||
return filename
|
||||
}
|
||||
func CreateDefaultFolder(db *gorm.DB) {
|
||||
folders := []string{"Film", "Série", "Manga"}
|
||||
|
||||
for _, name := range folders {
|
||||
path := "upload/" + name
|
||||
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
err := os.MkdirAll(path, 0755) // MkdirAll au cas où des dossiers parents manquent
|
||||
if err != nil {
|
||||
fmt.Printf("Erreur lors de la création du dossier %s : %v\n", path, err)
|
||||
} else {
|
||||
pathDownload := models.PathDownload{
|
||||
Path: path,
|
||||
PathName: name,
|
||||
}
|
||||
q := query.Use(db)
|
||||
if err := q.PathDownload.Create(&pathDownload); err != nil {
|
||||
fmt.Printf(`{"error": "Failed to create path"}`, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Dossier créé : %s\n", path)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Dossier déjà existant : %s\n", path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
main.go
4
main.go
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"app/shelfly/handlers"
|
||||
"app/shelfly/internal/db"
|
||||
"app/shelfly/internal/library"
|
||||
"app/shelfly/internal/route"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -17,6 +18,9 @@ func main() {
|
||||
// 2. Initialiser la DB
|
||||
bd := db.InitDB()
|
||||
|
||||
// 2.1
|
||||
library.CreateDefaultFolder(bd)
|
||||
|
||||
// 3. Routes non protégées : on les monte sur le routeur principal
|
||||
route.RoutesPublic(r, bd)
|
||||
|
||||
|
||||
BIN
shelfly_db.db
BIN
shelfly_db.db
Binary file not shown.
13
todo.tx
13
todo.tx
@ -30,3 +30,16 @@ docker compose -f docker-compose.yml -f docker-compose.prod.yml up --build
|
||||
clean
|
||||
|
||||
docker system prune -a --volumes
|
||||
|
||||
|
||||
Loop golang
|
||||
|
||||
func main() {
|
||||
// Declare an array of integers
|
||||
var numbers = [5]int{1, 2, 3, 4, 5}
|
||||
|
||||
// Loop over the array and print each element
|
||||
for _, number := range numbers {
|
||||
fmt.Println(number)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user