Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@
<GroupDocsViewerUICloudApi>8.0.4</GroupDocsViewerUICloudApi>
</PropertyGroup>

<PropertyGroup Label="NuGet Common Settings">
<PackageReleaseNotes>https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET-UI/releases/tag/$(GroupDocsViewerUI)</PackageReleaseNotes>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
});
endpoints.MapGroupDocsViewerUI(options =>
{
options.UIPath = "/viewer";
options.ApiEndpoint = "https://localhost:5001/viewer-api";
options.UIPath = "/document-viewer";
options.ApiEndpoint = "https://localhost:5001/document-viewer-api";
});
});

Expand Down
16 changes: 8 additions & 8 deletions samples/GroupDocs.Viewer.UI.SelfHost.Api.App.Sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,35 +144,35 @@ <h1>UI and API hosted in two apps</h1>

<ul>
<li>
<a href="/viewer/?file=annual-review.docx">annual-review.docx</a>
<a href="/document-viewer/?file=annual-review.docx">annual-review.docx</a>
<div class="description">This is a sample Word document with text and images.</div>
</li>
<li>
<a href="/viewer/?file=basic-presentation.pptx">basic-presentation.pptx</a>
<a href="/document-viewer/?file=basic-presentation.pptx">basic-presentation.pptx</a>
<div class="description">This is a sample PowerPoint presentation.</div>
</li>
<li>
<a href="/viewer/?file=compressed.zip">compressed.zip</a>
<a href="/document-viewer/?file=compressed.zip">compressed.zip</a>
<div class="description">The ZIP archive with multiple files.</div>
</li>
<li>
<a href="/viewer/?file=cost-analysis.xlsx">cost-analysis.xlsx</a>
<a href="/document-viewer/?file=cost-analysis.xlsx">cost-analysis.xlsx</a>
<div class="description">This is Excel spreadsheet with one worksheet.</div>
</li>
<li>
<a href="/viewer/?file=infographic-elements.tiff">infographic-elements.tiff</a>
<a href="/document-viewer/?file=infographic-elements.tiff">infographic-elements.tiff</a>
<div class="description">This is TIFF image with 3 frames.</div>
</li>
<li>
<a href="/viewer/?file=invitation.eml">invitation.eml</a>
<a href="/document-viewer/?file=invitation.eml">invitation.eml</a>
<div class="description">This is a sample email message.</div>
</li>
<li>
<a href="/viewer/?file=password-is-12345.docx">password-is-12345.docx</a>
<a href="/document-viewer/?file=password-is-12345.docx">password-is-12345.docx</a>
<div class="description">This is a password-protected Word document. Password: 12345.</div>
</li>
<li>
<a href="/viewer/?file=professional-services.pdf">professional-services.pdf</a>
<a href="/document-viewer/?file=professional-services.pdf">professional-services.pdf</a>
<div class="description">This is a sample PDF document.</div>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

//Trial limitations https://docs.groupdocs.com/viewer/net/evaluation-limitations-and-licensing-of-groupdocs-viewer/
//Temporary license can be requested at https://purchase.groupdocs.com/temporary-license
//config.SetLicensePath("GroupDocs.Viewer.lic"); // or set environment variable 'GROUPDOCS_LIC_PATH'
//config.SetLicensePath("c://Licenses//GroupDocs.Viewer.lic"); // or set environment variable 'GROUPDOCS_LIC_PATH'
})
.AddLocalStorage("./Files")
.AddLocalCache("./Cache");
Expand All @@ -53,7 +53,7 @@

