MCPcopy
hub / github.com/SurgeDM/Surge / AddWithID

Method AddWithID

internal/core/remote_service.go:161–185  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

159
160// AddWithID queues a new download with a caller-provided id.
161func (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.
188func (s *RemoteDownloadService) Pause(id string) error {

Callers

nothing calls this directly

Calls 2

doRequestMethod · 0.95
CloseMethod · 0.45

Tested by

no test coverage detected