feat(handler): return handler issues as streams for better visibility

This commit is contained in:
WebStreamr 2025-05-13 11:58:49 +00:00
parent 68a7a41606
commit d4db80789a
No known key found for this signature in database

View file

@ -1,4 +1,5 @@
import { Request, Response, Router } from 'express';
import { Stream } from 'stremio-addon-sdk';
import { Handler } from '../handler';
import { Config, UrlResult } from '../types';
import bytes from 'bytes';
@ -43,6 +44,8 @@ export class StreamController {
return;
}
const streams: Stream[] = [];
const urlResults: UrlResult[] = [];
const handlerPromises = selectedHandlers.map(async (handler) => {
if (!handler.contentTypes.includes(type)) {
@ -55,6 +58,11 @@ export class StreamController {
urlResults.push(...(handlerUrlResults.filter(handlerUrlResult => handlerUrlResult !== undefined)));
} catch (err) {
streams.push({
name: 'WebStreamr',
title: `❌ Error with handler "${handler.id}". Please check the logs or create an issue if this persists.`,
ytId: 'E4WlUXrJgy4',
});
this.logger.error(`${handler.id} error: ` + err);
}
});
@ -71,29 +79,31 @@ export class StreamController {
this.logger.info(`Return ${urlResults.length} streams`);
const streams = urlResults.map((urlResult) => {
let name = 'WebStreamr';
if (urlResult.height) {
name += ` ${urlResult.height}p`;
}
streams.push(
...urlResults.map((urlResult) => {
let name = 'WebStreamr';
if (urlResult.height) {
name += ` ${urlResult.height}p`;
}
let title = urlResult.label;
if (urlResult.bytes) {
title += ` | 💾 ${bytes.format(urlResult.bytes, { unitSeparator: ' ' })}`;
}
if (urlResult.countryCode) {
title += ` | ${flag(urlResult.countryCode)}`;
}
let title = urlResult.label;
if (urlResult.bytes) {
title += ` | 💾 ${bytes.format(urlResult.bytes, { unitSeparator: ' ' })}`;
}
if (urlResult.countryCode) {
title += ` | ${flag(urlResult.countryCode)}`;
}
return {
url: urlResult.url.toString(),
name,
title,
behaviourHints: {
group: `webstreamr-${urlResult.sourceId}`,
},
};
});
return {
url: urlResult.url.toString(),
name,
title,
behaviourHints: {
group: `webstreamr-${urlResult.sourceId}`,
},
};
}),
);
res.send(JSON.stringify({ streams }));
};