const fetch = require('node-fetch'); // Node.js 18以下版本需要安装 node-fetch
const redis_help = require('../../use_redis');
const CMD = {}
CMD.update_cookies = async function () {
    await require('./getActiveInfo').getActiveInfo()
    // try{
    //     let OPENSESSID = await redis_help.getKeyValue("OPENSESSID")
    //     let response =  await fetch("https://open.yuewen.com/api/Announce/AnnounceList?type=0&p=1&coop=0", {
    //         "headers": {
    //           "accept": "application/json, text/plain, */*",
    //           "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    //           "priority": "u=1, i",
    //           "sec-ch-ua": "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
    //           "sec-ch-ua-mobile": "?0",
    //           "sec-ch-ua-platform": "\"Windows\"",
    //           "sec-fetch-dest": "empty",
    //           "sec-fetch-mode": "cors",
    //           "sec-fetch-site": "same-origin",
    //           "cookie": `Hm_lvt_990f9ab9737a266517417cc2949bb3f4=1736394515; csrfToken=vEQbWeNTNVpt2aruM6_NwIpT; OPENSESSID=${OPENSESSID}; yw_open_token=6784e90e5a6fe; is_read_notice=6784e90e5a6fe; sidebarStatus=0`,
    //           "Referer": "https://open.yuewen.com/new/dashboard",
    //           "Referrer-Policy": "strict-origin-when-cross-origin"
    //         },
    //         "body": null,
    //         "method": "GET"
    //     });

    //     // console.log('-'.repeat(50));
    //     // response.headers.forEach((value, key) => {
    //     //     console.log(`${key}: ${value}`);
    //     // });
    //     let cookie = response.headers.get('set-cookie')
    //     // console.log("cookie:",cookie)
    //     const match = cookie.match(/OPENSESSID=([^;]+)/);
    //     if (match && match[1]) {
    //         OPENSESSID = match[1]
    //         console.log('OPENSESSID值:', match[1]);
    //         redis_help.setKeyValue("OPENSESSID",OPENSESSID)
    //     }
    //     const data = await response.json();
    //     // if(data.code!=0){
    //     //     throw data
    //     // }
    //     console.log('响应状态:', response.status);
    //     console.log('响应数据:', data);
    // }catch(e){

    // }
}

module.exports = CMD;
