{ "createdAt": "2025-02-13T05:07:52.422Z", "updatedAt": "2025-02-13T05:08:14.000Z", "id": "gqBaONqx9nBdgSeV", "name": "test_qw", "active": true, "nodes": [ { "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 title_info = {};\nlet summary_info = {};\ntitle = JSON.parse($input.item.json.body.info).title;\nsummary = JSON.parse($input.item.json.body.info).summary;\n// content = JSON.parse($input.item.json.body.info).content;\ntitle_info['title'] = title;\nsummary_info['summary'] = summary;\n//text_info['content'] = content;\noutput_info['title_text'] = JSON.stringify(title_info);\noutput_info['summary_text'] = JSON.stringify(summary_info);\nreturn output_info;" }, "id": "6408b6a8-b646-4a3b-aa21-6c5336c6725a", "name": "get_info", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 0, 520 ] }, { "parameters": { "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};\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nresult_data = $input.all();\ncontent_all = {};\nanswer_data = {};\nanswer_data_list = {};\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 answer_data_str = item_data['answer'];\n answer_json_data = get_answer_data(answer_data_str);\n title = answer_json_data.title;\n summary = answer_json_data.summary;\n if(!isEmptyString(title)){\n answer_data_list['title'] = title;\n }else if(!isEmptyString(summary)){\n answer_data_list['summary'] = summary;\n }\n }\n};\nfunction get_answer_data(answer){\n answer = answer.replaceAll(/\\n/g, '').replaceAll(/%s| /g, '');\n indexes = findAllIndexes(answer,\"```\");\n answer_str = '';\n if(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n }else{\n answer_str = answer;\n }\n answer_str = answer_str.replace(/\\s+/g, '');\n answer_data_json = JSON.parse(autoCompleteJSON(answer_str));\n return answer_data_json;\n};\nanswer_data[\"answer\"] = answer_data_list;\nreturn answer_data;" }, "id": "ca7c4b97-d310-44c8-a480-7c2498c114ea", "name": "get_answer", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 720, 480 ] }, { "parameters": { "operation": "executeQuery", "query": "START TRANSACTION;\n\nINSERT INTO news_source (topic,summary,source_url,author,publish_time,news_uid,status,language,news_web,news_type) VALUES {{ $json.news_data }};\n\nSET @last_insert_id = LAST_INSERT_ID();\n\nINSERT INTO news_url (url,thumbnail_url, type,news_id)\nVALUES {{ $json.urls_data }};\n\nCOMMIT;", "options": {} }, "id": "06139d0f-346e-42b5-aff2-21c56c344323", "name": "insert_city_news", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 1120, 480 ], "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').all()[0].json.body.info);\n// console.log(info_data_list);\nanswer_data = content_all.answer;\ninfo_data_list['title'] = answer_data.title;\ninfo_data_list['summary'] = answer_data.summary;\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.summary+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.author+'\"';\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\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.news_web+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.type+'\"';\nnews_item_data += ')';\nimages_url = info_data_list.images_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\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 }\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": "d1aba33d-47ec-4d11-a896-c4fb71b26e56", "name": "get_city_news_sql", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 920, 480 ] }, { "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.title_text.replaceAll(/\"/g, '\\\\\"').replaceAll(/\\\\n/g, '')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_theguardian\"\n}", "options": {} }, "id": "a10d27b4-6191-4cef-a550-7d3cea3a8bf1", "name": "title_dify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 260, 340 ] }, { "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.summary_text.replaceAll(/\"/g, '\\\\\"').replaceAll(/\\\\n/g, '')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_theguardian\"\n}", "options": {} }, "id": "37632a75-881f-43e8-bc14-34fc969d6bbe", "name": "summary_dify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 260, 640 ] }, { "parameters": {}, "id": "951e72d9-cbc5-4b0f-8bb9-7a6c46fe918a", "name": "merge_label", "type": "n8n-nodes-base.merge", "typeVersion": 3, "position": [ 520, 480 ] }, { "parameters": { "httpMethod": "POST", "path": "qw/translate/ch/test", "authentication": "headerAuth", "options": { "allowedOrigins": "*", "rawBody": false } }, "id": "faa7cc54-d085-4cf8-b243-0612b78c5696", "name": "Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ -260, 520 ], "webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07", "credentials": { "httpHeaderAuth": { "id": "1fHtEpWRIg2mFYBe", "name": "Header Auth account" } } } ], "connections": { "get_info": { "main": [ [ { "node": "summary_dify", "type": "main", "index": 0 }, { "node": "title_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 } ] ] }, "title_dify": { "main": [ [ { "node": "merge_label", "type": "main", "index": 0 } ] ] }, "summary_dify": { "main": [ [ { "node": "merge_label", "type": "main", "index": 1 } ] ] }, "merge_label": { "main": [ [ { "node": "get_answer", "type": "main", "index": 0 } ] ] }, "Webhook": { "main": [ [ { "node": "get_info", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "staticData": null, "meta": null, "pinData": null, "versionId": "8b1e1970-d293-4d45-90eb-a543ead1374f", "triggerCount": 1, "shared": [ { "createdAt": "2025-02-13T05:07:52.431Z", "updatedAt": "2025-02-13T05:07:52.431Z", "role": "workflow:owner", "workflowId": "gqBaONqx9nBdgSeV", "projectId": "C7zKoCDdmGgzUqSW", "project": { "createdAt": "2024-08-23T06:31:21.275Z", "updatedAt": "2024-08-23T06:41:43.608Z", "id": "C7zKoCDdmGgzUqSW", "name": "周 卫 ", "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": [] }