MCPcopy
hub / github.com/AlistGo/alist / getRawFiles

Function getRawFiles

drivers/halalcloud/util.go:220–267  ·  view source on GitHub ↗
(addr *pubUserFile.SliceDownloadInfo)

Source from the content-addressed store, hash-verified

218}
219
220func getRawFiles(addr *pubUserFile.SliceDownloadInfo) ([]byte, error) {
221
222 if addr == nil {
223 return nil, errors.New("addr is nil")
224 }
225
226 client := http.Client{
227 Timeout: time.Duration(60 * time.Second), // Set timeout to 5 seconds
228 }
229 resp, err := client.Get(addr.DownloadAddress)
230 if err != nil {
231
232 return nil, err
233 }
234 defer resp.Body.Close()
235 body, err := io.ReadAll(resp.Body)
236 if err != nil {
237 return nil, err
238 }
239 if resp.StatusCode != http.StatusOK {
240 return nil, fmt.Errorf("bad status: %s, body: %s", resp.Status, body)
241 }
242
243 if addr.Encrypt > 0 {
244 cd := uint8(addr.Encrypt)
245 for idx := 0; idx < len(body); idx++ {
246 body[idx] = body[idx] ^ cd
247 }
248 }
249
250 if addr.StoreType != 10 {
251
252 sourceCid, err := cid.Decode(addr.Identity)
253 if err != nil {
254 return nil, err
255 }
256 checkCid, err := sourceCid.Prefix().Sum(body)
257 if err != nil {
258 return nil, err
259 }
260 if !checkCid.Equals(sourceCid) {
261 return nil, fmt.Errorf("bad cid: %s, body: %s", checkCid.String(), body)
262 }
263 }
264
265 return body, nil
266
267}
268
269type openObject struct {
270 ctx context.Context

Callers 1

getChunkMethod · 0.85

Calls 5

DecodeMethod · 0.80
GetMethod · 0.65
CloseMethod · 0.65
SumMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected