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

Simplify url utils

This commit is contained in:
Bill Thornton 2022-04-06 17:31:54 -04:00
parent 67169e2a6a
commit 3412201532
5 changed files with 8 additions and 30 deletions

View file

@ -12,7 +12,6 @@ import Dashboard from '../scripts/clientUtils';
import ServerConnections from './ServerConnections'; import ServerConnections from './ServerConnections';
import alert from './alert'; import alert from './alert';
import reactControllerFactory from './reactControllerFactory'; import reactControllerFactory from './reactControllerFactory';
import { getWindowLocationSearch } from '../utils/url.ts';
class AppRouter { class AppRouter {
allRoutes = []; allRoutes = [];
@ -121,7 +120,7 @@ class AppRouter {
const regexS = '[\\?&]' + name + '=([^&#]*)'; const regexS = '[\\?&]' + name + '=([^&#]*)';
const regex = new RegExp(regexS, 'i'); const regex = new RegExp(regexS, 'i');
const results = regex.exec(url || getWindowLocationSearch()); const results = regex.exec(url || window.location.search);
if (results == null) { if (results == null) {
return ''; return '';
} else { } else {

View file

@ -10,7 +10,6 @@ import datetime from '../scripts/datetime';
import DirectoryBrowser from '../components/directorybrowser/directorybrowser'; import DirectoryBrowser from '../components/directorybrowser/directorybrowser';
import dialogHelper from '../components/dialogHelper/dialogHelper'; import dialogHelper from '../components/dialogHelper/dialogHelper';
import itemIdentifier from '../components/itemidentifier/itemidentifier'; import itemIdentifier from '../components/itemidentifier/itemidentifier';
import { getWindowLocationSearch } from '../utils/url.ts';
export function getCurrentUser() { export function getCurrentUser() {
return window.ApiClient.getCurrentUser(false); return window.ApiClient.getCurrentUser(false);
@ -113,7 +112,7 @@ export function navigate(url, preserveQueryString) {
throw new Error('url cannot be null or empty'); throw new Error('url cannot be null or empty');
} }
const queryString = getWindowLocationSearch(); const queryString = window.location.search;
if (preserveQueryString && queryString) { if (preserveQueryString && queryString) {
url += queryString; url += queryString;

View file

@ -300,9 +300,9 @@ import { getParameterByName } from '../utils/url.ts';
if (itemId) { if (itemId) {
return itemId; return itemId;
} }
const url = window.location.hash || window.location.href; return getParameterByName('id');
return getParameterByName('id', url);
} }
let nodesToLoad = []; let nodesToLoad = [];
let selectedNodeId; let selectedNodeId;
$(document).on('itemsaved', '.metadataEditorPage', function (e, item) { $(document).on('itemsaved', '.metadataEditorPage', function (e, item) {

View file

@ -41,8 +41,6 @@ import SyncPlayHtmlAudioPlayer from '../components/syncPlay/ui/players/HtmlAudio
import { currentSettings } from './settings/userSettings'; import { currentSettings } from './settings/userSettings';
import taskButton from './taskbutton'; import taskButton from './taskbutton';
// TODO: Move this elsewhere
function loadCoreDictionary() { function loadCoreDictionary() {
const languages = ['af', 'ar', 'be-by', 'bg-bg', 'bn_bd', 'ca', 'cs', 'da', 'de', 'el', 'en-gb', 'en-us', 'eo', 'es', 'es-419', 'es-ar', 'es_do', 'es-mx', 'fa', 'fi', 'fil', 'fr', 'fr-ca', 'gl', 'gsw', 'he', 'hi-in', 'hr', 'hu', 'id', 'it', 'ja', 'kk', 'ko', 'lt-lt', 'mr', 'ms', 'nb', 'nl', 'pl', 'pr', 'pt', 'pt-br', 'pt-pt', 'ro', 'ru', 'sk', 'sl-si', 'sq', 'sv', 'ta', 'th', 'tr', 'uk', 'ur_pk', 'vi', 'zh-cn', 'zh-hk', 'zh-tw']; const languages = ['af', 'ar', 'be-by', 'bg-bg', 'bn_bd', 'ca', 'cs', 'da', 'de', 'el', 'en-gb', 'en-us', 'eo', 'es', 'es-419', 'es-ar', 'es_do', 'es-mx', 'fa', 'fi', 'fil', 'fr', 'fr-ca', 'gl', 'gsw', 'he', 'hi-in', 'hr', 'hu', 'id', 'it', 'ja', 'kk', 'ko', 'lt-lt', 'mr', 'ms', 'nb', 'nl', 'pl', 'pr', 'pt', 'pt-br', 'pt-pt', 'ro', 'ru', 'sk', 'sl-si', 'sq', 'sv', 'ta', 'th', 'tr', 'uk', 'ur_pk', 'vi', 'zh-cn', 'zh-hk', 'zh-tw'];
const translations = languages.map(function (language) { const translations = languages.map(function (language) {

View file

@ -1,26 +1,8 @@
export const getWindowLocationSearch = (win?: Window | null | undefined) => {
let search = (win || window).location.search;
if (!search) {
const index = window.location.href.indexOf('?');
if (index != -1) {
search = window.location.href.substring(index);
}
}
return search || '';
};
export const getParameterByName = (name: string, url?: string | null | undefined) => { export const getParameterByName = (name: string, url?: string | null | undefined) => {
name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]'); if (!url) {
const regexS = '[\\?&]' + name + '=([^&#]*)'; url = window.location.search;
const regex = new RegExp(regexS, 'i');
const results = regex.exec(url || getWindowLocationSearch());
if (results == null) {
return '';
} }
return decodeURIComponent(results[1].replace(/\+/g, ' ')); // eslint-disable-next-line compat/compat
return new URLSearchParams(url).get(name) || '';
}; };