uploadCallbackCheck 对上传回调请求的 callback key 进行验证,如果成功则返回上传用户
(c *gin.Context, policyType types.PolicyType)
| 191 | |
| 192 | // uploadCallbackCheck 对上传回调请求的 callback key 进行验证,如果成功则返回上传用户 |
| 193 | func uploadCallbackCheck(c *gin.Context, policyType types.PolicyType) error { |
| 194 | // 验证 Callback Key |
| 195 | sessionID := c.Param("sessionID") |
| 196 | if sessionID == "" { |
| 197 | return serializer.NewError(serializer.CodeParamErr, "Session ID cannot be empty", nil) |
| 198 | } |
| 199 | |
| 200 | dep := dependency.FromContext(c) |
| 201 | callbackSessionRaw, exist := dep.KV().Get(manager.UploadSessionCachePrefix + sessionID) |
| 202 | if !exist { |
| 203 | return serializer.NewError(serializer.CodeUploadSessionExpired, "Upload session does not exist or expired", nil) |
| 204 | } |
| 205 | |
| 206 | callbackSession := callbackSessionRaw.(fs.UploadSession) |
| 207 | c.Set(manager.UploadSessionCtx, &callbackSession) |
| 208 | if callbackSession.Policy.Type != string(policyType) { |
| 209 | return serializer.NewError(serializer.CodePolicyNotAllowed, "", nil) |
| 210 | } |
| 211 | |
| 212 | if err := SetUserCtx(c, callbackSession.UID); err != nil { |
| 213 | return err |
| 214 | } |
| 215 | |
| 216 | return nil |
| 217 | } |
| 218 | |
| 219 | // RemoteCallbackAuth 远程回调签名验证 |
| 220 | func RemoteCallbackAuth() gin.HandlerFunc { |
no test coverage detected