feat(handler): return handler issues as streams for better visibility
This commit is contained in:
parent
68a7a41606
commit
d4db80789a
1 changed files with 31 additions and 21 deletions
|
|
@ -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 }));
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue