{
  "name": "Gartentop.de – Manual Test Publisher (1 Artikel mit Bild)",
  "nodes": [
    {
      "parameters": {},
      "id": "1",
      "name": "Start (Manuell)",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -900,
        -60
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\n  \"model\": \"gpt-4o-mini\",\n  \"messages\": [\n    {\"role\":\"system\",\"content\":\"Du bist ein deutscher SEO-Redakteur für Gartenthemen. Antworte nur mit JSON.\"},\n    {\"role\":\"user\",\"content\":\"Erstelle ein einzelnes zufälliges deutsches Gartenthema als JSON-Objekt: {\\\"topic\\\":\\\"Thema\\\",\\\"category_hint\\\":\\\"Pflanzen|Gartengeraete|Gartenmoebel|Bewaesserung|Gartengestaltung|Pflege & Tipps|Nachhaltig Gaertnern\\\"}. Keine Erklärungen, nur JSON.\"}\n  ]\n}"
      },
      "id": "2",
      "name": "HTTP – Thema generieren (OpenAI)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        -650,
        -60
      ],
      "credentials": {
        "httpBasicAuth": {
          "id": "",
          "name": "OpenAI API"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const raw = items[0].json.choices?.[0]?.message?.content || items[0].json.choices?.[0]?.message?.content || JSON.stringify(items[0].json);\nlet obj;\ntry { obj = JSON.parse(raw); } catch(e) { throw new Error('Konnte Thema nicht als JSON parsen: ' + raw); }\nreturn [{ json: obj }];"
      },
      "id": "3",
      "name": "Code – Thema parsen",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        -420,
        -60
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "authentication": "predefinedCredentialType",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\n  \"model\": \"gpt-4o\",\n  \"messages\": [\n    {\"role\":\"system\",\"content\":\"Du bist ein erfahrener deutscher SEO-Autor, schreibst emotional-informativ und suchmaschinenoptimiert. Antworte **ausschließlich** mit einem JSON-Objekt (kein Fließtext).\"},\n    {\"role\":\"user\",\"content\":\"Schreibe einen ausführlichen deutschen SEO-Artikel (~2000 Wörter) zum Thema: {{$json.topic}}. Antworte nur mit folgendem JSON-Objekt:\\n{\\n  \\\"title\\\": \\\"...\\\",\\n  \\\"slug\\\": \\\"...\\\",\\n  \\\"summary\\\": \\\"...\\\",\\n  \\\"keywords\\\": \\\"...\\\",\\n  \\\"content\\\": \\\"<h1>...</h1>... (HTML mit H1/H2/H3, Absätzen, Listen)\\\",\\n  \\\"image_prompt\\\": \\\"kurze Bildbeschreibung auf Deutsch\\\",\\n  \\\"category_hint\\\": \\\"...\\\"\\n}\\nVorgaben: Länge ~2000 Wörter; nutze deutsche Umlaute im Text, im Slug keine Umlaute (ae/oe/ue, ss). Keine externen Links in content.\"}\n  ]\n}"
      },
      "id": "4",
      "name": "HTTP – Artikel schreiben (OpenAI)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        -120,
        -60
      ],
      "credentials": {
        "httpBasicAuth": {
          "id": "",
          "name": "OpenAI API"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const raw = items[0].json.choices?.[0]?.message?.content || JSON.stringify(items[0].json);\nlet a;\ntry { a = JSON.parse(raw); } catch(e) { throw new Error('Kein gültiges JSON vom Artikel-Node: ' + raw); }\nreturn [{ json: a }];"
      },
      "id": "5",
      "name": "Code – Artikel parsen",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        150,
        -60
      ]
    },
    {
      "parameters": {
        "functionCode": "const hint = (items[0].json.category_hint || '').toLowerCase();\nconst map = {\n  'pflanzen': 1,\n  'gartengeraete': 2,\n  'gartenmoebel': 3,\n  'bewaesserung': 4,\n  'gartengestaltung': 5,\n  'pflege & tipps': 6,\n  'pflege & tipps': 6,\n  'nachhaltig gaertnern': 7,\n  'nachhaltig gärtnern': 7\n};\nconst key = hint.replace(/ä/g,'ae').replace(/ö/g,'oe').replace(/ü/g,'ue');\nitems[0].json.category_id = map[key] || 6;\nreturn items;"
      },
      "id": "6",
      "name": "Code – Kategorie Mapping",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        380,
        -60
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/images/generations",
        "authentication": "predefinedCredentialType",
        "jsonParameters": true,
        "bodyParametersJson": "{\n  \"model\": \"gpt-image-1\",\n  \"prompt\": \"{{$json.image_prompt}}\",\n  \"size\": \"1024x1024\",\n  \"response_format\": \"b64_json\"\n}"
      },
      "id": "7",
      "name": "HTTP – Bild generieren (OpenAI Images)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        640,
        -60
      ],
      "credentials": {
        "httpBasicAuth": {
          "id": "",
          "name": "OpenAI API"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "const b64 = items[0].json.data?.[0]?.b64_json || items[0].json.b64_json;\nif(!b64) throw new Error('Kein base64-Bild erhalten');\nconst buffer = Buffer.from(b64, 'base64');\nconst ym = new Date().toISOString().slice(0,7).replace('-','');\nconst fn = `image_870x_${Math.random().toString(16).slice(2,10)}.jpg`;\nreturn [{ json: { filename: fn, yearMonth: ym, image_prompt: items[0].json.prompt || $json?.image_prompt || '' }, binary: { data: { data: buffer, mimeType: 'image/jpeg' } } }];"
      },
      "id": "8",
      "name": "Code – Base64 → JPG",
      "type": "n8n-nodes-base.function",
      "typeVersion": 2,
      "position": [
        900,
        -60
      ]
    },
    {
      "parameters": {
        "protocol": "ftp",
        "path": "/home/gmomonet/public_html/gartentop.de/uploads/images/={{$json.yearMonth}}/",
        "fileName": "={{$json.filename}}",
        "binaryPropertyName": "data",
        "operation": "upload"
      },
      "id": "9",
      "name": "FTP – Bild hochladen",
      "type": "n8n-nodes-base.ftp",
      "typeVersion": 1,
      "position": [
        1160,
        -60
      ],
      "credentials": {
        "ftp": {
          "id": "",
          "name": "FTP Gartentop"
        }
      }
    },
    {
      "parameters": {
        "url": "https://gartentop.de/api/add_article.php",
        "method": "POST",
        "responseFormat": "json",
        "jsonParameters": true,
        "bodyParametersJson": "{\n  \"lang_id\": 1,\n  \"title\": \"{{$json.title}}\",\n  \"slug\": \"{{$json.slug}}\",\n  \"keywords\": \"{{$json.keywords}}\",\n  \"summary\": \"{{$json.summary}}\",\n  \"content\": \"{{$json.content}}\",\n  \"category_id\": {{$json.category_id}},\n  \"post_type\": \"article\",\n  \"video_embed_code\": \"\",\n  \"status\": 1,\n  \"image_url\": \"https://gartentop.de/uploads/images/\" + $json.yearMonth + \"/\" + $json.filename,\n  \"image_description\": \"{{$json.image_prompt}}\"\n}"
      },
      "id": "10",
      "name": "HTTP – Artikel veröffentlichen",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1420,
        -60
      ]
    }
  ],
  "connections": {
    "Start (Manuell)": {
      "main": [
        [
          {
            "node": "HTTP – Thema generieren (OpenAI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP – Thema generieren (OpenAI)": {
      "main": [
        [
          {
            "node": "Code – Thema parsen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code – Thema parsen": {
      "main": [
        [
          {
            "node": "HTTP – Artikel schreiben (OpenAI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP – Artikel schreiben (OpenAI)": {
      "main": [
        [
          {
            "node": "Code – Artikel parsen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code – Artikel parsen": {
      "main": [
        [
          {
            "node": "Code – Kategorie Mapping",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code – Kategorie Mapping": {
      "main": [
        [
          {
            "node": "HTTP – Bild generieren (OpenAI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP – Bild generieren (OpenAI)": {
      "main": [
        [
          {
            "node": "Code – Base64 → JPG",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code – Base64 → JPG": {
      "main": [
        [
          {
            "node": "FTP – Bild hochladen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FTP – Bild hochladen": {
      "main": [
        [
          {
            "node": "HTTP – Artikel veröffentlichen",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  }
}
