123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- const CMD = {}
- const PROT = 9111
- var http = require('http');
- const redis_help = require('../src/use_redis');
- const video_applet_product_controllers = require('../src/data_manager/Controllers/video_applet_product_controllers');
- CMD.init = function(){
- redis_help.connect(()=>{
- })
- }
- CMD.start_task = async function(msgBody){
- let PlatformConfig = JSON.parse(await redis_help.getKeyValue("PlatformConfig"))
- let main_info = msgBody.main_info
- let list = msgBody.list
- let PlatformInfo = null
- if(main_info.running_status==0){
- console.log("创建了一个关闭的主体:",main_info)
- return
- }
- console.log("main_info:",main_info)
- console.log("list:",list)
- for (let index = 0; index < PlatformConfig.length; index++) {
- const element = PlatformConfig[index];
- if(element.tg_platform_id == main_info.tg_platform_id){
- PlatformInfo = element
- break
- }
- }
- if(PlatformInfo==null){
- console.log("平台配置错误:",msgBody)
- }else{
- redis_help.setKeyValue("isPauseTask","true")
- console.log("list::",list)
- for (let index = 0; index < list.length; index++) {
- const element = list[index];
- let n_data = {book_id:element.product_id,
- book_name:element.product_name,
- tg_platform_id:element.book_platform,
- app_id:element.dy_small_applet_app_id,
- main_id:main_info.id
- }
- const result = await video_applet_product_controllers.createAppletProductData({
- book_platform:n_data.tg_platform_id,
- product_name:n_data.book_name,
- product_id:n_data.book_id,
- dy_small_applet_app_id:n_data.app_id,
- status:0,
- main_id:n_data.main_id,
- promotion_id:'',
- dy_small_program_start:'',
- dy_small_program_start_data:'',
- wait_status:0,
- })
- }
- redis_help.setKeyValue("isPauseTask","false")
- }
- }
- var server = http.createServer(function(req,res){
- res.setHeader('Access-Control-Allow-Origin', '*'); // 允许所有域的请求,注意:在生产环境中应该限制为特定的域
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); // 允许的方法
- res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization'); // 允许的头部
-
- let body = '';
- // 监听数据块
- req.on('data', chunk => {
- body += chunk.toString(); // 将接收到的数据块转换为字符串并拼接
- });
- // 监听请求结束
- req.on('end', async () => {
-
- if (req.method === 'POST') {
- if (req.headers['content-type'] === 'application/json') {
- try {
- // 解析 JSON 数据
- const jsonData = JSON.parse(body);
- console.log("recv msg:",jsonData)
- if(jsonData['fun']=="addMain"&&jsonData['cmd']=="filter_task"){
- CMD.start_task(jsonData['data']['data'])
- res.writeHead(200, {'Content-Type': 'application/json'});
- res.end(JSON.stringify({ msg: 'success!',code:10000,data:{}}));
- }else{
- res.writeHead(200, {'Content-Type': 'application/json'});
- res.end(JSON.stringify({ message: 'fun 错误',code:100}));
- }
- } catch (error) {
- // 处理解析错误
- console.error('Error parsing JSON:', error);
- res.writeHead(200, {'Content-Type': 'application/json'});
- res.end(JSON.stringify({ error: 'Invalid JSON' }));
- }
- } else {
- // 如果不是 JSON 内容类型,返回错误
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.end('Unsupported Media Type. Please send data as JSON.');
- }
- }else{
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.end(' Please Use Post.');
- }
-
- });
- })
- server.listen(PROT,()=>{
- });
- CMD.init()
|