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

Method Add

internal/core/remote_service.go:134–158  ·  view source on GitHub ↗

Add queues a new download.

(url string, path string, filename string, mirrors []string, headers map[string]string, isExplicitCategory bool, totalSize int64, supportsRange bool)

Source from the content-addressed store, hash-verified

132
133// Add queues a new download.
134func (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.
161func (s *RemoteDownloadService) AddWithID(url string, path string, filename string, mirrors []string, headers map[string]string, id string, totalSize int64, supportsRange bool) (string, error) {

Callers

nothing calls this directly

Calls 2

doRequestMethod · 0.95
CloseMethod · 0.45

Tested by

no test coverage detected