MCPcopy Create free account
hub / github.com/OpenSN-Library/OpenSN-Library / DownloadFileHandler

Function DownloadFileHandler

daemon/pkg/handler/file_handler.go:172–203  ·  view source on GitHub ↗
(ctx *gin.Context)

Source from the content-addressed store, hash-verified

170}
171
172func DownloadFileHandler(ctx *gin.Context) {
173 relativePath := ctx.Query("path")
174 downloadPath := path.Join(dir.UserDataDir, relativePath)
175
176 fileStat, err := os.Stat(downloadPath)
177
178 if err != nil {
179 errMsg := fmt.Sprintf("Locate Download File %s Error: %s", relativePath, err.Error())
180 logrus.Error(errMsg)
181 resp := ginmodel.JsonResp{
182 Code: -1,
183 Message: errMsg,
184 Data: nil,
185 }
186 ctx.JSON(http.StatusInternalServerError, resp)
187 return
188 }
189
190 if fileStat.IsDir() {
191 errMsg := "Download File Error: cannot download a dir"
192 logrus.Error(errMsg)
193 resp := ginmodel.JsonResp{
194 Code: -1,
195 Message: errMsg,
196 Data: nil,
197 }
198 ctx.JSON(http.StatusBadRequest, resp)
199 return
200 }
201
202 ctx.File(downloadPath)
203}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected