Spaces:
Paused
Paused
Update main.go
Browse files
main.go
CHANGED
|
@@ -160,33 +160,28 @@ func unrarSource(source, dest string) error {
|
|
| 160 |
cmd := exec.Command("unrar", "x", "-y", source, dest+string(os.PathSeparator))
|
| 161 |
return cmd.Run()
|
| 162 |
}
|
| 163 |
-
|
| 164 |
-
// --- Download & Zip Logic ---
|
| 165 |
func downloadFile(url string, customName string, destFolder string) (string, error) {
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
return finalPath, err
|
| 188 |
-
}
|
| 189 |
-
|
| 190 |
|
| 191 |
filename = filepath.Base(filename)
|
| 192 |
finalPath := filepath.Join(destFolder, filename)
|
|
@@ -198,7 +193,6 @@ func downloadFile(url string, customName string, destFolder string) (string, err
|
|
| 198 |
_, err = io.Copy(out, resp.Body)
|
| 199 |
return finalPath, err
|
| 200 |
}
|
| 201 |
-
|
| 202 |
func zipFile(sourcePath string, destFolder string) (string, error) {
|
| 203 |
filename := filepath.Base(sourcePath)
|
| 204 |
zipName := fmt.Sprintf("%s_%s.zip", strings.TrimSuffix(filename, filepath.Ext(filename)), uuid.New().String()[:8])
|
|
|
|
| 160 |
cmd := exec.Command("unrar", "x", "-y", source, dest+string(os.PathSeparator))
|
| 161 |
return cmd.Run()
|
| 162 |
}
|
|
|
|
|
|
|
| 163 |
func downloadFile(url string, customName string, destFolder string) (string, error) {
|
| 164 |
+
resp, err := http.Get(url)
|
| 165 |
+
if err != nil {
|
| 166 |
+
return "", err
|
| 167 |
+
}
|
| 168 |
+
defer resp.Body.Close()
|
| 169 |
+
|
| 170 |
+
filename := customName
|
| 171 |
+
if filename == "" {
|
| 172 |
+
if cd := resp.Header.Get("Content-Disposition"); cd != "" {
|
| 173 |
+
_, params, err := mime.ParseMediaType(cd)
|
| 174 |
+
if err == nil {
|
| 175 |
+
filename = params["filename"]
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
if filename == "" {
|
| 179 |
+
filename = filepath.Base(resp.Request.URL.Path)
|
| 180 |
+
}
|
| 181 |
+
if filename == "" || filename == "." || filename == "/" {
|
| 182 |
+
filename = "download_" + uuid.New().String()
|
| 183 |
+
}
|
| 184 |
+
}
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
filename = filepath.Base(filename)
|
| 187 |
finalPath := filepath.Join(destFolder, filename)
|
|
|
|
| 193 |
_, err = io.Copy(out, resp.Body)
|
| 194 |
return finalPath, err
|
| 195 |
}
|
|
|
|
| 196 |
func zipFile(sourcePath string, destFolder string) (string, error) {
|
| 197 |
filename := filepath.Base(sourcePath)
|
| 198 |
zipName := fmt.Sprintf("%s_%s.zip", strings.TrimSuffix(filename, filepath.Ext(filename)), uuid.New().String()[:8])
|