季兆星
季兆星
  • 发布:2023-08-14 13:54
  • 更新:2023-08-17 11:12
  • 阅读:257

【报Bug】数据加密传输 客户端请求云对象 设置secretMethods参数之后 导致databaseForJQL 数据库触发器 无法使用 这个怎么解决?

分类:uniCloud

产品分类: uniCloud/App

操作步骤:

数据加密传输 客户端请求云对象 设置secretMethods参数之后
云端使用databaseForJQL 报SYSTEM_ERROR:Method name required

"error": {
"errMsg": "[im-chat-service]: SYSTEM_ERROR:Method name required",
"errCode": "FunctionBizError",
"code": "FunctionBizError",
"detail": {
"errMsg": "[im-chat-service]: SYSTEM_ERROR:Method name required",
"errCode": "FunctionBizError",
"code": "FunctionBizError",
"requestId": "ac1cc3051691991683092128553"
}
}

设置skipTrigger: true,后可以正常
let dbJQL = uniCloud.databaseForJQL({
skipTrigger: true,
clientInfo: this.getClientInfo()
})

预期结果:

正常获取结果

实际结果:

"error": {
"errMsg": "[im-chat-service]: SYSTEM_ERROR:Method name required",
"errCode": "FunctionBizError",
"code": "FunctionBizError",
"detail": {
"errMsg": "[im-chat-service]: SYSTEM_ERROR:Method name required",
"errCode": "FunctionBizError",
"code": "FunctionBizError",
"requestId": "ac1cc3051691991683092128553"
}
}

bug描述:

数据加密传输 客户端请求云对象 设置secretMethods参数之后 导致数据库触发器 无法使用 这个怎么解决?

2023-08-14 13:54 负责人:无 分享
已邀请:

最佳回复

DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

bug已确认,感谢反馈,稍后修复后会在这里通知

  • DCloud_uniCloud_WYQ

    此问题已修复,你可以重新上传一下你这个云对象试试

    2023-08-17 12:01

DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

贴一下云对象的日志

  • 季兆星 (作者)

    [im-chat-service/ac1cd3721691977407569128458/526ms/ERROR] Method name required

    Error: Method name required

    at /tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:4110

    at G (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:4213)

    at Qs.gr [as getClientInfos] (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:51092)

    at a (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:256280)

    at /tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:257321

    at c (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:257358)

    at execAfterTrigger (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:257977)

    at exec (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:255850)

    at <anonymous>

    at process._tickCallback (internal/process/next_tick.js:189:7)

    [im-chat-service/ac1cd3721691977407569128458/528ms/ERROR] Method name required

    Error: Method name required

    at _callCloudFunction (/tmp/function/@common_modules/uni-cloud-jql/index.js:1:6206)

    at <anonymous>

    at process._tickCallback (internal/process/next_tick.js:189:7)

    请求响应状态: fail

    2023-08-15 20:18

季兆星

季兆星 (作者) - 念念堂

