Example #1
0
        private WopiRequest IdentifyFileRequest(HttpRequest httpRequest, PathString path, string accessToken, Features features)
        {
            var fileSegment = path.Value.Substring("/wopi/files/".Length)?.Trim();

            var method = httpRequest.Method;

            _logger?.LogTrace($"Extracted file segment from request path: '{fileSegment ?? "null"}' for method {method ?? "null"}");

            if (string.IsNullOrWhiteSpace(fileSegment))
            {
                return(WopiRequest.EMPTY);
            }

            // NB - Collabora have not implemented support for the X-WOPI-ItemVersion header and so the Version field set in the
            //      CheckFileInfo response does not flow through to those endpoints where it is optional - eg GetFile.
            //      This unfortunately means we have to do some crazy workaround using the fileId, and thus use that to derive
            //      the relevant metadata needed for us to operate correctly.  Hopefully this will prove to be just a temporary
            //      workaround

            if (fileSegment.EndsWith("/contents"))
            {
                var fileId = fileSegment.Substring(0, fileSegment.Length - "/contents".Length)?.Trim() ?? "null";

                _logger?.LogTrace($"Identified 'contents' request.  File Id extracted from url is: '{fileId}'");

                if (string.IsNullOrWhiteSpace(fileId))
                {
                    return(WopiRequest.EMPTY);
                }

                var fileVersion = httpRequest.Headers["X-WOPI-ItemVersion"].FirstOrDefault();

                var file = File.FromId(fileId, fileVersion);

                if (0 == string.Compare("GET", method, StringComparison.OrdinalIgnoreCase))
                {
                    _logger?.LogTrace($"Identified this to be a Get File request");

                    var isEphemeralRedirect = bool.Parse(httpRequest.Query["ephemeral_redirect"].FirstOrDefault() ?? bool.FalseString);

                    if (isEphemeralRedirect)
                    {
                        return(RedirectToFileStoreRequest.With(file, accessToken));
                    }

                    return(GetFileWopiRequest.With(file, accessToken));
                }
                else if (0 == string.Compare("POST", method, StringComparison.OrdinalIgnoreCase))
                {
                    _logger?.LogTrace($"Identified this to be a Save File request");

                    return(PostFileWopiRequest.With(file.Name, accessToken));
                }
                else
                {
                    _logger?.LogTrace($"The request method '{method}' is not supported for path '{path.Value ?? "null"}'");
                }
            }
            else
            {
                var fileId = fileSegment;

                _logger?.LogTrace($"File Id extracted from url is: '{fileId}'.  Attempting to identity request type");

                if (0 == string.Compare("GET", method, StringComparison.OrdinalIgnoreCase))
                {
                    _logger?.LogTrace($"Identified this is a Check File Info request");

                    var file = (File)fileId;

                    return(CheckFileInfoWopiRequest.With(file, accessToken, features));
                }
                else
                {
                    _logger?.LogTrace($"The request method '{method}' is not supported for path '{path.Value ?? "null"}");
                }
            }

            return(WopiRequest.EMPTY);
        }
Example #2
0
        public void With_ThrowsIfAuthenticatedUserIsNull()
        {
            var file = File.FromId(Guid.NewGuid().ToString());

            GetFileWopiRequestHandler.With(default, file);