mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-17 23:11:41 +00:00
Refactor stream resource validation in stremioService; improve logging for invalid resources and streamline resource checking logic to enhance clarity and maintainability. Remove redundant logging in useMetadata for cleaner output.
This commit is contained in:
parent
1aebcf6c6c
commit
b46e491afa
2 changed files with 20 additions and 32 deletions
|
|
@ -135,15 +135,10 @@ export const useMetadata = ({ id, type }: UseMetadataProps): UseMetadataReturn =
|
|||
} else if (streams && addonId && addonName) {
|
||||
logger.log(`✅ [${logPrefix}:${sourceName}] Received ${streams.length} streams from ${addonName} (${addonId}) after ${processTime}ms`);
|
||||
|
||||
// Log the raw streams received for this addon
|
||||
logger.log(`📦 [${logPrefix}:${sourceName}] Raw streams for ${addonName} (${addonId}):`, JSON.stringify(streams.slice(0, 2), null, 2)); // Log first 2 raw streams
|
||||
|
||||
if (streams.length > 0) {
|
||||
// Use the streams directly as they are already processed by stremioService
|
||||
const updateState = (prevState: GroupedStreams): GroupedStreams => {
|
||||
logger.log(`🔄 [${logPrefix}:${sourceName}] Updating state for addon ${addonName} (${addonId})`);
|
||||
// Log the streams being added to state
|
||||
logger.log(`💾 [${logPrefix}:${sourceName}] Adding processed streams for ${addonName} (${addonId}) to state:`, JSON.stringify(streams.slice(0, 2), null, 2)); // Log first 2 processed streams
|
||||
return {
|
||||
...prevState,
|
||||
[addonId]: {
|
||||
|
|
|
|||
|
|
@ -552,8 +552,8 @@ class StremioService {
|
|||
// Find addons that provide streams and sort them by installation order
|
||||
const streamAddons = addons
|
||||
.filter(addon => {
|
||||
if (!addon.resources) {
|
||||
logger.log(`⚠️ [getStreams] Addon ${addon.id} has no resources`);
|
||||
if (!addon.resources || !Array.isArray(addon.resources)) {
|
||||
logger.log(`⚠️ [getStreams] Addon ${addon.id} has no valid resources array`);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -562,32 +562,25 @@ class StremioService {
|
|||
|
||||
let hasStreamResource = false;
|
||||
|
||||
// Handle both resource formats:
|
||||
// 1. Standard format: array of ResourceObjects with name and types properties
|
||||
// 2. Simple format: string array ["stream"] with separate types array in the addon
|
||||
|
||||
// Check for standard format (array of objects)
|
||||
if (addon.resources.length > 0 && typeof addon.resources[0] === 'object') {
|
||||
// Type-safe check for standard format (objects with name/types)
|
||||
hasStreamResource = addon.resources.some(
|
||||
resource => {
|
||||
if (typeof resource === 'object' && resource !== null) {
|
||||
const typedResource = resource as ResourceObject;
|
||||
return typedResource.name === 'stream' &&
|
||||
Array.isArray(typedResource.types) &&
|
||||
typedResource.types.includes(type);
|
||||
}
|
||||
return false;
|
||||
// Iterate through the resources array, checking each element
|
||||
for (const resource of addon.resources) {
|
||||
// Check if the current element is a ResourceObject
|
||||
if (typeof resource === 'object' && resource !== null && 'name' in resource) {
|
||||
const typedResource = resource as ResourceObject;
|
||||
if (typedResource.name === 'stream' &&
|
||||
Array.isArray(typedResource.types) &&
|
||||
typedResource.types.includes(type)) {
|
||||
hasStreamResource = true;
|
||||
break; // Found the stream resource object, no need to check further
|
||||
}
|
||||
);
|
||||
}
|
||||
// Check for simple format (string array)
|
||||
else if (Array.isArray(addon.resources) && addon.types) {
|
||||
// Check if resources array contains 'stream' and types array includes the desired type
|
||||
hasStreamResource =
|
||||
(addon.resources as unknown as string[]).includes('stream') &&
|
||||
Array.isArray(addon.types) &&
|
||||
addon.types.includes(type);
|
||||
}
|
||||
// Check if the element is the simple string "stream" AND the addon has a top-level types array
|
||||
else if (typeof resource === 'string' && resource === 'stream' && addon.types) {
|
||||
if (Array.isArray(addon.types) && addon.types.includes(type)) {
|
||||
hasStreamResource = true;
|
||||
break; // Found the simple stream resource string and type support
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasStreamResource) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue