suanpan_node_sdk_test
v1.2.3
Published
suanpan sdk for node.js
Downloads
4
Readme
简介
目前 node.js sdk
- 支持消息收发
- 读取组件的右面板参数
- 支持 oss 类型的 storage 功能[beta]
安装 sdk
npm install suanpan_node_sdk
Docker
可以使用基础镜像 node_sdk_base:latest latest可替换为指定的SDK版本号 例如
ARG ARCH="amd64"
FROM registry.cn-shanghai.aliyuncs.com/shuzhi-$ARCH/node_sdk_base:latest
基础镜像中 suanpan_node_sdk 通过全局安装
本地开发可以通过npm install -D suanpan_node_sdk
来提供代码提示
API 列表
加载 sdk
let sp = require('suanpan_node_sdk').sp
获得右面板配置参数(parameter)
let spParameter = sp.parameter
console.log(spParameter)
发送消息与接受消息
构建发送包
let msgPackOut={
out1:"a", //将发送 "a" 到第一个消息出口
out2:"b", //将发送 "b" 到第二个消息出口
// key(outN) 表示第N个消息出口, value必须是字符串
}
监听 call 事件
// 当由一个消息到达时候触发
sp.onCall((req, res) => {
let msgPackIn = req.msg
console.log(msgPackIn)
// msgPackIn结构如下
//{in1:"a"}
// key(inN) 表示第N个消息入口, value是字符串
// doSomething here
res.send(msgPackOut)
})
主动发送信息
sp.sendMessage(msgPack)
存储相关
目前存储相关api仍处于beta状态,api接口会活跃变动
let storage = require("suanpan_node_sdk").sp.storage; // use node module
if (1) {
async function test() {
if (1) {
console.log("now we list all synced files");
let list_result = await storage.list("/");
console.log("list_result", list_result);
}
if (1) {
console.log("now we upload **package.json** as new.json");
let upload_result = await storage.upload("./package.json", "new.json");
console.log("upload successfully:", upload_result);
}
if (1) {
console.log("now we list, should see **new.json**");
let list_result = await storage.list("/");
console.log("list_result", list_result);
}
if (1) {
console.log(
"now we download **new.json** to local with new name **download.json**"
);
let download_file_buffer = await storage.download("new.json");
let fs = require("fs");
console.log("download_file_buffer type:", typeof download_file_buffer);
console.log(
"download_file_buffer isBuffer:",
Buffer.isBuffer(download_file_buffer)
);
fs.writeFileSync("./download.json", download_file_buffer);
}
if (1) {
console.log(
"now we download **new.json** direct to local file **download2.json**"
);
await storage.download("new.json", "./download2.json");
// console.log('is_download_success:', is_download_success)
}
if (1) {
console.log("now we delete **new.json**");
let r = await storage.delete("new.json");
}
if (1) {
console.log("now we list, should see **new.json** disappear");
let list_result = await storage.list("/");
console.log("list_result", list_result);
}
console.log("now we exit all test done");
process.exit();
}
test();
}
static 原则 图片资源 html等前端资源