{ "createdAt": "2025-02-13T05:09:56.575Z", "updatedAt": "2025-02-13T05:10:04.000Z", "id": "eRywiclDmLD3rzji", "name": "test_theguardian", "active": true, "nodes": [ { "parameters": { "method": "POST", "url": "http://172.31.0.160/v1/completion-messages", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "{\n \"Authorization\": \"Bearer app-KRXKS2lXohYjnIKmuYxSncem\",\n \"Content-Type\": \"application/json\"\n}", "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"').replaceAll(/\\\\n/g, '')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_theguardian\"\n}", "options": {} }, "id": "183ec461-7b39-48ef-a6bb-98de5fdfe11f", "name": "dify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 900, 260 ] }, { "parameters": { "mode": "runOnceForEachItem", "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ntitle = JSON.parse($input.item.json.body.info).title;\ncontent = JSON.parse($input.item.json.body.info).content;\ntext_info['title'] = title;\n//text_info['content'] = content;\noutput_info['text'] = JSON.stringify(text_info);\nreturn output_info;" }, "id": "bb8c4f66-723d-4b4e-9202-e1ffc934beb8", "name": "get_info", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 640, 260 ] }, { "parameters": { "mode": "runOnceForEachItem", "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n let missing = '';\n if (!str.endsWith('\"}')) {\n missing += '\"}'\n }\n str = str+missing;\n return str;\n}\nanswer = $input.item.json.answer;\nanswer = answer.replaceAll(/\\n/g, '').replaceAll(/%s| /g, '');\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;" }, "id": "28e1681a-c530-4c04-a07f-c76a09df7592", "name": "get_answer", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1180, 260 ] }, { "parameters": { "operation": "executeQuery", "query": "START TRANSACTION;\n\nINSERT INTO news_source (topic,content,source_url,news_uid,status,language,snapshot,news_web,news_type) VALUES {{ $json.news_data }};\n\nSET @last_insert_id = LAST_INSERT_ID();\n\nINSERT INTO news_url (url, type,news_id)\nVALUES {{ $json.urls_data }};\n\nCOMMIT;", "options": {} }, "id": "94ddd8f2-a743-4bd5-a650-8517bf3769cc", "name": "insert_city_news", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 1700, 260 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "parameters": { "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('answer' in item_data){\n content_all['answer'] = item_data['answer'];\n }\n}\n//console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\nanswer_data = content_all.answer;\ninfo_data_list['title'] = answer_data.title;\n//info_data_list['content'] = answer_data.content;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += '\"'+info_data_list.title+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.content+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.id+'\"';\nnews_item_data += ',';\nnews_item_data += '\"4\"';\nnews_item_data += ',';\nnews_item_data += '\"zh_cn\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.html_url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.news_web+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.type+'\"';\nnews_item_data += ')';\nimages_url = info_data_list.images_url;\nfor (let i = 0; i < images_url.length; i++) {\n image_url = images_url[i];\n image_item_data = \"(\";\n image_item_data += '\"'+image_url+'\"';\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n}\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','',''),\"\n}\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;" }, "id": "799360b0-2c9b-4c38-b14b-b0368add48e7", "name": "get_city_news_sql", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1440, 260 ] }, { "parameters": { "httpMethod": "POST", "path": "theguardian/translate/ch/test", "authentication": "headerAuth", "options": { "allowedOrigins": "*", "rawBody": false } }, "id": "5420669a-71e4-4386-8d42-2567613ea3b5", "name": "Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ 380, 260 ], "webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07", "credentials": { "httpHeaderAuth": { "id": "1fHtEpWRIg2mFYBe", "name": "Header Auth account" } } } ], "connections": { "dify": { "main": [ [ { "node": "get_answer", "type": "main", "index": 0 } ] ] }, "get_info": { "main": [ [ { "node": "dify", "type": "main", "index": 0 } ] ] }, "get_answer": { "main": [ [ { "node": "get_city_news_sql", "type": "main", "index": 0 } ] ] }, "get_city_news_sql": { "main": [ [ { "node": "insert_city_news", "type": "main", "index": 0 } ] ] }, "Webhook": { "main": [ [ { "node": "get_info", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "staticData": null, "meta": null, "pinData": null, "versionId": "a5e7ceea-f48f-4447-b656-c2fafd83f2e6", "triggerCount": 1, "shared": [ { "createdAt": "2025-02-13T05:09:56.588Z", "updatedAt": "2025-02-13T05:09:56.588Z", "role": "workflow:owner", "workflowId": "eRywiclDmLD3rzji", "projectId": "C7zKoCDdmGgzUqSW", "project": { "createdAt": "2024-08-23T06:31:21.275Z", "updatedAt": "2024-08-23T06:41:43.608Z", "id": "C7zKoCDdmGgzUqSW", "name": "周 卫 <zhouwei@ssish.com>", "type": "personal", "projectRelations": [ { "createdAt": "2024-08-23T06:31:21.275Z", "updatedAt": "2024-08-23T06:31:21.275Z", "role": "project:personalOwner", "userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882", "projectId": "C7zKoCDdmGgzUqSW", "user": { "createdAt": "2024-08-23T06:31:16.119Z", "updatedAt": "2025-03-19T06:19:26.514Z", "id": "3f0021b4-d0a7-4db6-af21-5ef829c47882", "email": "zhouwei@ssish.com", "firstName": "周", "lastName": "卫", "personalizationAnswers": { "companyType": "education", "role": "business-owner", "automationBeneficiary": "my-team", "companySize": "20-99", "reportedSource": "friend", "version": "v4", "personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z", "personalization_survey_n8n_version": "1.55.3" }, "settings": { "userActivated": true, "firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx", "userActivatedAt": 1725957335278, "npsSurvey": { "responded": true, "lastShownAt": 1742365155724 }, "isOnboarded": true }, "role": "global:owner", "disabled": false, "mfaEnabled": false, "isPending": false, "isOwner": true } } ] } } ], "tags": [] }