(c *gin.Context)
| 189 | } |
| 190 | |
| 191 | func SharingDown(c *gin.Context) { |
| 192 | sid := c.Request.Context().Value(conf.SharingIDKey).(string) |
| 193 | path := c.Request.Context().Value(conf.PathKey).(string) |
| 194 | path = utils.FixAndCleanPath(path) |
| 195 | pwd := c.Query("pwd") |
| 196 | s, err := op.GetSharingById(sid) |
| 197 | if err == nil { |
| 198 | if !s.Valid() { |
| 199 | err = errs.InvalidSharing |
| 200 | } else if !s.Verify(pwd) { |
| 201 | err = errs.WrongShareCode |
| 202 | } else if len(s.Files) != 1 && path == "/" { |
| 203 | err = errors.New("cannot get sharing root link") |
| 204 | } |
| 205 | } |
| 206 | if dealErrorPage(c, err) { |
| 207 | return |
| 208 | } |
| 209 | unwrapPath, err := op.GetSharingUnwrapPath(s, path) |
| 210 | if err != nil { |
| 211 | common.ErrorPage(c, errors.New("failed get sharing unwrap path"), 500) |
| 212 | return |
| 213 | } |
| 214 | storage, actualPath, err := op.GetStorageAndActualPath(unwrapPath) |
| 215 | if dealErrorPage(c, err) { |
| 216 | return |
| 217 | } |
| 218 | if setting.GetBool(conf.ShareForceProxy) || common.ShouldProxy(storage, stdpath.Base(actualPath)) { |
| 219 | if _, ok := c.GetQuery("d"); !ok { |
| 220 | if url := common.GenerateDownProxyURL(storage.GetStorage(), unwrapPath); url != "" { |
| 221 | c.Redirect(302, url) |
| 222 | _ = countAccess(c.ClientIP(), s) |
| 223 | return |
| 224 | } |
| 225 | } |
| 226 | link, obj, err := op.Link(c.Request.Context(), storage, actualPath, model.LinkArgs{ |
| 227 | Header: c.Request.Header, |
| 228 | Type: c.Query("type"), |
| 229 | }) |
| 230 | if err != nil { |
| 231 | common.ErrorPage(c, errors.WithMessage(err, "failed get sharing link"), 500) |
| 232 | return |
| 233 | } |
| 234 | _ = countAccess(c.ClientIP(), s) |
| 235 | proxy(c, link, obj, storage.GetStorage().ProxyRange) |
| 236 | } else { |
| 237 | link, _, err := op.Link(c.Request.Context(), storage, actualPath, model.LinkArgs{ |
| 238 | IP: c.ClientIP(), |
| 239 | Header: c.Request.Header, |
| 240 | Type: c.Query("type"), |
| 241 | Redirect: true, |
| 242 | }) |
| 243 | if err != nil { |
| 244 | common.ErrorPage(c, errors.WithMessage(err, "failed get sharing link"), 500) |
| 245 | return |
| 246 | } |
| 247 | _ = countAccess(c.ClientIP(), s) |
| 248 | redirect(c, link) |
nothing calls this directly
no test coverage detected