import SQL from 'sql'

function main() {
    // const SYSTEM_CONFIG = SQL.queryWithCache(
    //     "system_sql",
    //     86400, // 缓存时间，单位秒，0表示不缓存，-1表示永久缓存，默认缓存时间为1天
    //     "SELECT * FROM `sys_configs` WHERE `delete_time` IS NULL;",
    // );

    // const appid = SYSTEM_CONFIG.find(item => item.name === 'wechat_appid').value;
    // const secret = SYSTEM_CONFIG.find(item => item.name === 'wechat_appsecret').value;

    const req = {
        method:'POST',
        data: `{"email":"x@l-l.cn","password":"5614f928e0608895306b885c0b3444a9915b0fb0e3f0a474b0501cfd30bd9a7d"}`,
        url: `https://chat.qwen.ai/api/v1/auths/signin`
    }

    // console.log(request.toCURL(req))
    const res = request.parse(req).body.toObject()
    if (res.token) {
        SQL.push('system_sql', 'UPDATE sys_configs SET value =? WHERE name =?;', res.token, 'ai_qwen_token')
        console.mod('Event').fn('apps').proc('qwen').info(`[getAccessToken] - ${res.token}`)
        cache.set('oauth', 'ai_qwen_token', res.token, 7000 * 1000)
        return
    }
    console.mod('Event').fn('apps').proc('qwen').error(`[getAccessToken] - ${JSON.stringify(res)}`)
    return
}
