add retardcheck to zipstream
This commit is contained in:
parent
ced920ceb9
commit
6001894b0b
|
@ -10,19 +10,18 @@ import (
|
|||
"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.WriteHeader(http.StatusOK)
|
||||
|
||||
zipWriter := kzip.NewWriter(w)
|
||||
// queuedwalk through the directory and add each file to the zip
|
||||
filepath.Walk(dirPath, func(filePath string, info os.FileInfo, err error) error {
|
||||
// Walk through the directory and add each file to the zip
|
||||
filepath.Walk(fullPath, func(filePath string, info os.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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) {
|
||||
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 {
|
||||
file.RetardCheck(fullPath)
|
||||
relPath := file.StripRootDir(fullPath)
|
||||
|
||||
// Try to get the data from the cache
|
||||
|
|
|
@ -44,7 +44,7 @@ func APIDownload(w http.ResponseWriter, r *http.Request) {
|
|||
cleanPaths = append(cleanPaths, cleanPath)
|
||||
}
|
||||
|
||||
// Multiple files, zip them
|
||||
// Multiple files, zip them.
|
||||
helpers.ZipHandlerCompressMultiple(cleanPaths, w, r)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue