MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / put

Method put

drivers/189pc/utils.go:152–195  ·  view source on GitHub ↗
(ctx context.Context, url string, headers map[string]string, sign bool, file io.Reader, isFamily bool)

Source from the content-addressed store, hash-verified

150}
151
152func (y *Cloud189PC) put(ctx context.Context, url string, headers map[string]string, sign bool, file io.Reader, isFamily bool) ([]byte, error) {
153 req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, file)
154 if err != nil {
155 return nil, err
156 }
157
158 query := req.URL.Query()
159 for key, value := range clientSuffix() {
160 query.Add(key, value)
161 }
162 req.URL.RawQuery = query.Encode()
163
164 for key, value := range headers {
165 req.Header.Add(key, value)
166 }
167
168 if sign {
169 for key, value := range y.SignatureHeader(url, http.MethodPut, "", isFamily) {
170 req.Header.Add(key, value)
171 }
172 }
173
174 resp, err := base.HttpClient.Do(req)
175 if err != nil {
176 return nil, err
177 }
178 defer resp.Body.Close()
179
180 body, err := io.ReadAll(resp.Body)
181 if err != nil {
182 return nil, err
183 }
184
185 var erron RespErr
186 _ = jsoniter.Unmarshal(body, &erron)
187 _ = xml.Unmarshal(body, &erron)
188 if erron.HasError() {
189 return nil, &erron
190 }
191 if resp.StatusCode != http.StatusOK {
192 return nil, errors.Errorf("put fail,err:%s", string(body))
193 }
194 return body, nil
195}
196
197func (y *Cloud189PC) getFiles(ctx context.Context, fileId string, isFamily bool) ([]model.Obj, error) {
198 res := make([]model.Obj, 0, 100)

Callers 3

StreamUploadMethod · 0.95
fastUploadMethod · 0.95
OldUploadMethod · 0.95

Calls 8

SignatureHeaderMethod · 0.95
HasErrorMethod · 0.95
clientSuffixFunction · 0.70
AddMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
EncodeMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected