Have ideas to improve npm?Join in the discussion! »

    @cloudbase/extension-ci
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.3 • Public • Published

    数据万象Cloud Infinite(扩展)

    Usage

    const extCi = require('@cloudbase/extension-ci')
    
    tcb.init({
        env:'xxx',
    });
    
    tcb.registerExtension(extCi)
    
    const res = await tcb.invokeExtension('CloudInfinite',opts)

    opts包含以下属性

    名称 类型 是否必须 说明
    action string 操作类型
    cloudPath string 文件的绝对路径,与tcb.uploadFile中一致,除盲水印功能外,其它功能必须存在此路径的文件
    fileContent Uint8Array|Buffer|ArrayBuffer 文件内容, 盲水印选传
    operations object 数据万象的headers中的Pic-Operations字段,图像处理或者盲水印功能时需要填入的参数

    action目前包含以下类型

    • DetectLabel
    • DetectType
    • WaterMark
    • ImageProcess

    fileContent在云函数和前端的获取方式参考

    // 云函数中
    const fileContent = fs.readFileSync('C:\\Users\\user\\Desktop\\bb.png'),
    
    // 网页中
    const readFile = async function(file) {
        let reader = new FileReader();
        let res = await new Promise(resolve=>{
            reader.onload = function(e) {
                let arrayBuffer = new Uint8Array((e.target as any).result);
                resolve(arrayBuffer)
            }
            reader.readAsArrayBuffer(file);
        })
        return res
    }
    let file = document.getElementById('selectFile').files[0]
    let fileContent = await readFile(file)

    功能说明

    图像处理

    参考文档万象文档 云上数据处理

    const ops = {
        rules:[{
            rule:'QRcode/cover/0'
        }]
    }
    
    const res = await tcb.invokeExtension('CloudInfinite',{
        cloudPath: "bb.png",
        action:'ImageProcess',
        operations:ops
    })
    
    console.log(JSON.stringify(res,null,4))
    }

    盲水印

    参考文档万象文档 盲水印功能

    const ops = {
        rules:[{
            fileid:'qr6.jpg'
            rule:{
                mode:3,
                type:3,
                text:'1234'
            }
        }]
    }
    
    const res = await tcb.invokeExtension('CloudInfinite',{
        action:'WaterMark',
        cloudPath: "qr5.jpg",
        fileContent: fs.readFileSync('C:\\Users\\xxx\\Desktop\\bb.png'),
        operations:ops
    })

    图片标签

    参考文档万象文档 图片标签

    const res = await tcb.invokeExtension('CloudInfinite',{
        action:'DetectLabel',
        cloudPath: "ab.png"
    })
    
    console.log(JSON.stringify(res,null,4))

    安全审核

    参考文档万象文档 内容识别

    const opts = {
        type: "porn" // 审核类型:porn(涉黄识别)、terrorist(涉暴恐识别)、politics(涉政识别)、ads(广告识别),可选择多种识别类型,如porn,ads
    }
    const res = await tcb.invokeExtension('CloudInfinite',{
        action:'DetectType',
        operations:opts,
        cloudPath: "ab.png"
    })
    
    console.log(JSON.stringify(res,null,4))

    Keywords

    none

    Install

    npm i @cloudbase/extension-ci

    DownloadsWeekly Downloads

    16

    Version

    0.2.3

    License

    ISC

    Unpacked Size

    29.4 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar