1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/appRouter.js

852 lines
25 KiB
JavaScript
Raw Normal View History

2020-07-30 20:34:21 +02:00
import appHost from 'apphost';
import appSettings from 'appSettings';
import backdrop from 'backdrop';
import browser from 'browser';
import events from 'events';
import globalize from 'globalize';
import itemHelper from 'itemHelper';
import loading from 'loading';
import page from 'page';
import viewManager from 'viewManager';
import * as webSettings from 'webSettings';
2020-07-30 20:34:21 +02:00
class AppRouter {
allRoutes = [];
backdropContainer;
backgroundContainer;
currentRouteInfo;
currentViewLoadRequest;
firstConnectionResult;
forcedLogoutMsg;
handleAnchorClick = page.clickHandler;
isDummyBackToHome;
msgTimeout;
popstateOccurred = false;
resolveOnNextShow;
/**
* Pages of "no return" (when "Go back" should behave differently, probably quitting the application).
*/
startPages = ['home', 'login', 'selectserver'];
constructor() {
window.addEventListener('popstate', () => {
this.popstateOccurred = true;
});
document.addEventListener('viewshow', () => {
const resolve = this.resolveOnNextShow;
if (resolve) {
this.resolveOnNextShow = null;
resolve();
}
});
2020-08-25 10:12:35 +09:00
this.baseRoute = window.location.href.split('?')[0].replace(this.getRequestFile(), '');
2020-07-30 20:34:21 +02:00
// support hashbang
this.baseRoute = this.baseRoute.split('#')[0];
if (this.baseRoute.endsWith('/') && !this.baseRoute.endsWith('://')) {
this.baseRoute = this.baseRoute.substring(0, this.baseRoute.length - 1);
}
this.setBaseRoute();
}
/**
* @private
*/
setBaseRoute() {
2020-08-25 10:12:35 +09:00
let baseRoute = window.location.pathname.replace(this.getRequestFile(), '');
2020-07-30 20:34:21 +02:00
if (baseRoute.lastIndexOf('/') === baseRoute.length - 1) {
baseRoute = baseRoute.substring(0, baseRoute.length - 1);
}
console.debug('setting page base to ' + baseRoute);
page.base(baseRoute);
}
addRoute(path, newRoute) {
page(path, this.getHandler(newRoute));
this.allRoutes.push(newRoute);
}
showLocalLogin(serverId) {
2020-08-06 23:25:18 +02:00
Dashboard.navigate('login.html?serverid=' + serverId);
}
showVideoOsd() {
Dashboard.navigate('video');
2020-07-30 20:34:21 +02:00
}
showSelectServer() {
Dashboard.navigate('selectserver.html');
2020-07-30 20:34:21 +02:00
}
showSettings() {
2020-08-06 23:25:18 +02:00
Dashboard.navigate('mypreferencesmenu.html');
2020-07-30 20:34:21 +02:00
}
showNowPlaying() {
2020-08-06 23:25:18 +02:00
this.show('queue');
2020-07-30 20:34:21 +02:00
}
beginConnectionWizard() {
2020-08-06 23:25:18 +02:00
backdrop.clearBackdrop();
2020-07-31 21:35:01 +01:00
loading.show();
2020-08-30 06:06:47 +02:00
window.connectionManager.connect({
2018-10-23 01:05:09 +03:00
enableAutoLogin: appSettings.enableAutoLogin()
2020-07-30 20:34:21 +02:00
}).then((result) => {
this.handleConnectionResult(result);
});
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
param(name, url) {
name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
const regexS = '[\\?&]' + name + '=([^&#]*)';
const regex = new RegExp(regexS, 'i');
const results = regex.exec(url || getWindowLocationSearch());
if (results == null) {
return '';
} else {
return decodeURIComponent(results[1].replace(/\+/g, ' '));
}
}
back() {
page.back();
}
show(path, options) {
if (path.indexOf('/') !== 0 && path.indexOf('://') === -1) {
path = '/' + path;
}
path = path.replace(this.baseUrl(), '');
if (this.currentRouteInfo && this.currentRouteInfo.path === path) {
// can't use this with home right now due to the back menu
if (this.currentRouteInfo.route.type !== 'home') {
loading.hide();
return Promise.resolve();
}
}
return new Promise((resolve) => {
this.resolveOnNextShow = resolve;
page.show(path, options);
});
}
showDirect(path) {
return new Promise(function(resolve) {
this.resolveOnNextShow = resolve;
page.show(this.baseUrl() + path);
});
}
start(options) {
loading.show();
this.initApiClients();
events.on(appHost, 'beforeexit', this.onBeforeExit);
events.on(appHost, 'resume', this.onAppResume);
2020-08-30 06:06:47 +02:00
window.connectionManager.connect({
2020-07-30 20:34:21 +02:00
enableAutoLogin: appSettings.enableAutoLogin()
}).then((result) => {
this.firstConnectionResult = result;
options = options || {};
page({
click: options.click !== false,
hashbang: options.hashbang !== false
});
}).catch().then(() => {
loading.hide();
});
}
baseUrl() {
return this.baseRoute;
}
canGoBack() {
const curr = this.current();
if (!curr) {
return false;
}
if (!document.querySelector('.dialogContainer') && this.startPages.indexOf(curr.type) !== -1) {
return false;
}
2020-08-25 10:12:35 +09:00
return window.history.length > 1;
2020-07-30 20:34:21 +02:00
}
current() {
return this.currentRouteInfo ? this.currentRouteInfo.route : null;
}
invokeShortcut(id) {
if (id.indexOf('library-') === 0) {
id = id.replace('library-', '');
id = id.split('_');
this.showItem(id[0], id[1]);
} else if (id.indexOf('item-') === 0) {
id = id.replace('item-', '');
id = id.split('_');
this.showItem(id[0], id[1]);
} else {
id = id.split('_');
this.show(this.getRouteUrl(id[0], {
serverId: id[1]
}));
}
}
showItem(item, serverId, options) {
// TODO: Refactor this so it only gets items, not strings.
if (typeof (item) === 'string') {
2020-08-30 06:06:47 +02:00
const apiClient = serverId ? window.connectionManager.getApiClient(serverId) : window.connectionManager.currentApiClient();
2020-07-30 20:34:21 +02:00
apiClient.getItem(apiClient.getCurrentUserId(), item).then((itemObject) => {
this.showItem(itemObject, options);
});
} else {
if (arguments.length === 2) {
options = arguments[1];
}
const url = this.getRouteUrl(item, options);
this.show(url, {
item: item
});
}
}
setTransparency(level) {
if (!this.backdropContainer) {
this.backdropContainer = document.querySelector('.backdropContainer');
}
if (!this.backgroundContainer) {
this.backgroundContainer = document.querySelector('.backgroundContainer');
}
if (level === 'full' || level === 2) {
2020-08-06 23:25:18 +02:00
backdrop.clearBackdrop(true);
2020-07-30 20:34:21 +02:00
document.documentElement.classList.add('transparentDocument');
this.backgroundContainer.classList.add('backgroundContainer-transparent');
this.backdropContainer.classList.add('hide');
} else if (level === 'backdrop' || level === 1) {
backdrop.externalBackdrop(true);
document.documentElement.classList.add('transparentDocument');
this.backgroundContainer.classList.add('backgroundContainer-transparent');
this.backdropContainer.classList.add('hide');
} else {
backdrop.externalBackdrop(false);
document.documentElement.classList.remove('transparentDocument');
this.backgroundContainer.classList.remove('backgroundContainer-transparent');
this.backdropContainer.classList.remove('hide');
}
}
getRoutes() {
return this.allRoutes;
}
pushState(state, title, url) {
state.navigate = false;
2020-08-25 10:12:35 +09:00
window.history.pushState(state, title, url);
2020-07-30 20:34:21 +02:00
}
enableNativeHistory() {
return false;
}
handleConnectionResult(result) {
2018-10-23 01:05:09 +03:00
switch (result.State) {
case 'SignedIn':
2020-07-31 21:35:01 +01:00
loading.hide();
Emby.Page.goHome();
break;
case 'ServerSignIn':
2020-07-30 20:34:21 +02:00
result.ApiClient.getPublicUsers().then((users) => {
if (users.length) {
2020-07-30 20:34:21 +02:00
this.showLocalLogin(result.Servers[0].Id);
} else {
2020-07-30 20:34:21 +02:00
this.showLocalLogin(result.Servers[0].Id, true);
}
});
2018-10-23 01:05:09 +03:00
break;
case 'ServerSelection':
2020-07-30 20:34:21 +02:00
this.showSelectServer();
2018-10-23 01:05:09 +03:00
break;
case 'ServerUpdateNeeded':
2020-08-12 15:12:03 +02:00
import('alert').then(({default: alert}) =>{
2020-07-30 20:34:21 +02:00
alert({
text: globalize.translate('ServerUpdateNeeded', 'https://github.com/jellyfin/jellyfin'),
html: globalize.translate('ServerUpdateNeeded', '<a href="https://github.com/jellyfin/jellyfin">https://github.com/jellyfin/jellyfin</a>')
2020-07-30 20:34:21 +02:00
}).then(() => {
this.showSelectServer();
});
});
break;
default:
2018-10-23 01:05:09 +03:00
break;
}
}
2020-07-30 20:34:21 +02:00
loadContentUrl(ctx, next, route, request) {
let url;
if (route.contentPath && typeof (route.contentPath) === 'function') {
url = route.contentPath(ctx.querystring);
} else {
url = route.contentPath || route.path;
}
if (url.includes('configurationpage')) {
url = ApiClient.getUrl('/web' + url);
} else if (url.indexOf('://') === -1) {
// Put a slash at the beginning but make sure to avoid a double slash
if (url.indexOf('/') !== 0) {
url = '/' + url;
}
2020-07-30 20:34:21 +02:00
url = this.baseUrl() + url;
}
if (ctx.querystring && route.enableContentQueryString) {
url += '?' + ctx.querystring;
}
2020-08-12 15:12:03 +02:00
import('text!' + url).then(({default: html}) => {
2020-07-30 20:34:21 +02:00
this.loadContent(ctx, route, html, request);
});
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
handleRoute(ctx, next, route) {
this.authenticate(ctx, route, () => {
this.initRoute(ctx, next, route);
});
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
initRoute(ctx, next, route) {
const onInitComplete = (controllerFactory) => {
this.sendRouteToViewManager(ctx, next, route, controllerFactory);
2018-10-23 01:05:09 +03:00
};
if (route.controller) {
2020-08-12 15:12:03 +02:00
import('controllers/' + route.controller).then(onInitComplete);
} else {
onInitComplete();
}
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
cancelCurrentLoadRequest() {
const currentRequest = this.currentViewLoadRequest;
if (currentRequest) {
currentRequest.cancel = true;
}
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
sendRouteToViewManager(ctx, next, route, controllerFactory) {
if (this.isDummyBackToHome && route.type === 'home') {
this.isDummyBackToHome = false;
return;
}
2020-07-30 20:34:21 +02:00
this.cancelCurrentLoadRequest();
const isBackNav = ctx.isBack;
2020-07-30 20:34:21 +02:00
const currentRequest = {
url: this.baseUrl() + ctx.path,
transition: route.transition,
isBack: isBackNav,
state: ctx.state,
type: route.type,
fullscreen: route.fullscreen,
controllerFactory: controllerFactory,
options: {
supportsThemeMedia: route.supportsThemeMedia || false,
enableMediaControl: route.enableMediaControl !== false
},
autoFocus: route.autoFocus
};
2020-07-30 20:34:21 +02:00
this.currentViewLoadRequest = currentRequest;
2020-07-30 20:34:21 +02:00
const onNewViewNeeded = () => {
if (typeof route.path === 'string') {
2020-07-30 20:34:21 +02:00
this.loadContentUrl(ctx, next, route, currentRequest);
} else {
next();
}
2018-10-23 01:05:09 +03:00
};
if (!isBackNav) {
onNewViewNeeded();
return;
}
2020-07-30 20:34:21 +02:00
viewManager.tryRestoreView(currentRequest, () => {
this.currentRouteInfo = {
2018-10-23 01:05:09 +03:00
route: route,
path: ctx.path
};
2020-07-30 20:34:21 +02:00
}).catch((result) => {
if (!result || !result.cancelled) {
onNewViewNeeded();
2018-10-23 01:05:09 +03:00
}
});
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
onForcedLogoutMessageTimeout() {
const msg = this.forcedLogoutMsg;
this.forcedLogoutMsg = null;
if (msg) {
2020-08-12 15:12:03 +02:00
import('alert').then((alert) => {
alert(msg);
});
}
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
showForcedLogoutMessage(msg) {
this.forcedLogoutMsg = msg;
if (this.msgTimeout) {
clearTimeout(this.msgTimeout);
}
2020-07-30 20:34:21 +02:00
this.msgTimeout = setTimeout(this.onForcedLogoutMessageTimeout, 100);
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
onRequestFail(e, data) {
const apiClient = this;
if (data.status === 403) {
2020-05-04 12:44:12 +02:00
if (data.errorCode === 'ParentalControl') {
2020-07-30 20:34:21 +02:00
const isCurrentAllowed = this.currentRouteInfo ? (this.currentRouteInfo.route.anonymous || this.currentRouteInfo.route.startup) : true;
// Bounce to the login screen, but not if a password entry fails, obviously
if (!isCurrentAllowed) {
2020-07-30 20:34:21 +02:00
this.showForcedLogoutMessage(globalize.translate('AccessRestrictedTryAgainLater'));
this.showLocalLogin(apiClient.serverId());
}
}
2018-10-23 01:05:09 +03:00
}
}
2020-07-30 20:34:21 +02:00
onBeforeExit() {
if (browser.web0s) {
page.restorePreviousState();
}
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
normalizeImageOptions(options) {
let setQuality;
2020-07-16 16:03:36 +02:00
if (options.maxWidth || options.width || options.maxHeight || options.height) {
setQuality = true;
}
2020-07-16 17:25:36 +02:00
if (setQuality && !options.quality) {
2020-07-16 16:03:36 +02:00
options.quality = 90;
2018-10-23 01:05:09 +03:00
}
}
2020-07-30 20:34:21 +02:00
getMaxBandwidth() {
/* eslint-disable compat/compat */
2018-10-23 01:05:09 +03:00
if (navigator.connection) {
2020-07-30 20:34:21 +02:00
let max = navigator.connection.downlinkMax;
if (max && max > 0 && max < Number.POSITIVE_INFINITY) {
max /= 8;
max *= 1000000;
max *= 0.7;
2020-07-30 19:42:30 +02:00
return parseInt(max, 10);
}
2018-10-23 01:05:09 +03:00
}
/* eslint-enable compat/compat */
return null;
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
getMaxBandwidthIOS() {
return 800000;
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
onApiClientCreated(e, newApiClient) {
newApiClient.normalizeImageOptions = this.normalizeImageOptions;
if (browser.iOS) {
2020-07-30 20:34:21 +02:00
newApiClient.getMaxBandwidth = this.getMaxBandwidthIOS;
} else {
2020-07-30 20:34:21 +02:00
newApiClient.getMaxBandwidth = this.getMaxBandwidth;
}
2020-07-30 20:34:21 +02:00
events.off(newApiClient, 'requestfail', this.onRequestFail);
events.on(newApiClient, 'requestfail', this.onRequestFail);
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
initApiClient(apiClient, instance) {
instance.onApiClientCreated({}, apiClient);
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
initApiClients() {
2020-08-30 06:06:47 +02:00
window.connectionManager.getApiClients().forEach((apiClient) => {
2020-07-30 20:34:21 +02:00
this.initApiClient(apiClient, this);
});
2020-08-30 06:06:47 +02:00
events.on(window.connectionManager, 'apiclientcreated', this.onApiClientCreated);
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
onAppResume() {
2020-08-30 06:06:47 +02:00
const apiClient = window.connectionManager.currentApiClient();
if (apiClient) {
apiClient.ensureWebSocket();
}
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
authenticate(ctx, route, callback) {
const firstResult = this.firstConnectionResult;
this.firstConnectionResult = null;
if (firstResult && firstResult.State === 'ServerSignIn' && !route.anonymous) {
const url = ApiClient.serverAddress() + '/System/Info/Public';
fetch(url).then(response => {
2020-09-12 08:41:04 +09:00
if (!response.ok) return Promise.reject('fetch failed');
return response.json();
}).then(data => {
if (data !== null && data.StartupWizardCompleted === false) {
Dashboard.navigate('wizardstart.html');
} else {
this.handleConnectionResult(firstResult);
}
}).catch(error => {
console.error(error);
});
}
2020-08-30 06:06:47 +02:00
const apiClient = window.connectionManager.currentApiClient();
2020-07-30 20:34:21 +02:00
const pathname = ctx.pathname.toLowerCase();
2020-09-12 08:41:04 +09:00
console.debug('processing path request: ' + pathname);
2020-07-30 20:34:21 +02:00
const isCurrentRouteStartup = this.currentRouteInfo ? this.currentRouteInfo.route.startup : true;
const shouldExitApp = ctx.isBack && route.isDefaultRoute && isCurrentRouteStartup;
if (!shouldExitApp && (!apiClient || !apiClient.isLoggedIn()) && !route.anonymous) {
console.debug('route does not allow anonymous access: redirecting to login');
2020-07-30 20:34:21 +02:00
this.beginConnectionWizard();
return;
}
2018-10-23 01:05:09 +03:00
if (shouldExitApp) {
if (appHost.supports('exit')) {
appHost.exit();
}
return;
}
if (apiClient && apiClient.isLoggedIn()) {
console.debug('user is authenticated');
2019-03-24 12:15:13 +00:00
if (route.isDefaultRoute) {
console.debug('loading home page');
Emby.Page.goHome();
return;
} else if (route.roles) {
2020-07-30 20:34:21 +02:00
this.validateRoles(apiClient, route.roles).then(() => {
callback();
2020-07-30 20:34:21 +02:00
}, this.beginConnectionWizard);
return;
2018-10-23 01:05:09 +03:00
}
}
console.debug('proceeding to page: ' + pathname);
callback();
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
validateRoles(apiClient, roles) {
return Promise.all(roles.split(',').map((role) => {
return this.validateRole(apiClient, role);
}));
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
validateRole(apiClient, role) {
if (role === 'admin') {
2020-07-30 20:34:21 +02:00
return apiClient.getCurrentUser().then((user) => {
if (user.Policy.IsAdministrator) {
return Promise.resolve();
}
return Promise.reject();
});
}
// Unknown role
return Promise.resolve();
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
loadContent(ctx, route, html, request) {
2020-07-18 09:21:15 +01:00
html = globalize.translateHtml(html, route.dictionary);
request.view = html;
viewManager.loadView(request);
2020-07-30 20:34:21 +02:00
this.currentRouteInfo = {
2018-10-23 01:05:09 +03:00
route: route,
path: ctx.path
};
ctx.handled = true;
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
getRequestFile() {
2020-08-25 10:12:35 +09:00
let path = window.location.pathname || '';
2020-07-30 20:34:21 +02:00
const index = path.lastIndexOf('/');
if (index !== -1) {
path = path.substring(index);
} else {
path = '/' + path;
}
if (!path || path === '/') {
path = '/index.html';
}
return path;
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
getHandler(route) {
return (ctx, next) => {
ctx.isBack = this.popstateOccurred;
this.handleRoute(ctx, next, route);
this.popstateOccurred = false;
};
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
getWindowLocationSearch() {
const currentPath = this.currentRouteInfo ? (this.currentRouteInfo.path || '') : '';
const index = currentPath.indexOf('?');
let search = '';
if (index !== -1) {
search = currentPath.substring(index);
}
return search || '';
}
2020-07-30 20:34:21 +02:00
showGuide() {
2020-08-06 23:25:18 +02:00
Dashboard.navigate('livetv.html?tab=1');
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
goHome() {
2020-08-06 23:25:18 +02:00
Dashboard.navigate('home.html');
2020-07-30 20:34:21 +02:00
}
2020-03-24 10:03:51 +03:00
2020-07-30 20:34:21 +02:00
showSearch() {
2020-08-06 23:25:18 +02:00
Dashboard.navigate('search.html');
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
showLiveTV() {
2020-08-06 23:25:18 +02:00
Dashboard.navigate('livetv.html');
2020-07-30 20:34:21 +02:00
}
2020-07-30 20:34:21 +02:00
showRecordedTV() {
2020-08-06 23:25:18 +02:00
Dashboard.navigate('livetv.html?tab=3');
2020-07-30 20:34:21 +02:00
}
2020-07-30 20:34:21 +02:00
showFavorites() {
2020-08-06 23:25:18 +02:00
Dashboard.navigate('home.html?tab=1');
2020-07-30 20:34:21 +02:00
}
2020-07-30 20:34:21 +02:00
setTitle(title) {
LibraryMenu.setTitle(title);
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
getRouteUrl(item, options) {
if (!item) {
throw new Error('item cannot be null');
}
2020-07-30 20:34:21 +02:00
if (item.url) {
return item.url;
}
2018-10-23 01:05:09 +03:00
2020-07-30 20:34:21 +02:00
const context = options ? options.context : null;
const id = item.Id || item.ItemId;
2018-10-23 01:05:09 +03:00
2020-07-30 20:34:21 +02:00
if (!options) {
options = {};
}
2020-01-25 01:18:07 +03:00
2020-07-30 20:34:21 +02:00
let url;
// TODO: options will never be false. Replace condition with lodash's isEmpty()
const itemType = item.Type || (options ? options.itemType : null);
const serverId = item.ServerId || options.serverId;
if (item === 'settings') {
return 'mypreferencesmenu.html';
}
2020-07-30 20:34:21 +02:00
if (item === 'wizard') {
return 'wizardstart.html';
}
2020-07-24 19:02:25 +02:00
2020-07-30 20:34:21 +02:00
if (item === 'manageserver') {
return 'dashboard.html';
}
2020-07-30 20:34:21 +02:00
if (item === 'recordedtv') {
return 'livetv.html?tab=3&serverId=' + options.serverId;
}
2020-07-30 20:34:21 +02:00
if (item === 'nextup') {
return 'list.html?type=nextup&serverId=' + options.serverId;
}
2020-07-30 20:34:21 +02:00
if (item === 'list') {
let url = 'list.html?serverId=' + options.serverId + '&type=' + options.itemTypes;
2020-07-30 20:34:21 +02:00
if (options.isFavorite) {
url += '&IsFavorite=true';
}
2020-07-30 20:34:21 +02:00
return url;
}
2020-07-30 20:34:21 +02:00
if (item === 'livetv') {
if (options.section === 'programs') {
return 'livetv.html?tab=0&serverId=' + options.serverId;
}
if (options.section === 'guide') {
return 'livetv.html?tab=1&serverId=' + options.serverId;
}
2018-10-23 01:05:09 +03:00
2020-07-30 20:34:21 +02:00
if (options.section === 'movies') {
return 'list.html?type=Programs&IsMovie=true&serverId=' + options.serverId;
}
2020-07-30 20:34:21 +02:00
if (options.section === 'shows') {
return 'list.html?type=Programs&IsSeries=true&IsMovie=false&IsNews=false&serverId=' + options.serverId;
}
2018-10-23 01:05:09 +03:00
2020-07-30 20:34:21 +02:00
if (options.section === 'sports') {
return 'list.html?type=Programs&IsSports=true&serverId=' + options.serverId;
}
2020-07-30 20:34:21 +02:00
if (options.section === 'kids') {
return 'list.html?type=Programs&IsKids=true&serverId=' + options.serverId;
}
if (options.section === 'news') {
return 'list.html?type=Programs&IsNews=true&serverId=' + options.serverId;
}
if (options.section === 'onnow') {
return 'list.html?type=Programs&IsAiring=true&serverId=' + options.serverId;
}
if (options.section === 'dvrschedule') {
return 'livetv.html?tab=4&serverId=' + options.serverId;
}
if (options.section === 'seriesrecording') {
return 'livetv.html?tab=5&serverId=' + options.serverId;
}
return 'livetv.html?serverId=' + options.serverId;
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
if (itemType == 'SeriesTimer') {
return 'details?seriesTimerId=' + id + '&serverId=' + serverId;
}
2020-07-30 20:34:21 +02:00
if (item.CollectionType == 'livetv') {
return 'livetv.html';
}
2018-10-23 01:05:09 +03:00
2020-07-30 20:34:21 +02:00
if (item.Type === 'Genre') {
url = 'list.html?genreId=' + item.Id + '&serverId=' + serverId;
if (context === 'livetv') {
url += '&type=Programs';
}
if (options.parentId) {
url += '&parentId=' + options.parentId;
}
2018-10-23 01:05:09 +03:00
2020-07-30 20:34:21 +02:00
return url;
}
2020-07-30 20:34:21 +02:00
if (item.Type === 'MusicGenre') {
url = 'list.html?musicGenreId=' + item.Id + '&serverId=' + serverId;
if (options.parentId) {
url += '&parentId=' + options.parentId;
}
return url;
}
2020-07-30 20:34:21 +02:00
if (item.Type === 'Studio') {
url = 'list.html?studioId=' + item.Id + '&serverId=' + serverId;
if (options.parentId) {
url += '&parentId=' + options.parentId;
}
return url;
}
2018-10-23 01:05:09 +03:00
2020-07-30 20:34:21 +02:00
if (context !== 'folders' && !itemHelper.isLocalItem(item)) {
if (item.CollectionType == 'movies') {
url = 'movies.html?topParentId=' + item.Id;
2020-07-30 20:34:21 +02:00
if (options && options.section === 'latest') {
url += '&tab=1';
}
return url;
}
if (item.CollectionType == 'tvshows') {
url = 'tv.html?topParentId=' + item.Id;
if (options && options.section === 'latest') {
url += '&tab=2';
}
return url;
}
if (item.CollectionType == 'music') {
return 'music.html?topParentId=' + item.Id;
}
}
2020-07-30 20:34:21 +02:00
const itemTypes = ['Playlist', 'TvChannel', 'Program', 'BoxSet', 'MusicAlbum', 'MusicGenre', 'Person', 'Recording', 'MusicArtist'];
2020-07-30 20:34:21 +02:00
if (itemTypes.indexOf(itemType) >= 0) {
return 'details?id=' + id + '&serverId=' + serverId;
}
2020-07-30 20:34:21 +02:00
const contextSuffix = context ? '&context=' + context : '';
2020-07-30 20:34:21 +02:00
if (itemType == 'Series' || itemType == 'Season' || itemType == 'Episode') {
return 'details?id=' + id + contextSuffix + '&serverId=' + serverId;
}
2020-07-30 20:34:21 +02:00
if (item.IsFolder) {
if (id) {
return 'list.html?parentId=' + id + '&serverId=' + serverId;
}
return '#';
}
2020-07-30 20:34:21 +02:00
return 'details?id=' + id + '&serverId=' + serverId;
2018-10-23 01:05:09 +03:00
}
2020-07-30 20:34:21 +02:00
}
2020-07-30 20:34:21 +02:00
export default new AppRouter();