MCPcopy Create free account
hub / github.com/ZeStream/zestream-server / Fetch

Function Fetch

utils/fetch.go:17–53  ·  view source on GitHub ↗

* Fetch downlods a file to downloads folder from the given url, and names it as given fileName */

(url string, fileName string)

Source from the content-addressed store, hash-verified

15 if err != nil {
16 return err
17 }
18
19 response, err := http.Get(url)
20 if err != nil {
21 return err
22 }
23
24 defer response.Body.Close()
25
26 if response.StatusCode != 200 {
27 return errors.New(constants.FILE_DOWNLOAD_ERROR + strconv.Itoa(response.StatusCode))
28 }
29
30 // create an empty file
31 file, err := os.Create(newFileName)
32 if err != nil {
33 return err
34 }
35
36 defer file.Close()
37
38 // write the bytes to the file
39 _, err = io.Copy(file, response.Body)
40 if err != nil {
41 return err
42 }
43
44 return nil
45}
46
47func getFileName(fileName string) (string, error) {
48 cwd, err := os.Getwd()
49
50 if err != nil {
51 return "", err
52 }
53
54 newPath := path.Join(cwd, constants.DOWNLOAD_FILE_PATH_PREFIX)
55
56 err = os.MkdirAll(newPath, os.ModePerm)

Callers 2

TestFetchFunction · 0.92
processVideoFunction · 0.92

Calls 2

GetDownloadFilePathNameFunction · 0.85
GetMethod · 0.80

Tested by 1

TestFetchFunction · 0.74