Kapitel 10/Stream Reminder Post.json aktualisiert
This commit is contained in:
@@ -217,7 +217,7 @@
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "/**\n * INPUT: items[0].json ODER items[0].json.body (String) vom HTTP Request /helix/schedule\n * OUTPUT: pro Segment ein Item in deinem Schema:\n * { uid, cancelled, title, description, startIso, endIso, tz, hash }\n */\n\nconst input = items[0]?.json ?? {};\nlet payload;\n\nif (typeof input.body === 'string') {\n // HTTP-Node hat \"Response Format: Text\" -> JSON-String in body\n try { payload = JSON.parse(input.body); }\n catch (e) { throw new Error('HTTP body ist kein gültiges JSON'); }\n} else if (input.data) {\n // HTTP-Node hat \"Response Format: JSON\"\n payload = input;\n} else if (typeof input === 'string') {\n payload = JSON.parse(input);\n} else {\n throw new Error('Unerwartete Eingabeform. Erwartet JSON oder body-String.');\n}\n\nconst segments = Array.isArray(payload.data?.segments) ? payload.data.segments : [];\n\n// Hash wie in deinem ICS-Code\nfunction hashHex(s) {\n let h = 5381;\n for (let i = 0; i < s.length; i++) h = ((h << 5) + h) ^ s.charCodeAt(i);\n return (h >>> 0).toString(16).padStart(8, '0');\n}\n\nfunction buildTitle() { return 'Streamtime'; }\n\nfunction buildDesc(seg) {\n const lines = [];\n if (seg.title) lines.push(`Originaltitel: ${seg.title}`);\n if (seg.category?.name) lines.push(`Kategorie/Game: ${seg.category.name}`);\n return lines.join('\\n');\n}\n\nconst tz = 'Europe/Berlin';\n\nconst out = segments.map(seg => {\n const startIso = seg.start_time; // ISO-UTC laut Twitch\n const endIso = seg.end_time;\n const title = buildTitle();\n const description = buildDesc(seg);\n const hash = hashHex(`${title}|${startIso}|${endIso}|${description}`);\n\n return {\n json: {\n uid: seg.id,\n cancelled: Boolean(seg.canceled_until),\n title, description,\n startIso, endIso, tz,\n hash\n }\n };\n});\n\nreturn out;\n"
|
||||
"jsCode": "/**\n * INPUT: items[0].json ODER items[0].json.body (String) vom HTTP Request /helix/schedule\n * OUTPUT: pro Segment ein Item in deinem Schema:\n * { uid, cancelled, title, description, startIso, endIso, tz, hash }\n */\n\nconst input = items[0]?.json ?? {};\nlet payload;\n\nif (typeof input.body === 'string') {\n // HTTP-Node hat \"Response Format: Text\" -> JSON-String in body\n try { payload = JSON.parse(input.body); }\n catch (e) { throw new Error('HTTP body ist kein gültiges JSON'); }\n} else if (input.data) {\n // HTTP-Node hat \"Response Format: JSON\"\n payload = input;\n} else if (typeof input === 'string') {\n payload = JSON.parse(input);\n} else {\n throw new Error('Unerwartete Eingabeform. Erwartet JSON oder body-String.');\n}\n\nconst segments = Array.isArray(payload.data?.segments) ? payload.data.segments : [];\n\n// Hash wie in deinem ICS-Code\nfunction hashHex(s) {\n let h = 5381;\n for (let i = 0; i < s.length; i++) h = ((h << 5) + h) ^ s.charCodeAt(i);\n return (h >>> 0).toString(16).padStart(8, '0');\n}\n\nfunction buildTitle() { return 'Streamtime'; }\n\nfunction buildDesc(seg) {\n const lines = [];\n if (seg.title) lines.push(`Originaltitel: ${seg.title}`);\n if (seg.category?.name) lines.push(`Kategorie/Game: ${seg.category.name}`);\n return lines.join('\\n');\n}\n\nconst tz = 'Europe/Berlin';\n\nconst out = segments.map(seg => {\n const startIso = seg.start_time; // ISO-UTC laut Twitch\n const endIso = seg.end_time;\n const title = buildTitle();\n const description = buildDesc(seg);\n const hash = hashHex(`${title}|${startIso}|${endIso}|${description}`);\n const kategorie = seg.category?.name;\n return {\n json: {\n uid: seg.id,\n cancelled: Boolean(seg.canceled_until),\n title, description,\n startIso, endIso, tz,\n hash, kategorie \n }\n };\n});\n\nreturn out;\n"
|
||||
},
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
@@ -231,7 +231,7 @@
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "/**\n * INPUT: Array von Items aus \"Parse ICS\"\n * OUTPUT: nur das nächste bevorstehende Event\n */\n\nconst now = Date.now();\n\nconst upcoming = items\n .map(i => i.json)\n .filter(e => !e.cancelled && new Date(e.startIso).getTime() > now)\n .sort((a, b) => new Date(a.startIso) - new Date(b.startIso));\n\nif (upcoming.length === 0) {\n return [{ json: { message: 'Kein bevorstehender Stream gefunden' } }];\n}\n\nconst next = upcoming[0];\n\nreturn [{\n json: {\n uid: next.uid,\n title: next.title,\n description: next.description,\n startIso: next.startIso,\n endIso: next.endIso,\n tz: next.tz,\n hash: next.hash\n }\n}];"
|
||||
"jsCode": "/**\n * INPUT: Array von Items aus \"Parse ICS\"\n * OUTPUT: nur das nächste bevorstehende Event\n */\n\nconst now = Date.now();\n\nconst upcoming = items\n .map(i => i.json)\n .filter(e => !e.cancelled && new Date(e.startIso).getTime() > now)\n .sort((a, b) => new Date(a.startIso) - new Date(b.startIso));\n\nif (upcoming.length === 0) {\n return [{ json: { message: 'Kein bevorstehender Stream gefunden' } }];\n}\n\nconst next = upcoming[0];\n\nreturn [{\n json: {\n uid: next.uid,\n title: next.title,\n kategroie: next.kategorie,\n description: next.description,\n startIso: next.startIso,\n endIso: next.endIso,\n tz: next.tz,\n hash: next.hash\n }\n}];"
|
||||
},
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
@@ -297,8 +297,8 @@
|
||||
"type": "n8n-nodes-base.nextCloud",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
2816,
|
||||
160
|
||||
3296,
|
||||
96
|
||||
],
|
||||
"id": "b3694213-54fb-4987-98b3-156b7d49119d",
|
||||
"name": "Download a file",
|
||||
@@ -316,8 +316,8 @@
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
"position": [
|
||||
3024,
|
||||
160
|
||||
3440,
|
||||
96
|
||||
],
|
||||
"id": "10583c07-00f8-4b74-9397-a0fb8804ddb4",
|
||||
"name": "Posttext auswählen"
|
||||
@@ -330,8 +330,8 @@
|
||||
"type": "n8n-nodes-base.twitter",
|
||||
"typeVersion": 2,
|
||||
"position": [
|
||||
3280,
|
||||
160
|
||||
3824,
|
||||
240
|
||||
],
|
||||
"id": "14f6ea83-a1fc-4d9c-a8e4-49fea946ab8b",
|
||||
"name": "X – Post veröffentlichen",
|
||||
@@ -340,7 +340,8 @@
|
||||
"id": "FBWhPuyEfuMJFdKU",
|
||||
"name": "X account"
|
||||
}
|
||||
}
|
||||
},
|
||||
"disabled": true
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
@@ -349,8 +350,8 @@
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
"position": [
|
||||
3488,
|
||||
160
|
||||
4000,
|
||||
240
|
||||
],
|
||||
"id": "8dd18b30-a935-4bd3-8d6c-8abd11890de4",
|
||||
"name": "Code"
|
||||
@@ -535,10 +536,9 @@
|
||||
"settings": {
|
||||
"executionOrder": "v1",
|
||||
"timezone": "Europe/Berlin",
|
||||
"callerPolicy": "workflowsFromSameOwner",
|
||||
"executionTimeout": -1
|
||||
"callerPolicy": "workflowsFromSameOwner"
|
||||
},
|
||||
"versionId": "a4085334-5196-4a2b-894e-103860945307",
|
||||
"versionId": "fb5ad769-df0b-4258-8d3e-80b8b9899ef2",
|
||||
"meta": {
|
||||
"templateCredsSetupCompleted": true,
|
||||
"instanceId": "4edc03810a5a67ca6728ea68a9aec5a82547f97ec5ae65df9f22d521c302e706"
|
||||
|
||||
Reference in New Issue
Block a user