UP ADD ZIP RAR

This commit is contained in:
julien 2025-06-26 11:11:21 +02:00
parent 0432f64306
commit 8f98bf7a39
2 changed files with 70 additions and 5 deletions

View File

@ -1,7 +1,8 @@
FROM golang:1.24-bullseye
# Installer ffmpeg et air
# Installer ffmpeg, curl, unrar et air
RUN apt-get update && \
apt-get install -y ffmpeg curl && \
apt-get install -y ffmpeg curl unrar && \
curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b /usr/local/bin && \
apt-get clean && rm -rf /var/lib/apt/lists/*
@ -13,4 +14,4 @@ RUN go mod download
COPY . .
# Lancer Air avec le bon chemin
CMD ["air", "-c", ".air.toml"]
CMD ["air", "-c", ".air.toml"]

View File

@ -14,7 +14,7 @@ import (
"strings"
"sync"
"time"
"archive/zip"
"gorm.io/gorm"
)
@ -274,8 +274,30 @@ func StartDownload(job *DownloadJob, downloadURL string, client *debridlink.Clie
part.Close()
os.Remove(tmpPath)
}
UpdateJobProgress(job.ID, 100, db)
ext := strings.ToLower(filepath.Ext(finalPath))
videoExts := map[string]bool{".mkv": true, ".avi": true, ".mp4": true}
if !videoExts[ext] {
switch ext {
case ".zip":
if err := unzip(finalPath, path.Path); err != nil {
log.Printf("[ERROR] Décompression ZIP échouée : %v\n", err)
UpdateJobStatus(job.ID, "failed", db)
return
}
case ".rar":
if err := unrarExtract(finalPath, path.Path); err != nil {
log.Printf("[ERROR] Décompression RAR échouée : %v\n", err)
UpdateJobStatus(job.ID, "failed", db)
return
}
default:
log.Printf("[INFO] Extension non gérée : %s\n", ext)
}
}
UpdateJobStatus(job.ID, "done", db)
log.Printf("[OK] Fichier téléchargé : %s\n", finalPath)
}
@ -452,4 +474,46 @@ func Broadcast() {
}
}
}
func unzip(srcZip, destDir string) error {
r, err := zip.OpenReader(srcZip)
if err != nil {
return err
}
defer r.Close()
for _, f := range r.File {
fpath := filepath.Join(destDir, f.Name)
if f.FileInfo().IsDir() {
os.MkdirAll(fpath, os.ModePerm)
continue
}
if err := os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil {
return err
}
in, err := f.Open()
if err != nil {
return err
}
defer in.Close()
out, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
return err
}
defer out.Close()
if _, err := io.Copy(out, in); err != nil {
return err
}
}
return nil
}
func unrarExtract(srcRar, destDir string) error {
cmd := exec.Command("unrar", "x", "-y", srcRar, destDir)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("unrar error: %v, output: %s", err, string(output))
}
return nil
}
//***//