{
  "name": "IDS AI - PDF Processor",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "ids-ai-upload",
        "responseMode": "responseNode",
        "options": {
          "allowedOrigins": "*",
          "rawBody": true
        }
      },
      "id": "webhook-trigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "// Extract data from request\nconst body = $input.first().json.body;\nconst filename = body.filename || 'document.pdf';\nconst content = body.content; // Base64 encoded PDF\nconst mimeType = body.mimeType || 'application/pdf';\n\n// Check filename for exercise patterns\nconst exercisePatterns = [\n  /exercise/i, /homework/i, /\\bhw\\d/i, /assignment/i,\n  /quiz/i, /exam/i, /test/i, /worksheet/i, /problem\\s*set/i\n];\n\nlet isExercise = false;\nlet reasons = [];\n\nfor (const pattern of exercisePatterns) {\n  if (pattern.test(filename)) {\n    isExercise = true;\n    reasons.push(`Filename matches pattern: ${pattern}`);\n    break;\n  }\n}\n\n// Generate document ID\nconst documentId = 'doc_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);\n\nreturn [{\n  json: {\n    documentId,\n    filename,\n    content,\n    mimeType,\n    isExercise,\n    reasons\n  }\n}];"
      },
      "id": "process-upload",
      "name": "Process Upload",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.isExercise }}",
              "value2": true
            }
          ]
        }
      },
      "id": "if-exercise",
      "name": "Is Exercise?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        660,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"success\": false,\n  \"isExercise\": true,\n  \"error\": \"This file appears to be an exercise or homework document.\",\n  \"reasons\": {{ JSON.stringify($json.reasons) }}\n}",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "reject-exercise",
      "name": "Reject Exercise",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        880,
        180
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"success\": true,\n  \"documentId\": \"{{ $json.documentId }}\",\n  \"filename\": \"{{ $json.filename }}\",\n  \"message\": \"Document processed successfully\"\n}",
        "options": {
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              }
            ]
          }
        }
      },
      "id": "success-response",
      "name": "Success Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        880,
        420
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Process Upload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Upload": {
      "main": [
        [
          {
            "node": "Is Exercise?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Exercise?": {
      "main": [
        [
          {
            "node": "Reject Exercise",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Success Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "IDS AI"
    }
  ],
  "triggerCount": 0,
  "updatedAt": "2024-12-17T00:00:00.000Z",
  "versionId": "1"
}