installed addons checks improved

This commit is contained in:
svetlagasheva 2020-02-25 18:51:47 +02:00
parent b1d5377453
commit 437e47f36b

View file

@ -2,6 +2,9 @@ const React = require('react');
const { useServices } = require('stremio/services'); const { useServices } = require('stremio/services');
const { useModelState } = require('stremio/common'); const { useModelState } = require('stremio/common');
const INSTALLED_CATALOG_ID = 'INSTALLED';
const INSTALLED_CATALOG_BASE = '';
const initAddonsState = () => ({ const initAddonsState = () => ({
selectable: { selectable: {
types: [], types: [],
@ -11,48 +14,60 @@ const initAddonsState = () => ({
}); });
const mapAddonsStateWithCtx = (addons, ctx) => { const mapAddonsStateWithCtx = (addons, ctx) => {
const installedTypes = [...new Set([].concat(...ctx.profile.addons.map(addon => addon.manifest.types)))].map((type) => ( const installedSelectableTypes = [...new Set([].concat(...ctx.profile.addons.map(addon => addon.manifest.types)))].map((type) => ({
{ name: 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: { request: {
base: 'https://v3-cinemeta.strem.io/manifest.json', base: INSTALLED_CATALOG_BASE,
path: { path: {
resource: 'addon_catalog', resource: 'addon_catalog',
type_name: type, type_name: installedSelectableTypes[0].request.path.type_name,
id: 'INSTALLED', id: INSTALLED_CATALOG_ID,
extra: [] 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: { content: {
type: addons.catalog_resource.content.type, type: 'Ready',
content: (addons.catalog_resource.request.path.id === 'INSTALLED' ? content: ctx.profile.addons.filter((addon) => addon.manifest.types.includes(addons.selected.request.path.type_name)).map((addon) => ({
ctx.profile.addons.filter((addon) => addon.manifest.types.includes(addons.selected.request.path.type_name)) transportUrl: addon.transportUrl,
: installed: true,
addons.catalog_resource.content.content) manifest: {
.map((addon) => ({ 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, transportUrl: addon.transportUrl,
installed: ctx.profile.addons.some(({ transportUrl }) => transportUrl === addon.transportUrl), installed: ctx.profile.addons.some(({ transportUrl }) => transportUrl === addon.transportUrl),
manifest: { manifest: {
@ -64,10 +79,10 @@ const mapAddonsStateWithCtx = (addons, ctx) => {
types: addon.manifest.types types: addon.manifest.types
} }
})) }))
}
} }
} :
: addons.catalog_resource;
addons.catalog_resource;
return { selectable, catalog_resource }; return { selectable, catalog_resource };
}; };