Fixed: Caching for dynamically loaded JS files Fixed: Incorrect caching of initialize.jspull/5808/head
parent
f62bc59a73
commit
f0cb5b81f1
@ -0,0 +1,23 @@
|
||||
import { createBrowserHistory } from 'history';
|
||||
import React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
import createAppStore from 'Store/createAppStore';
|
||||
import { fetchTranslations } from 'Utilities/String/translate';
|
||||
import App from './App/App';
|
||||
|
||||
import 'Diag/ConsoleApi';
|
||||
|
||||
export async function bootstrap() {
|
||||
const history = createBrowserHistory();
|
||||
const store = createAppStore(history);
|
||||
const hasTranslationsError = !(await fetchTranslations());
|
||||
|
||||
render(
|
||||
<App
|
||||
store={store}
|
||||
history={history}
|
||||
hasTranslationsError={hasTranslationsError}
|
||||
/>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
import { createBrowserHistory } from 'history';
|
||||
import React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
import { fetchTranslations } from 'Utilities/String/translate';
|
||||
|
||||
import './preload';
|
||||
import './polyfills';
|
||||
import 'Diag/ConsoleApi';
|
||||
import 'Styles/globals.css';
|
||||
import './index.css';
|
||||
|
||||
const history = createBrowserHistory();
|
||||
const hasTranslationsError = !await fetchTranslations();
|
||||
|
||||
const { default: createAppStore } = await import('Store/createAppStore');
|
||||
const { default: App } = await import('./App/App');
|
||||
|
||||
const store = createAppStore(history);
|
||||
|
||||
render(
|
||||
<App
|
||||
store={store}
|
||||
history={history}
|
||||
hasTranslationsError={hasTranslationsError}
|
||||
/>,
|
||||
document.getElementById('root')
|
||||
);
|
@ -0,0 +1,19 @@
|
||||
import './polyfills';
|
||||
import 'Styles/globals.css';
|
||||
import './index.css';
|
||||
|
||||
const initializeUrl = `${
|
||||
window.Sonarr.urlBase
|
||||
}/initialize.json?t=${Date.now()}`;
|
||||
const response = await fetch(initializeUrl);
|
||||
|
||||
window.Sonarr = await response.json();
|
||||
|
||||
/* eslint-disable no-undef, @typescript-eslint/ban-ts-comment */
|
||||
// @ts-ignore 2304
|
||||
__webpack_public_path__ = `${window.Sonarr.urlBase}/`;
|
||||
/* eslint-enable no-undef, @typescript-eslint/ban-ts-comment */
|
||||
|
||||
const { bootstrap } = await import('./bootstrap');
|
||||
|
||||
await bootstrap();
|
@ -1,2 +0,0 @@
|
||||
/* eslint no-undef: 0 */
|
||||
__webpack_public_path__ = `${window.Sonarr.urlBase}/`;
|
@ -1,65 +0,0 @@
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Analytics;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace Sonarr.Http.Frontend
|
||||
{
|
||||
[Authorize(Policy = "UI")]
|
||||
[ApiController]
|
||||
public class InitializeJsController : Controller
|
||||
{
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IAnalyticsService _analyticsService;
|
||||
|
||||
private static string _apiKey;
|
||||
private static string _urlBase;
|
||||
private string _generatedContent;
|
||||
|
||||
public InitializeJsController(IConfigFileProvider configFileProvider,
|
||||
IAnalyticsService analyticsService)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
_analyticsService = analyticsService;
|
||||
|
||||
_apiKey = configFileProvider.ApiKey;
|
||||
_urlBase = configFileProvider.UrlBase;
|
||||
}
|
||||
|
||||
[HttpGet("/initialize.js")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return Content(GetContent(), "application/javascript");
|
||||
}
|
||||
|
||||
private string GetContent()
|
||||
{
|
||||
if (RuntimeInfo.IsProduction && _generatedContent != null)
|
||||
{
|
||||
return _generatedContent;
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine("window.Sonarr = {");
|
||||
builder.AppendLine($" apiRoot: '{_urlBase}/api/v3',");
|
||||
builder.AppendLine($" apiKey: '{_apiKey}',");
|
||||
builder.AppendLine($" release: '{BuildInfo.Release}',");
|
||||
builder.AppendLine($" version: '{BuildInfo.Version.ToString()}',");
|
||||
builder.AppendLine($" instanceName: '{_configFileProvider.InstanceName.ToString()}',");
|
||||
builder.AppendLine($" theme: '{_configFileProvider.Theme.ToString()}',");
|
||||
builder.AppendLine($" branch: '{_configFileProvider.Branch.ToLower()}',");
|
||||
builder.AppendLine($" analytics: {_analyticsService.IsEnabled.ToString().ToLowerInvariant()},");
|
||||
builder.AppendLine($" userHash: '{HashUtil.AnonymousToken()}',");
|
||||
builder.AppendLine($" urlBase: '{_urlBase}',");
|
||||
builder.AppendLine($" isProduction: {RuntimeInfo.IsProduction.ToString().ToLowerInvariant()}");
|
||||
builder.AppendLine("};");
|
||||
|
||||
_generatedContent = builder.ToString();
|
||||
|
||||
return _generatedContent;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Analytics;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace Sonarr.Http.Frontend
|
||||
{
|
||||
[Authorize(Policy = "UI")]
|
||||
[ApiController]
|
||||
public class InitializeJsonController : Controller
|
||||
{
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IAnalyticsService _analyticsService;
|
||||
|
||||
private static string _apiKey;
|
||||
private static string _urlBase;
|
||||
private string _generatedContent;
|
||||
|
||||
public InitializeJsonController(IConfigFileProvider configFileProvider,
|
||||
IAnalyticsService analyticsService)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
_analyticsService = analyticsService;
|
||||
|
||||
_apiKey = configFileProvider.ApiKey;
|
||||
_urlBase = configFileProvider.UrlBase;
|
||||
}
|
||||
|
||||
[HttpGet("/initialize.json")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return Content(GetContent(), "application/json");
|
||||
}
|
||||
|
||||
private string GetContent()
|
||||
{
|
||||
if (RuntimeInfo.IsProduction && _generatedContent != null)
|
||||
{
|
||||
return _generatedContent;
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine("{");
|
||||
builder.AppendLine($" \"apiRoot\": \"{_urlBase}/api/v3\",");
|
||||
builder.AppendLine($" \"apiKey\": \"{_apiKey}\",");
|
||||
builder.AppendLine($" \"release\": \"{BuildInfo.Release}\",");
|
||||
builder.AppendLine($" \"version\": \"{BuildInfo.Version.ToString()}\",");
|
||||
builder.AppendLine($" \"instanceName\": \"{_configFileProvider.InstanceName.ToString()}\",");
|
||||
builder.AppendLine($" \"theme\": \"{_configFileProvider.Theme.ToString()}\",");
|
||||
builder.AppendLine($" \"branch\": \"{_configFileProvider.Branch.ToLower()}\",");
|
||||
builder.AppendLine($" \"analytics\": {_analyticsService.IsEnabled.ToString().ToLowerInvariant()},");
|
||||
builder.AppendLine($" \"userHash\": \"{HashUtil.AnonymousToken()}\",");
|
||||
builder.AppendLine($" \"urlBase\": \"{_urlBase}\",");
|
||||
builder.AppendLine($" \"isProduction\": {RuntimeInfo.IsProduction.ToString().ToLowerInvariant()}");
|
||||
builder.AppendLine("}");
|
||||
|
||||
_generatedContent = builder.ToString();
|
||||
|
||||
return _generatedContent;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue