(ctx *gin.Context)
| 170 | } |
| 171 | |
| 172 | func 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected