Exemple #1
0
 private async Task <WopiResponse> ProcessGetFileRequestAsync(GetFileRequest wopiRequest,
                                                              CancellationToken cancellationToken)
 {
     if (!int.TryParse(wopiRequest.FileId, out var contentId))
     {
         return new WopiResponse {
                    StatusCode = HttpStatusCode.NotFound
         }
     }
     ;
     if (!(await Node.LoadNodeAsync(contentId, cancellationToken).ConfigureAwait(false) is File file))
     {
         return new WopiResponse {
                    StatusCode = HttpStatusCode.NotFound
         }
     }
     ;
     if (!IsPreconditionOk(wopiRequest, file))
     {
         return new WopiResponse {
                    StatusCode = HttpStatusCode.PreconditionFailed
         }
     }
     ;
     return(new GetFileResponse
     {
         StatusCode = HttpStatusCode.OK,
         File = file,
         ContentType = file.Binary.ContentType
     });
 }
Exemple #2
0
 private WopiResponse ProcessGetFileRequest(GetFileRequest wopiReq)
 {
     if (!int.TryParse(wopiReq.FileId, out var contentId))
     {
         return new WopiResponse {
                    StatusCode = HttpStatusCode.NotFound
         }
     }
     ;
     if (!(Node.LoadNode(contentId) is File file))
     {
         return new WopiResponse {
                    StatusCode = HttpStatusCode.NotFound
         }
     }
     ;
     if (!IsPreconditionOk(wopiReq, file))
     {
         return new WopiResponse {
                    StatusCode = HttpStatusCode.PreconditionFailed
         }
     }
     ;
     return(new GetFileResponse
     {
         StatusCode = HttpStatusCode.OK,
         File = file,
         ContentType = file.Binary.ContentType
     });
 }
Exemple #3
0
        private bool IsPreconditionOk(GetFileRequest wopiRequest, File file)
        {
            if (wopiRequest.MaxExpectedSize == null)
            {
                return(true);
            }

            var bigLength = file.Binary.Size;

            if (bigLength > int.MaxValue)
            {
                return(false);
            }

            var length = Convert.ToInt32(bigLength);

            return(wopiRequest.MaxExpectedSize.Value >= length);
        }