mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
installed addons checks improved
This commit is contained in:
parent
b1d5377453
commit
437e47f36b
1 changed files with 51 additions and 36 deletions
|
|
@ -2,6 +2,9 @@ const React = require('react');
|
|||
const { useServices } = require('stremio/services');
|
||||
const { useModelState } = require('stremio/common');
|
||||
|
||||
const INSTALLED_CATALOG_ID = 'INSTALLED';
|
||||
const INSTALLED_CATALOG_BASE = '';
|
||||
|
||||
const initAddonsState = () => ({
|
||||
selectable: {
|
||||
types: [],
|
||||
|
|
@ -11,48 +14,60 @@ const initAddonsState = () => ({
|
|||
});
|
||||
|
||||
const mapAddonsStateWithCtx = (addons, ctx) => {
|
||||
const installedTypes = [...new Set([].concat(...ctx.profile.addons.map(addon => addon.manifest.types)))].map((type) => (
|
||||
{
|
||||
name: type,
|
||||
const installedSelectableTypes = [...new Set([].concat(...ctx.profile.addons.map(addon => addon.manifest.types)))].map((type) => ({
|
||||
name: type,
|
||||
request: {
|
||||
base: INSTALLED_CATALOG_BASE,
|
||||
path: {
|
||||
resource: 'addon_catalog',
|
||||
type_name: type,
|
||||
id: INSTALLED_CATALOG_ID,
|
||||
extra: []
|
||||
}
|
||||
}
|
||||
}));
|
||||
const selectable = {
|
||||
types: addons.selected !== null && addons.selected.request.path.id === INSTALLED_CATALOG_ID ? installedSelectableTypes : addons.selectable.types,
|
||||
catalogs: addons.selectable.catalogs.concat({
|
||||
name: 'Installed',
|
||||
addon_name: '',
|
||||
request: {
|
||||
base: 'https://v3-cinemeta.strem.io/manifest.json',
|
||||
base: INSTALLED_CATALOG_BASE,
|
||||
path: {
|
||||
resource: 'addon_catalog',
|
||||
type_name: type,
|
||||
id: 'INSTALLED',
|
||||
type_name: installedSelectableTypes[0].request.path.type_name,
|
||||
id: INSTALLED_CATALOG_ID,
|
||||
extra: []
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
const selectable = {
|
||||
types: addons.selected.request.path.id === 'INSTALLED' ? installedTypes : addons.selectable.types,
|
||||
catalogs: addons.selectable.catalogs.concat(
|
||||
{
|
||||
name: 'Installed',
|
||||
addon_name: '',
|
||||
request: {
|
||||
base: 'https://v3-cinemeta.strem.io/manifest.json',
|
||||
path: {
|
||||
resource: 'addon_catalog',
|
||||
type_name: installedTypes[0].name,
|
||||
id: 'INSTALLED',
|
||||
extra: []
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
};
|
||||
const catalog_resource = addons.catalog_resource !== null && addons.catalog_resource.content.type === 'Ready' ?
|
||||
const catalog_resource = addons.selected !== null && addons.selected.request.base === INSTALLED_CATALOG_BASE && addons.selected.request.path.id === INSTALLED_CATALOG_ID ?
|
||||
{
|
||||
request: addons.catalog_resource.request,
|
||||
request: addons.selected.request,
|
||||
content: {
|
||||
type: addons.catalog_resource.content.type,
|
||||
content: (addons.catalog_resource.request.path.id === 'INSTALLED' ?
|
||||
ctx.profile.addons.filter((addon) => addon.manifest.types.includes(addons.selected.request.path.type_name))
|
||||
:
|
||||
addons.catalog_resource.content.content)
|
||||
.map((addon) => ({
|
||||
type: 'Ready',
|
||||
content: ctx.profile.addons.filter((addon) => addon.manifest.types.includes(addons.selected.request.path.type_name)).map((addon) => ({
|
||||
transportUrl: addon.transportUrl,
|
||||
installed: true,
|
||||
manifest: {
|
||||
id: addon.manifest.id,
|
||||
name: addon.manifest.name,
|
||||
version: addon.manifest.version,
|
||||
logo: addon.manifest.logo,
|
||||
description: addon.manifest.description,
|
||||
types: addon.manifest.types
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
:
|
||||
addons.catalog_resource !== null && addons.catalog_resource.content.type === 'Ready' ?
|
||||
{
|
||||
request: addons.catalog_resource.request,
|
||||
content: {
|
||||
type: addons.catalog_resource.content.type,
|
||||
content: addons.catalog_resource.content.content.map((addon) => ({
|
||||
transportUrl: addon.transportUrl,
|
||||
installed: ctx.profile.addons.some(({ transportUrl }) => transportUrl === addon.transportUrl),
|
||||
manifest: {
|
||||
|
|
@ -64,10 +79,10 @@ const mapAddonsStateWithCtx = (addons, ctx) => {
|
|||
types: addon.manifest.types
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
:
|
||||
addons.catalog_resource;
|
||||
:
|
||||
addons.catalog_resource;
|
||||
return { selectable, catalog_resource };
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue