Kapitel 10/Free Rhohtext.md aktualisiert
This commit is contained in:
@@ -872,66 +872,35 @@ Kopiere den folgenden Code vollständig in das Code-Feld:
|
|||||||
|
|
||||||
```
|
```
|
||||||
/**
|
/**
|
||||||
* INPUT: items[0].json ODER items[0].json.body (String) vom HTTP Request /helix/schedule
|
* INPUT: Array von Items aus "Parse ICS"
|
||||||
* OUTPUT: pro Segment ein Item in deinem Schema:
|
* OUTPUT: nur das nächste bevorstehende Event
|
||||||
* { uid, cancelled, title, description, startIso, endIso, tz, hash }
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const input = items[0]?.json ?? {};
|
const now = Date.now();
|
||||||
let payload;
|
|
||||||
|
|
||||||
if (typeof input.body === 'string') {
|
const upcoming = items
|
||||||
// HTTP-Node hat "Response Format: Text" -> JSON-String in body
|
.map(i => i.json)
|
||||||
try { payload = JSON.parse(input.body); }
|
.filter(e => !e.cancelled && new Date(e.startIso).getTime() > now)
|
||||||
catch (e) { throw new Error('HTTP body ist kein gültiges JSON'); }
|
.sort((a, b) => new Date(a.startIso) - new Date(b.startIso));
|
||||||
} else if (input.data) {
|
|
||||||
// HTTP-Node hat "Response Format: JSON"
|
if (upcoming.length === 0) {
|
||||||
payload = input;
|
return [{ json: { message: 'Kein bevorstehender Stream gefunden' } }];
|
||||||
} else if (typeof input === 'string') {
|
|
||||||
payload = JSON.parse(input);
|
|
||||||
} else {
|
|
||||||
throw new Error('Unerwartete Eingabeform. Erwartet JSON oder body-String.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const segments = Array.isArray(payload.data?.segments) ? payload.data.segments : [];
|
const next = upcoming[0];
|
||||||
|
|
||||||
// Hash wie in deinem ICS-Code
|
return [{
|
||||||
function hashHex(s) {
|
json: {
|
||||||
let h = 5381;
|
uid: next.uid,
|
||||||
for (let i = 0; i < s.length; i++) h = ((h << 5) + h) ^ s.charCodeAt(i);
|
title: next.title,
|
||||||
return (h >>> 0).toString(16).padStart(8, '0');
|
kategroie: next.kategorie,
|
||||||
}
|
description: next.description,
|
||||||
|
startIso: next.startIso,
|
||||||
function buildTitle() { return 'Streamtime'; }
|
endIso: next.endIso,
|
||||||
|
tz: next.tz,
|
||||||
function buildDesc(seg) {
|
hash: next.hash
|
||||||
const lines = [];
|
}
|
||||||
if (seg.title) lines.push(`Originaltitel: ${seg.title}`);
|
}];
|
||||||
if (seg.category?.name) lines.push(`Kategorie/Game: ${seg.category.name}`);
|
|
||||||
return lines.join('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
const tz = 'Europe/Berlin';
|
|
||||||
|
|
||||||
const out = segments.map(seg => {
|
|
||||||
const startIso = seg.start_time; // ISO-UTC laut Twitch
|
|
||||||
const endIso = seg.end_time;
|
|
||||||
const title = buildTitle();
|
|
||||||
const description = buildDesc(seg);
|
|
||||||
const hash = hashHex(`${title}|${startIso}|${endIso}|${description}`);
|
|
||||||
const kategorie = seg.category?.name;
|
|
||||||
return {
|
|
||||||
json: {
|
|
||||||
uid: seg.id,
|
|
||||||
cancelled: Boolean(seg.canceled_until),
|
|
||||||
title, description,
|
|
||||||
startIso, endIso, tz,
|
|
||||||
hash, kategorie
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return out;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
[!TIP]
|
[!TIP]
|
||||||
|
|||||||
Reference in New Issue
Block a user