endpoints.MapGroupDocsViewerApi(options =>
{
options.ApiPath = "/viewer-api";
options.ApiPath = "/document-viewer-api";
options.ApiDomain = "https://localhost:5001";
});
});
Expand Down
14 changes: 14 additions & 0 deletions src/GroupDocs.Viewer.UI.API/Configuration/IOptionsProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace GroupDocs.Viewer.UI.Api.Configuration
{
/// <summary>
/// This interface is used as a workaround to the issue where API does not now about ApiDomain and ApiPath.
/// See related implementation that uses Singleton to make Options object kind of `static` but accesible as
/// a service using service provider.
/// </summary>
public interface IOptionsProvider
{
Options GetOptions();

void SetOptions(Options options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace GroupDocs.Viewer.UI.Api.Configuration.Implementation
{
public class InMemoryOptionsProvider : IOptionsProvider
{
private Options _options;

public Options GetOptions()
{
return _options;
}

public void SetOptions(Options options)
{
_options = options;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ public static IEndpointConventionBuilder MapGroupDocsViewerApi(this IEndpointRou
var options = new Options();
setupOptions?.Invoke(options);

var service = builder.ServiceProvider.GetService(typeof(IOptionsProvider));
if (service != null)
{
var optionsService = (IOptionsProvider)service;
{
optionsService.SetOptions(options);
}
}

EnsureValidApiOptions(options);

MapControllerRoutes(builder, options);
Expand Down
21 changes: 10 additions & 11 deletions src/GroupDocs.Viewer.UI.API/Utils/ApiUrlBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Web;
using System;
Expand All @@ -9,57 +8,57 @@ namespace GroupDocs.Viewer.UI.Api.Utils
public class ApiUrlBuilder : IApiUrlBuilder
{
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IOptions<Configuration.Options> _options;
private readonly Configuration.Options _options;

public ApiUrlBuilder(
IHttpContextAccessor httpContextAccessor,
IOptions<Configuration.Options> options)
Configuration.IOptionsProvider optionsProvider)
{
_httpContextAccessor = httpContextAccessor;
_options = options;
_options = optionsProvider.GetOptions();
}

public string GetApiDomainOrDefault()
{
var request = _httpContextAccessor.HttpContext.Request;

return string.IsNullOrEmpty(_options.Value.ApiDomain)
return string.IsNullOrEmpty(_options.ApiDomain)
? $"{request.Scheme}://{request.Host}"
: _options.Value.ApiDomain;
: _options.ApiDomain;
}

public string BuildPageUrl(string file, int page, string extension) =>
BuildUrl(
apiDomain: GetApiDomainOrDefault(),
apiPath: _options.Value.ApiPath,
apiPath: _options.ApiPath,
apiMethodName: ApiNames.API_METHOD_GET_PAGE,
values: new { file = file, page = page });

public string BuildThumbUrl(string file, int page, string extension) =>
BuildUrl(
apiDomain: GetApiDomainOrDefault(),
apiPath: _options.Value.ApiPath,
apiPath: _options.ApiPath,
apiMethodName: ApiNames.API_METHOD_GET_THUMB,
values: new { file = file, page = page });

public string BuildPdfUrl(string file) =>
BuildUrl(
apiDomain: GetApiDomainOrDefault(),
apiPath: _options.Value.ApiPath,
apiPath: _options.ApiPath,
apiMethodName: ApiNames.API_METHOD_GET_PDF,
values: new { file = file });

public string BuildResourceUrl(string file, int page, string resource) =>
BuildUrl(
apiDomain: GetApiDomainOrDefault(),
apiPath: _options.Value.ApiPath,
apiPath: _options.ApiPath,
apiMethodName: ApiNames.API_METHOD_GET_RESOURCE,
values: new { file = file, page = page, resource = resource });

public string BuildResourceUrl(string file, string pageTemplate, string resourceTemplate) =>
BuildUrl(
apiDomain: GetApiDomainOrDefault(),
apiPath: _options.Value.ApiPath,
apiPath: _options.ApiPath,
apiMethodName: ApiNames.API_METHOD_GET_RESOURCE,
values: new { file = file, page = pageTemplate, resource = resourceTemplate });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using GroupDocs.Viewer.UI.Core;
using GroupDocs.Viewer.UI.Core.Entities;
using Microsoft.Extensions.Options;
using Options = GroupDocs.Viewer.UI.Api.Configuration.Options;

namespace GroupDocs.Viewer.UI.Cloud.Api.Viewers
{
Expand All @@ -17,7 +16,6 @@ internal class HtmlWithExternalResourcesViewer : BaseViewer

public HtmlWithExternalResourcesViewer(
IOptions<Config> config,
IOptions<Options> options,
IFileStorage fileStorage,
IViewerApiConnect viewerApiConnect,
IPageFormatter pageFormatter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Reflection;
using GroupDocs.Viewer.UI.Api;
using GroupDocs.Viewer.UI.Api.Configuration;
using GroupDocs.Viewer.UI.Api.Configuration.Implementation;
using GroupDocs.Viewer.UI.Api.Controllers;
using GroupDocs.Viewer.UI.Api.Utils;
using GroupDocs.Viewer.UI.Core;
Expand Down Expand Up @@ -41,6 +43,7 @@ public static GroupDocsViewerUIApiBuilder AddGroupDocsViewerSelfHostApi(this IMv
});

builder.Services.AddHttpContextAccessor();
builder.Services.AddSingleton<IOptionsProvider, InMemoryOptionsProvider>();
builder.Services.AddTransient<IApiUrlBuilder, ApiUrlBuilder>();
builder.Services.AddSingleton<IViewerLicenseManager, ViewerLicenseManager>();
builder.Services.AddTransient<IFileCache, NoopFileCache>();
Expand Down
2 changes: 1 addition & 1 deletion src/GroupDocs.Viewer.UI/App/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/GroupDocs.Viewer.UI/GroupDocs.Viewer.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageIcon>images\icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>

<AppsCommitSha>470fa61076428d554da675b5df25b6b36f38bf67</AppsCommitSha>
<AppsCommitSha>e8ad04a9c3fa0f7181d20add20bd13cd39e03478</AppsCommitSha>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading