Add queues a new download.
(url string, path string, filename string, mirrors []string, headers map[string]string, isExplicitCategory bool, totalSize int64, supportsRange bool)
| 132 | |
| 133 | // Add queues a new download. |
| 134 | func (s *RemoteDownloadService) Add(url string, path string, filename string, mirrors []string, headers map[string]string, isExplicitCategory bool, totalSize int64, supportsRange bool) (string, error) { |
| 135 | req := map[string]interface{}{ |
| 136 | "url": url, |
| 137 | "path": path, |
| 138 | "filename": filename, |
| 139 | "mirrors": mirrors, |
| 140 | "headers": headers, |
| 141 | "skip_approval": true, |
| 142 | "is_explicit_category": isExplicitCategory, |
| 143 | "total_size": totalSize, |
| 144 | "supports_range": supportsRange, |
| 145 | } |
| 146 | |
| 147 | resp, err := s.doRequest("POST", "/download", req) |
| 148 | if err != nil { |
| 149 | return "", err |
| 150 | } |
| 151 | defer func() { _, _ = io.Copy(io.Discard, resp.Body); _ = resp.Body.Close() }() |
| 152 | |
| 153 | var result map[string]string |
| 154 | if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { |
| 155 | return "", err |
| 156 | } |
| 157 | return result["id"], nil |
| 158 | } |
| 159 | |
| 160 | // AddWithID queues a new download with a caller-provided id. |
| 161 | func (s *RemoteDownloadService) AddWithID(url string, path string, filename string, mirrors []string, headers map[string]string, id string, totalSize int64, supportsRange bool) (string, error) { |