diff --git a/medusa/server/api/v2/history.py b/medusa/server/api/v2/history.py index 707930e200..f6a75219bd 100644 --- a/medusa/server/api/v2/history.py +++ b/medusa/server/api/v2/history.py @@ -53,7 +53,7 @@ def get(self, series_slug, path_param): compact_layout = bool(self.get_argument('compact', default=False)) return_last = bool(self.get_argument('last', default=False)) total_rows = self.get_argument('total', default=None) - sort = [json.loads(item) for item in self.get_arguments('sort[]')] + sort = [json.loads(item) for item in self.get_arguments('sort')] filter = json.loads(self.get_argument('filter')) if self.get_arguments('filter') else None headers = {} diff --git a/themes-default/slim/src/store/modules/history.js b/themes-default/slim/src/store/modules/history.js index 446fd6eeba..46cfa3c12f 100644 --- a/themes-default/slim/src/store/modules/history.js +++ b/themes-default/slim/src/store/modules/history.js @@ -159,7 +159,7 @@ const actions = { if (!Array.isArray(sort)) { sort = [sort]; } - params.sort = sort; + params.sort = JSON.stringify(sort); } if (filter) { diff --git a/themes/dark/assets/js/medusa-runtime.js b/themes/dark/assets/js/medusa-runtime.js index 7eb8e873c3..856a70b37a 100644 --- a/themes/dark/assets/js/medusa-runtime.js +++ b/themes/dark/assets/js/medusa-runtime.js @@ -3029,7 +3029,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var _mutation_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../mutation-types */ \"./src/store/mutation-types.js\");\n/* harmony import */ var _utils_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils/core */ \"./src/utils/core.js\");\n\n\n\nconst state = {\n remote: {\n rows: [],\n totalRows: 0,\n page: 1,\n perPage: 25,\n sort: [{\n field: 'date',\n type: 'desc'\n }],\n filter: null\n },\n remoteCompact: {\n rows: [],\n totalRows: 0,\n page: 1,\n perPage: 25,\n sort: [{\n field: 'date',\n type: 'desc'\n }],\n filter: null\n },\n episodeHistory: {},\n historyLast: null,\n historyLastCompact: null,\n loading: false\n};\nconst mutations = {\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY_ROW](state, _ref) {\n let {\n history,\n compact\n } = _ref;\n // Only evaluate compact once.\n const historyKey = compact ? 'remoteCompact' : 'remote';\n\n // Update state, add one item at the top.\n state[historyKey].rows.unshift(history);\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY](state, _ref2) {\n let {\n history,\n compact\n } = _ref2;\n // Only evaluate compact once.\n const historyKey = compact ? 'remoteCompact' : 'remote';\n\n // Update state\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state[historyKey], 'rows', history);\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY](state, _ref3) {\n let {\n showSlug,\n history\n } = _ref3;\n // Add history data to episodeHistory, but without passing the show slug.\n for (const row of history) {\n if (!Object.keys(state.episodeHistory).includes(showSlug)) {\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory, showSlug, {});\n }\n const episodeSlug = (0,_utils_core__WEBPACK_IMPORTED_MODULE_1__.episodeToSlug)(row.season, row.episode);\n if (!state.episodeHistory[showSlug][episodeSlug]) {\n state.episodeHistory[showSlug][episodeSlug] = [];\n }\n state.episodeHistory[showSlug][episodeSlug].push(row);\n }\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_EPISODE_HISTORY](state, _ref4) {\n let {\n showSlug,\n episodeSlug,\n history\n } = _ref4;\n // Keep an object of shows, with their history per episode\n // Example: {tvdb1234: {s01e01: [history]}}\n\n if (!Object.keys(state.episodeHistory).includes(showSlug)) {\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory, showSlug, {});\n }\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory[showSlug], episodeSlug, history);\n },\n setLoading(state, value) {\n state.loading = value;\n },\n setRemoteTotal(state, _ref5) {\n let {\n total,\n compact = false\n } = _ref5;\n state[compact ? 'remoteCompact' : 'remote'].totalRows = total;\n }\n};\nconst getters = {\n getShowHistoryBySlug: state => showSlug => state.showHistory[showSlug],\n getLastReleaseName: state => _ref6 => {\n let {\n showSlug,\n episodeSlug\n } = _ref6;\n if (state.episodeHistory[showSlug] !== undefined) {\n if (state.episodeHistory[showSlug][episodeSlug] !== undefined) {\n if (state.episodeHistory[showSlug][episodeSlug].length === 1) {\n return state.episodeHistory[showSlug][episodeSlug][0].resource;\n }\n const filteredHistory = state.episodeHistory[showSlug][episodeSlug].slice().sort((a, b) => (a.actionDate - b.actionDate) * -1).filter(ep => ['Snatched', 'Downloaded'].includes(ep.statusName) && ep.resource !== '');\n if (filteredHistory.length > 0) {\n return filteredHistory[0].resource;\n }\n }\n }\n },\n getEpisodeHistory: state => _ref7 => {\n let {\n showSlug,\n episodeSlug\n } = _ref7;\n if (state.episodeHistory[showSlug] === undefined) {\n return [];\n }\n return state.episodeHistory[showSlug][episodeSlug] || [];\n },\n getSeasonHistory: state => _ref8 => {\n let {\n showSlug,\n season\n } = _ref8;\n if (state.episodeHistory[showSlug] === undefined) {\n return [];\n }\n return Object.values(state.episodeHistory[showSlug]).flat().filter(row => row.season === season) || [];\n }\n};\n\n/**\n * An object representing request parameters for getting a show from the API.\n *\n * @typedef {object} ShowGetParameters\n * @property {boolean} detailed Fetch detailed information? (e.g. scene/xem numbering)\n * @property {boolean} episodes Fetch seasons & episodes?\n */\n\nconst actions = {\n /**\n * Get show history from API and commit it to the store.\n *\n * @param {*} context The store context.\n * @param {ShowIdentifier&ShowGetParameters} parameters Request parameters.\n * @returns {Promise} The API response.\n */\n async getShowHistory(_ref9, _ref10) {\n let {\n rootState,\n commit\n } = _ref9;\n let {\n slug\n } = _ref10;\n const response = await rootState.auth.client.api.get(`/history/${slug}`);\n if (response.data.length > 0) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY, {\n showSlug: slug,\n history: response.data\n });\n }\n },\n /**\n * Get detailed history from API and commit them to the store.\n *\n * @param {*} context - The store context.\n * @param {object} args - arguments.\n */\n async getHistory(_ref11, args) {\n let {\n rootState,\n commit\n } = _ref11;\n let url = '/history';\n const page = args?.page || 1;\n const limit = args?.perPage || 1000;\n let sort = args?.sort || [{\n field: 'date',\n type: 'desc'\n }];\n const filter = args?.filter || {};\n const showSlug = args?.showSlug;\n const compact = args?.compact;\n const params = {\n page,\n limit\n };\n if (sort) {\n if (!Array.isArray(sort)) {\n sort = [sort];\n }\n params.sort = sort;\n }\n if (filter) {\n params.filter = filter;\n }\n if (showSlug) {\n url = `${url}/${showSlug}`;\n }\n if (compact) {\n params.compact = true;\n }\n commit('setLoading', true);\n let response = null;\n try {\n response = await rootState.auth.client.api.get(url, {\n params\n }); // eslint-disable-line no-await-in-loop\n if (response) {\n commit('setRemoteTotal', {\n total: Number(response.headers['x-pagination-count']),\n compact\n });\n if (showSlug) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY, {\n showSlug,\n history: response.data,\n compact\n });\n } else {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY, {\n history: response.data,\n compact\n });\n }\n }\n } catch (error) {\n if (error.response && error.response.status === 404) {\n console.debug(`No history available${showSlug ? ' for show ' + showSlug : ''}`);\n }\n }\n commit('setLoading', false);\n },\n /**\n * Get episode history from API and commit it to the store.\n *\n * @param {*} context The store context.\n * @param {ShowIdentifier&ShowGetParameters} parameters Request parameters.\n * @returns {Promise} The API response.\n */\n getShowEpisodeHistory(_ref12, _ref13) {\n let {\n rootState,\n commit\n } = _ref12;\n let {\n showSlug,\n episodeSlug\n } = _ref13;\n return new Promise(resolve => {\n rootState.auth.client.api.get(`/history/${showSlug}/episode/${episodeSlug}`).then(response => {\n if (response.data.length > 0) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_EPISODE_HISTORY, {\n showSlug,\n episodeSlug,\n history: response.data\n });\n }\n resolve();\n }).catch(() => {\n console.warn(`No episode history found for show ${showSlug} and episode ${episodeSlug}`);\n });\n });\n },\n updateHistory(_ref14, data) {\n let {\n rootState,\n commit\n } = _ref14;\n // Update store's search queue item. (provided through websocket)\n const compact = rootState.config.layout.history === 'compact';\n // We can't live update the compact layout, as it requires to aggregate the data.\n if (compact) {\n return;\n }\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY_ROW, {\n history: data\n });\n }\n};\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({\n state,\n mutations,\n getters,\n actions\n});\n\n//# sourceURL=webpack://slim/./src/store/modules/history.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var _mutation_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../mutation-types */ \"./src/store/mutation-types.js\");\n/* harmony import */ var _utils_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils/core */ \"./src/utils/core.js\");\n\n\n\nconst state = {\n remote: {\n rows: [],\n totalRows: 0,\n page: 1,\n perPage: 25,\n sort: [{\n field: 'date',\n type: 'desc'\n }],\n filter: null\n },\n remoteCompact: {\n rows: [],\n totalRows: 0,\n page: 1,\n perPage: 25,\n sort: [{\n field: 'date',\n type: 'desc'\n }],\n filter: null\n },\n episodeHistory: {},\n historyLast: null,\n historyLastCompact: null,\n loading: false\n};\nconst mutations = {\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY_ROW](state, _ref) {\n let {\n history,\n compact\n } = _ref;\n // Only evaluate compact once.\n const historyKey = compact ? 'remoteCompact' : 'remote';\n\n // Update state, add one item at the top.\n state[historyKey].rows.unshift(history);\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY](state, _ref2) {\n let {\n history,\n compact\n } = _ref2;\n // Only evaluate compact once.\n const historyKey = compact ? 'remoteCompact' : 'remote';\n\n // Update state\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state[historyKey], 'rows', history);\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY](state, _ref3) {\n let {\n showSlug,\n history\n } = _ref3;\n // Add history data to episodeHistory, but without passing the show slug.\n for (const row of history) {\n if (!Object.keys(state.episodeHistory).includes(showSlug)) {\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory, showSlug, {});\n }\n const episodeSlug = (0,_utils_core__WEBPACK_IMPORTED_MODULE_1__.episodeToSlug)(row.season, row.episode);\n if (!state.episodeHistory[showSlug][episodeSlug]) {\n state.episodeHistory[showSlug][episodeSlug] = [];\n }\n state.episodeHistory[showSlug][episodeSlug].push(row);\n }\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_EPISODE_HISTORY](state, _ref4) {\n let {\n showSlug,\n episodeSlug,\n history\n } = _ref4;\n // Keep an object of shows, with their history per episode\n // Example: {tvdb1234: {s01e01: [history]}}\n\n if (!Object.keys(state.episodeHistory).includes(showSlug)) {\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory, showSlug, {});\n }\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory[showSlug], episodeSlug, history);\n },\n setLoading(state, value) {\n state.loading = value;\n },\n setRemoteTotal(state, _ref5) {\n let {\n total,\n compact = false\n } = _ref5;\n state[compact ? 'remoteCompact' : 'remote'].totalRows = total;\n }\n};\nconst getters = {\n getShowHistoryBySlug: state => showSlug => state.showHistory[showSlug],\n getLastReleaseName: state => _ref6 => {\n let {\n showSlug,\n episodeSlug\n } = _ref6;\n if (state.episodeHistory[showSlug] !== undefined) {\n if (state.episodeHistory[showSlug][episodeSlug] !== undefined) {\n if (state.episodeHistory[showSlug][episodeSlug].length === 1) {\n return state.episodeHistory[showSlug][episodeSlug][0].resource;\n }\n const filteredHistory = state.episodeHistory[showSlug][episodeSlug].slice().sort((a, b) => (a.actionDate - b.actionDate) * -1).filter(ep => ['Snatched', 'Downloaded'].includes(ep.statusName) && ep.resource !== '');\n if (filteredHistory.length > 0) {\n return filteredHistory[0].resource;\n }\n }\n }\n },\n getEpisodeHistory: state => _ref7 => {\n let {\n showSlug,\n episodeSlug\n } = _ref7;\n if (state.episodeHistory[showSlug] === undefined) {\n return [];\n }\n return state.episodeHistory[showSlug][episodeSlug] || [];\n },\n getSeasonHistory: state => _ref8 => {\n let {\n showSlug,\n season\n } = _ref8;\n if (state.episodeHistory[showSlug] === undefined) {\n return [];\n }\n return Object.values(state.episodeHistory[showSlug]).flat().filter(row => row.season === season) || [];\n }\n};\n\n/**\n * An object representing request parameters for getting a show from the API.\n *\n * @typedef {object} ShowGetParameters\n * @property {boolean} detailed Fetch detailed information? (e.g. scene/xem numbering)\n * @property {boolean} episodes Fetch seasons & episodes?\n */\n\nconst actions = {\n /**\n * Get show history from API and commit it to the store.\n *\n * @param {*} context The store context.\n * @param {ShowIdentifier&ShowGetParameters} parameters Request parameters.\n * @returns {Promise} The API response.\n */\n async getShowHistory(_ref9, _ref10) {\n let {\n rootState,\n commit\n } = _ref9;\n let {\n slug\n } = _ref10;\n const response = await rootState.auth.client.api.get(`/history/${slug}`);\n if (response.data.length > 0) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY, {\n showSlug: slug,\n history: response.data\n });\n }\n },\n /**\n * Get detailed history from API and commit them to the store.\n *\n * @param {*} context - The store context.\n * @param {object} args - arguments.\n */\n async getHistory(_ref11, args) {\n let {\n rootState,\n commit\n } = _ref11;\n let url = '/history';\n const page = args?.page || 1;\n const limit = args?.perPage || 1000;\n let sort = args?.sort || [{\n field: 'date',\n type: 'desc'\n }];\n const filter = args?.filter || {};\n const showSlug = args?.showSlug;\n const compact = args?.compact;\n const params = {\n page,\n limit\n };\n if (sort) {\n if (!Array.isArray(sort)) {\n sort = [sort];\n }\n params.sort = JSON.stringify(sort);\n }\n if (filter) {\n params.filter = filter;\n }\n if (showSlug) {\n url = `${url}/${showSlug}`;\n }\n if (compact) {\n params.compact = true;\n }\n commit('setLoading', true);\n let response = null;\n try {\n response = await rootState.auth.client.api.get(url, {\n params\n }); // eslint-disable-line no-await-in-loop\n if (response) {\n commit('setRemoteTotal', {\n total: Number(response.headers['x-pagination-count']),\n compact\n });\n if (showSlug) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY, {\n showSlug,\n history: response.data,\n compact\n });\n } else {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY, {\n history: response.data,\n compact\n });\n }\n }\n } catch (error) {\n if (error.response && error.response.status === 404) {\n console.debug(`No history available${showSlug ? ' for show ' + showSlug : ''}`);\n }\n }\n commit('setLoading', false);\n },\n /**\n * Get episode history from API and commit it to the store.\n *\n * @param {*} context The store context.\n * @param {ShowIdentifier&ShowGetParameters} parameters Request parameters.\n * @returns {Promise} The API response.\n */\n getShowEpisodeHistory(_ref12, _ref13) {\n let {\n rootState,\n commit\n } = _ref12;\n let {\n showSlug,\n episodeSlug\n } = _ref13;\n return new Promise(resolve => {\n rootState.auth.client.api.get(`/history/${showSlug}/episode/${episodeSlug}`).then(response => {\n if (response.data.length > 0) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_EPISODE_HISTORY, {\n showSlug,\n episodeSlug,\n history: response.data\n });\n }\n resolve();\n }).catch(() => {\n console.warn(`No episode history found for show ${showSlug} and episode ${episodeSlug}`);\n });\n });\n },\n updateHistory(_ref14, data) {\n let {\n rootState,\n commit\n } = _ref14;\n // Update store's search queue item. (provided through websocket)\n const compact = rootState.config.layout.history === 'compact';\n // We can't live update the compact layout, as it requires to aggregate the data.\n if (compact) {\n return;\n }\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY_ROW, {\n history: data\n });\n }\n};\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({\n state,\n mutations,\n getters,\n actions\n});\n\n//# sourceURL=webpack://slim/./src/store/modules/history.js?"); /***/ }), diff --git a/themes/light/assets/js/medusa-runtime.js b/themes/light/assets/js/medusa-runtime.js index 7eb8e873c3..856a70b37a 100644 --- a/themes/light/assets/js/medusa-runtime.js +++ b/themes/light/assets/js/medusa-runtime.js @@ -3029,7 +3029,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var _mutation_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../mutation-types */ \"./src/store/mutation-types.js\");\n/* harmony import */ var _utils_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils/core */ \"./src/utils/core.js\");\n\n\n\nconst state = {\n remote: {\n rows: [],\n totalRows: 0,\n page: 1,\n perPage: 25,\n sort: [{\n field: 'date',\n type: 'desc'\n }],\n filter: null\n },\n remoteCompact: {\n rows: [],\n totalRows: 0,\n page: 1,\n perPage: 25,\n sort: [{\n field: 'date',\n type: 'desc'\n }],\n filter: null\n },\n episodeHistory: {},\n historyLast: null,\n historyLastCompact: null,\n loading: false\n};\nconst mutations = {\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY_ROW](state, _ref) {\n let {\n history,\n compact\n } = _ref;\n // Only evaluate compact once.\n const historyKey = compact ? 'remoteCompact' : 'remote';\n\n // Update state, add one item at the top.\n state[historyKey].rows.unshift(history);\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY](state, _ref2) {\n let {\n history,\n compact\n } = _ref2;\n // Only evaluate compact once.\n const historyKey = compact ? 'remoteCompact' : 'remote';\n\n // Update state\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state[historyKey], 'rows', history);\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY](state, _ref3) {\n let {\n showSlug,\n history\n } = _ref3;\n // Add history data to episodeHistory, but without passing the show slug.\n for (const row of history) {\n if (!Object.keys(state.episodeHistory).includes(showSlug)) {\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory, showSlug, {});\n }\n const episodeSlug = (0,_utils_core__WEBPACK_IMPORTED_MODULE_1__.episodeToSlug)(row.season, row.episode);\n if (!state.episodeHistory[showSlug][episodeSlug]) {\n state.episodeHistory[showSlug][episodeSlug] = [];\n }\n state.episodeHistory[showSlug][episodeSlug].push(row);\n }\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_EPISODE_HISTORY](state, _ref4) {\n let {\n showSlug,\n episodeSlug,\n history\n } = _ref4;\n // Keep an object of shows, with their history per episode\n // Example: {tvdb1234: {s01e01: [history]}}\n\n if (!Object.keys(state.episodeHistory).includes(showSlug)) {\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory, showSlug, {});\n }\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory[showSlug], episodeSlug, history);\n },\n setLoading(state, value) {\n state.loading = value;\n },\n setRemoteTotal(state, _ref5) {\n let {\n total,\n compact = false\n } = _ref5;\n state[compact ? 'remoteCompact' : 'remote'].totalRows = total;\n }\n};\nconst getters = {\n getShowHistoryBySlug: state => showSlug => state.showHistory[showSlug],\n getLastReleaseName: state => _ref6 => {\n let {\n showSlug,\n episodeSlug\n } = _ref6;\n if (state.episodeHistory[showSlug] !== undefined) {\n if (state.episodeHistory[showSlug][episodeSlug] !== undefined) {\n if (state.episodeHistory[showSlug][episodeSlug].length === 1) {\n return state.episodeHistory[showSlug][episodeSlug][0].resource;\n }\n const filteredHistory = state.episodeHistory[showSlug][episodeSlug].slice().sort((a, b) => (a.actionDate - b.actionDate) * -1).filter(ep => ['Snatched', 'Downloaded'].includes(ep.statusName) && ep.resource !== '');\n if (filteredHistory.length > 0) {\n return filteredHistory[0].resource;\n }\n }\n }\n },\n getEpisodeHistory: state => _ref7 => {\n let {\n showSlug,\n episodeSlug\n } = _ref7;\n if (state.episodeHistory[showSlug] === undefined) {\n return [];\n }\n return state.episodeHistory[showSlug][episodeSlug] || [];\n },\n getSeasonHistory: state => _ref8 => {\n let {\n showSlug,\n season\n } = _ref8;\n if (state.episodeHistory[showSlug] === undefined) {\n return [];\n }\n return Object.values(state.episodeHistory[showSlug]).flat().filter(row => row.season === season) || [];\n }\n};\n\n/**\n * An object representing request parameters for getting a show from the API.\n *\n * @typedef {object} ShowGetParameters\n * @property {boolean} detailed Fetch detailed information? (e.g. scene/xem numbering)\n * @property {boolean} episodes Fetch seasons & episodes?\n */\n\nconst actions = {\n /**\n * Get show history from API and commit it to the store.\n *\n * @param {*} context The store context.\n * @param {ShowIdentifier&ShowGetParameters} parameters Request parameters.\n * @returns {Promise} The API response.\n */\n async getShowHistory(_ref9, _ref10) {\n let {\n rootState,\n commit\n } = _ref9;\n let {\n slug\n } = _ref10;\n const response = await rootState.auth.client.api.get(`/history/${slug}`);\n if (response.data.length > 0) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY, {\n showSlug: slug,\n history: response.data\n });\n }\n },\n /**\n * Get detailed history from API and commit them to the store.\n *\n * @param {*} context - The store context.\n * @param {object} args - arguments.\n */\n async getHistory(_ref11, args) {\n let {\n rootState,\n commit\n } = _ref11;\n let url = '/history';\n const page = args?.page || 1;\n const limit = args?.perPage || 1000;\n let sort = args?.sort || [{\n field: 'date',\n type: 'desc'\n }];\n const filter = args?.filter || {};\n const showSlug = args?.showSlug;\n const compact = args?.compact;\n const params = {\n page,\n limit\n };\n if (sort) {\n if (!Array.isArray(sort)) {\n sort = [sort];\n }\n params.sort = sort;\n }\n if (filter) {\n params.filter = filter;\n }\n if (showSlug) {\n url = `${url}/${showSlug}`;\n }\n if (compact) {\n params.compact = true;\n }\n commit('setLoading', true);\n let response = null;\n try {\n response = await rootState.auth.client.api.get(url, {\n params\n }); // eslint-disable-line no-await-in-loop\n if (response) {\n commit('setRemoteTotal', {\n total: Number(response.headers['x-pagination-count']),\n compact\n });\n if (showSlug) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY, {\n showSlug,\n history: response.data,\n compact\n });\n } else {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY, {\n history: response.data,\n compact\n });\n }\n }\n } catch (error) {\n if (error.response && error.response.status === 404) {\n console.debug(`No history available${showSlug ? ' for show ' + showSlug : ''}`);\n }\n }\n commit('setLoading', false);\n },\n /**\n * Get episode history from API and commit it to the store.\n *\n * @param {*} context The store context.\n * @param {ShowIdentifier&ShowGetParameters} parameters Request parameters.\n * @returns {Promise} The API response.\n */\n getShowEpisodeHistory(_ref12, _ref13) {\n let {\n rootState,\n commit\n } = _ref12;\n let {\n showSlug,\n episodeSlug\n } = _ref13;\n return new Promise(resolve => {\n rootState.auth.client.api.get(`/history/${showSlug}/episode/${episodeSlug}`).then(response => {\n if (response.data.length > 0) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_EPISODE_HISTORY, {\n showSlug,\n episodeSlug,\n history: response.data\n });\n }\n resolve();\n }).catch(() => {\n console.warn(`No episode history found for show ${showSlug} and episode ${episodeSlug}`);\n });\n });\n },\n updateHistory(_ref14, data) {\n let {\n rootState,\n commit\n } = _ref14;\n // Update store's search queue item. (provided through websocket)\n const compact = rootState.config.layout.history === 'compact';\n // We can't live update the compact layout, as it requires to aggregate the data.\n if (compact) {\n return;\n }\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY_ROW, {\n history: data\n });\n }\n};\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({\n state,\n mutations,\n getters,\n actions\n});\n\n//# sourceURL=webpack://slim/./src/store/modules/history.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var _mutation_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../mutation-types */ \"./src/store/mutation-types.js\");\n/* harmony import */ var _utils_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../utils/core */ \"./src/utils/core.js\");\n\n\n\nconst state = {\n remote: {\n rows: [],\n totalRows: 0,\n page: 1,\n perPage: 25,\n sort: [{\n field: 'date',\n type: 'desc'\n }],\n filter: null\n },\n remoteCompact: {\n rows: [],\n totalRows: 0,\n page: 1,\n perPage: 25,\n sort: [{\n field: 'date',\n type: 'desc'\n }],\n filter: null\n },\n episodeHistory: {},\n historyLast: null,\n historyLastCompact: null,\n loading: false\n};\nconst mutations = {\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY_ROW](state, _ref) {\n let {\n history,\n compact\n } = _ref;\n // Only evaluate compact once.\n const historyKey = compact ? 'remoteCompact' : 'remote';\n\n // Update state, add one item at the top.\n state[historyKey].rows.unshift(history);\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY](state, _ref2) {\n let {\n history,\n compact\n } = _ref2;\n // Only evaluate compact once.\n const historyKey = compact ? 'remoteCompact' : 'remote';\n\n // Update state\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state[historyKey], 'rows', history);\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY](state, _ref3) {\n let {\n showSlug,\n history\n } = _ref3;\n // Add history data to episodeHistory, but without passing the show slug.\n for (const row of history) {\n if (!Object.keys(state.episodeHistory).includes(showSlug)) {\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory, showSlug, {});\n }\n const episodeSlug = (0,_utils_core__WEBPACK_IMPORTED_MODULE_1__.episodeToSlug)(row.season, row.episode);\n if (!state.episodeHistory[showSlug][episodeSlug]) {\n state.episodeHistory[showSlug][episodeSlug] = [];\n }\n state.episodeHistory[showSlug][episodeSlug].push(row);\n }\n },\n [_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_EPISODE_HISTORY](state, _ref4) {\n let {\n showSlug,\n episodeSlug,\n history\n } = _ref4;\n // Keep an object of shows, with their history per episode\n // Example: {tvdb1234: {s01e01: [history]}}\n\n if (!Object.keys(state.episodeHistory).includes(showSlug)) {\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory, showSlug, {});\n }\n vue__WEBPACK_IMPORTED_MODULE_2__[\"default\"].set(state.episodeHistory[showSlug], episodeSlug, history);\n },\n setLoading(state, value) {\n state.loading = value;\n },\n setRemoteTotal(state, _ref5) {\n let {\n total,\n compact = false\n } = _ref5;\n state[compact ? 'remoteCompact' : 'remote'].totalRows = total;\n }\n};\nconst getters = {\n getShowHistoryBySlug: state => showSlug => state.showHistory[showSlug],\n getLastReleaseName: state => _ref6 => {\n let {\n showSlug,\n episodeSlug\n } = _ref6;\n if (state.episodeHistory[showSlug] !== undefined) {\n if (state.episodeHistory[showSlug][episodeSlug] !== undefined) {\n if (state.episodeHistory[showSlug][episodeSlug].length === 1) {\n return state.episodeHistory[showSlug][episodeSlug][0].resource;\n }\n const filteredHistory = state.episodeHistory[showSlug][episodeSlug].slice().sort((a, b) => (a.actionDate - b.actionDate) * -1).filter(ep => ['Snatched', 'Downloaded'].includes(ep.statusName) && ep.resource !== '');\n if (filteredHistory.length > 0) {\n return filteredHistory[0].resource;\n }\n }\n }\n },\n getEpisodeHistory: state => _ref7 => {\n let {\n showSlug,\n episodeSlug\n } = _ref7;\n if (state.episodeHistory[showSlug] === undefined) {\n return [];\n }\n return state.episodeHistory[showSlug][episodeSlug] || [];\n },\n getSeasonHistory: state => _ref8 => {\n let {\n showSlug,\n season\n } = _ref8;\n if (state.episodeHistory[showSlug] === undefined) {\n return [];\n }\n return Object.values(state.episodeHistory[showSlug]).flat().filter(row => row.season === season) || [];\n }\n};\n\n/**\n * An object representing request parameters for getting a show from the API.\n *\n * @typedef {object} ShowGetParameters\n * @property {boolean} detailed Fetch detailed information? (e.g. scene/xem numbering)\n * @property {boolean} episodes Fetch seasons & episodes?\n */\n\nconst actions = {\n /**\n * Get show history from API and commit it to the store.\n *\n * @param {*} context The store context.\n * @param {ShowIdentifier&ShowGetParameters} parameters Request parameters.\n * @returns {Promise} The API response.\n */\n async getShowHistory(_ref9, _ref10) {\n let {\n rootState,\n commit\n } = _ref9;\n let {\n slug\n } = _ref10;\n const response = await rootState.auth.client.api.get(`/history/${slug}`);\n if (response.data.length > 0) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY, {\n showSlug: slug,\n history: response.data\n });\n }\n },\n /**\n * Get detailed history from API and commit them to the store.\n *\n * @param {*} context - The store context.\n * @param {object} args - arguments.\n */\n async getHistory(_ref11, args) {\n let {\n rootState,\n commit\n } = _ref11;\n let url = '/history';\n const page = args?.page || 1;\n const limit = args?.perPage || 1000;\n let sort = args?.sort || [{\n field: 'date',\n type: 'desc'\n }];\n const filter = args?.filter || {};\n const showSlug = args?.showSlug;\n const compact = args?.compact;\n const params = {\n page,\n limit\n };\n if (sort) {\n if (!Array.isArray(sort)) {\n sort = [sort];\n }\n params.sort = JSON.stringify(sort);\n }\n if (filter) {\n params.filter = filter;\n }\n if (showSlug) {\n url = `${url}/${showSlug}`;\n }\n if (compact) {\n params.compact = true;\n }\n commit('setLoading', true);\n let response = null;\n try {\n response = await rootState.auth.client.api.get(url, {\n params\n }); // eslint-disable-line no-await-in-loop\n if (response) {\n commit('setRemoteTotal', {\n total: Number(response.headers['x-pagination-count']),\n compact\n });\n if (showSlug) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_HISTORY, {\n showSlug,\n history: response.data,\n compact\n });\n } else {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY, {\n history: response.data,\n compact\n });\n }\n }\n } catch (error) {\n if (error.response && error.response.status === 404) {\n console.debug(`No history available${showSlug ? ' for show ' + showSlug : ''}`);\n }\n }\n commit('setLoading', false);\n },\n /**\n * Get episode history from API and commit it to the store.\n *\n * @param {*} context The store context.\n * @param {ShowIdentifier&ShowGetParameters} parameters Request parameters.\n * @returns {Promise} The API response.\n */\n getShowEpisodeHistory(_ref12, _ref13) {\n let {\n rootState,\n commit\n } = _ref12;\n let {\n showSlug,\n episodeSlug\n } = _ref13;\n return new Promise(resolve => {\n rootState.auth.client.api.get(`/history/${showSlug}/episode/${episodeSlug}`).then(response => {\n if (response.data.length > 0) {\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_SHOW_EPISODE_HISTORY, {\n showSlug,\n episodeSlug,\n history: response.data\n });\n }\n resolve();\n }).catch(() => {\n console.warn(`No episode history found for show ${showSlug} and episode ${episodeSlug}`);\n });\n });\n },\n updateHistory(_ref14, data) {\n let {\n rootState,\n commit\n } = _ref14;\n // Update store's search queue item. (provided through websocket)\n const compact = rootState.config.layout.history === 'compact';\n // We can't live update the compact layout, as it requires to aggregate the data.\n if (compact) {\n return;\n }\n commit(_mutation_types__WEBPACK_IMPORTED_MODULE_0__.ADD_HISTORY_ROW, {\n history: data\n });\n }\n};\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({\n state,\n mutations,\n getters,\n actions\n});\n\n//# sourceURL=webpack://slim/./src/store/modules/history.js?"); /***/ }),