AddWithID queues a new download with a caller-provided id.
(url string, path string, filename string, mirrors []string, headers map[string]string, id string, totalSize int64, supportsRange bool)
| 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) { |
| 162 | req := map[string]interface{}{ |
| 163 | "url": url, |
| 164 | "path": path, |
| 165 | "filename": filename, |
| 166 | "mirrors": mirrors, |
| 167 | "headers": headers, |
| 168 | "skip_approval": true, |
| 169 | "id": id, |
| 170 | "total_size": totalSize, |
| 171 | "supports_range": supportsRange, |
| 172 | } |
| 173 | |
| 174 | resp, err := s.doRequest("POST", "/download", req) |
| 175 | if err != nil { |
| 176 | return "", err |
| 177 | } |
| 178 | defer func() { _, _ = io.Copy(io.Discard, resp.Body); _ = resp.Body.Close() }() |
| 179 | |
| 180 | var result map[string]string |
| 181 | if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { |
| 182 | return "", err |
| 183 | } |
| 184 | return result["id"], nil |
| 185 | } |
| 186 | |
| 187 | // Pause pauses an active download. |
| 188 | func (s *RemoteDownloadService) Pause(id string) error { |