[im-chat-service/ac1cd3721691977407569128458/526ms/ERROR] Method name required
Error: Method name required
at /tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:4110
at G (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:4213)
at Qs.gr [as getClientInfos] (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:51092)
at a (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:256280)
at /tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:257321
at c (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:257358)
at execAfterTrigger (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:257977)
at exec (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:255850)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
[im-chat-service/ac1cd3721691977407569128458/528ms/ERROR] Method name required
Error: Method name required
at _callCloudFunction (/tmp/function/@common_modules/uni-cloud-jql/index.js:1:6206)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
请求响应状态: fail

  • DCloud_uniCloud_WYQ

    触发器的after里面怎么写的代码

    2023-08-16 16:52

  • 季兆星 (作者)

    回复 DCloud_uniCloud_WYQ: async function afterReadAction({

    field,

    result,

    userInfo: currentUserInfo,

    primaryCollection

    } = {}, asSecondaryCollection = false) {

    if (result && field && field.includes('nickname')) {

    //uni-im 处理查询nickname,但值为空的情况

    console.log('afterReakUser------1')

    let { data } = result


        console.log('afterReakUser------2', data)  
    if (!Array.isArray(data)) {
    // 说明走了 getOne
    data = [data]
    }
    console.log('afterReakUser------3', data)
    // 为联查 且为副表时的字段
    if (asSecondaryCollection && typeof(data[0]) === 'object') {
    let foreignKeysObj = {
    'uni-im-group-member': 'user_id',
    'uni-im-friend': 'friend_uid'
    }
    let foreignKey = foreignKeysObj[primaryCollection]

    if (foreignKey in data[0]) {
    data = data.map(item => item[foreignKey][0])
    } else {
    return console.log(
    '触发器uni-id-users.schema.ext.js,未在当前操作生效。如需应用此触发器,请补充:主表表名及其foreignKey的值,到触发器uni-id-users.schema.ext.js的变量foreignKeysObj内'
    )
    }
    }

    // console.log('data',data);
    if (!Array.isArray(data)) {
    data = [data]
    }
    // 记录没有nickname的用户id
    let user_ids = [],
    usersInfo = {}
    data.forEach(item => {
    if (item && !item.nickname) {
    user_ids.push(item._id)
    }
    })
    if (user_ids.length) {
    console.info('注意:uni-im项目用户数据依赖nickname。有' + user_ids.length +
    '个用户数据 nickname 的值为空,已多执行一次数据库查询:将此用户的“用户名”或“邮箱”或“手机号”脱敏后,作为nickname输出。请引导用户完善nickname,减少查库次数')
    let res = await db.collection('uni-id-users')
    .where({ _id: dbCmd.in(user_ids) })
    .field({
    username: true,
    email: true,
    mobile: true
    })
    .limit(1000)
    .get()
    usersInfo = res.data.reduce((sum, current) => {
    sum[current._id] = current
    return sum
    }, {})
    }

    let isUniImAdmin = currentUserInfo.role.includes('uni-im-admin') || currentUserInfo.role.includes('admin')

    data.forEach(item => {
    console.log('读取用户>>>>>', item)
    if (!item.nickname) {
    let userInfo = usersInfo[item._id]
    // 管理员可以看到不打码的
    if (isUniImAdmin) {
    item.nickname = userInfo.username || userInfo.email || userInfo.mobile
    } else {
    item.nickname = hideUsernameStr(userInfo.username) || hideEmailStr(userInfo.email) ||
    hideMobileStr(userInfo.mobile)
    }
    } else if (!isUniImAdmin && item.nickname.includes('@')) {
    // 禁止昵称用邮箱 脱敏处理
    item.nickname = hideEmailStr(item.nickname)
    }

    // 特殊处理某个用户xxx
    if (item._id == 'xxx') {
    item.nickname = 'xxx'
    item.avatar_file = { url: 'xxx' }
    }

    })

    function hideUsernameStr(username) {
    if (username == undefined) {
    return false
    }
    let length = username.length
    let n = parseInt(length / 2.5) * 2
    return username.substr(0, length - n) + '**' + username.substr(-1 * n / 2)
    }

    function hideEmailStr(email) {
    if (email == undefined) {
    return false
    }
    const content = email.split('@')
    return content[0].substr(0, content[0].length - 2) + '**' + content[1]
    }

    function hideMobileStr(mobile) {
    if (mobile == undefined) {
    return false
    }
    return mobile.substr(0, 3) + '****' + mobile.substr(-1 * 4)
    }
    }

    }

    2023-08-16 17:06

  • 季兆星 (作者)

    回复 DCloud_uniCloud_WYQ: uni-id-users 表 如果开启数据加密 读取uni-id-users数据 就会报这个错,不开启数据加密 就正常,只要写了 beforeRead 或者 afterRead 就会报错


    module.exports = {

    trigger: {

    // 注册数据表的read前事件

    beforeRead: async function (

    // 确定要监听的什么样的JQL指令

    {

    collection,

    operation,

    where,

    field

    } = {}) {

    // 当上述jql指令被触发时,将执行这里的代码。这里就是普通的uniCloud代码,可以调用uniCloud的各种api。

    console.log("这个触发器被触发了")

    },

    afterRead: async function ({

    collection,

    operation,

    where,

    field

    } = {}) {


    }  

    }

    }


    写个这个 空函数 也会报错


    报错内容 是一样的


    Method name required

    Error: Method name required

    at /tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:4110

    at G (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:4213)

    at Qs.gr [as getClientInfos] (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:51092)

    at a (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:256280)

    at /tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:257321

    at c (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:257358)

    at execAfterTrigger (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:257977)

    at exec (/tmp/function/@common_modules/uni-cloud-jql/uni-curd/index.js:1:255850)

    at

    at process._tickCallback (internal/process/next_tick.js:189:7)

    [im-chat-service/ac1cd3721691977407569128458/528ms/ERROR] Method name required

    Error: Method name required

    at _callCloudFunction (/tmp/function/@common_modules/uni-cloud-jql/index.js:1:6206)

    at

    at process._tickCallback (internal/process/next_tick.js:189:7)

    2023-08-16 20:14

要回复问题请先登录注册