add retardcheck to zipstream

This commit is contained in:
Cyberes 2024-03-25 15:42:54 -06:00
parent ced920ceb9
commit 6001894b0b
2 changed files with 8 additions and 8 deletions

View File

@ -10,19 +10,18 @@ import (
"path/filepath" "path/filepath"
) )
func ZipHandlerCompress(dirPath string, w http.ResponseWriter, r *http.Request) { func ZipHandlerCompress(fullPath string, w http.ResponseWriter, r *http.Request) {
file.RetardCheck(fullPath)
w.Header().Set("Content-Type", "application/zip") w.Header().Set("Content-Type", "application/zip")
//w.WriteHeader(http.StatusOK)
zipWriter := kzip.NewWriter(w) zipWriter := kzip.NewWriter(w)
// queuedwalk through the directory and add each file to the zip // Walk through the directory and add each file to the zip
filepath.Walk(dirPath, func(filePath string, info os.FileInfo, err error) error { filepath.Walk(fullPath, func(filePath string, info os.FileInfo, err error) error {
if info.IsDir() { if info.IsDir() {
return nil return nil
} }
// Ensure the file path is relative to the directory being zipped // Ensure the file path is relative to the directory being zipped
relativePath, err := filepath.Rel(dirPath, filePath) relativePath, err := filepath.Rel(fullPath, filePath)
if err != nil { if err != nil {
return err return err
} }
@ -49,8 +48,9 @@ func ZipHandlerCompress(dirPath string, w http.ResponseWriter, r *http.Request)
} }
func ZipHandlerCompressMultiple(paths []string, w http.ResponseWriter, r *http.Request) { func ZipHandlerCompressMultiple(paths []string, w http.ResponseWriter, r *http.Request) {
zipWriter := kzip.NewWriter(w) zipWriter := kzip.NewWriter(w)
// queuedwalk through each file and add it to the zip // Walk through each file and add it to the zip
for _, fullPath := range paths { for _, fullPath := range paths {
file.RetardCheck(fullPath)
relPath := file.StripRootDir(fullPath) relPath := file.StripRootDir(fullPath)
// Try to get the data from the cache // Try to get the data from the cache

View File

@ -44,7 +44,7 @@ func APIDownload(w http.ResponseWriter, r *http.Request) {
cleanPaths = append(cleanPaths, cleanPath) cleanPaths = append(cleanPaths, cleanPath)
} }
// Multiple files, zip them // Multiple files, zip them.
helpers.ZipHandlerCompressMultiple(cleanPaths, w, r) helpers.ZipHandlerCompressMultiple(cleanPaths, w, r)
return return
} }