package workoss:extension;
world extension {
import extension-http;
import platform;
/// 获取配置
import get-settings: func(key: option<string>) -> result<string, string>;
/// 下载文件
import download-file: func(url: string, file-path: string, file-type: download-file-type) -> result<_,string>;
/// 让下载后的文件变成可执行文件
import make-file-executable: func(file-path: string) -> result<_, string>;
/// 执行命令 返回命令行执行结果
import run-command: func(cmd: terminal-command)->result<list<u8>,string>;
/// env vars
type env-vars = list<tuple<string, string>>;
///下载文件后缀 解压
enum download-file-type {
/// .gz
gzip,
/// .tar.gz
tar-gzip,
/// .zip
zip,
// uncompressed
uncompressed,
}
enum mime-type {
//json类型
json,
/// 文本
text,
/// 二进制
octet-stream,
///图片
image,
//音频
audio,
///视频
video
}
/// 执行命令
record terminal-command {
/// bin name
program: string,
/// 当前目录
current-dir: option<string>,
/// 参数
args: option<list<string>>,
/// 环境变量
envs: option<env-vars>,
}
/// 输入
record plugin-input {
body: option<list<u8>>,
mime-type: mime-type,
envs: option<env-vars>,
}
/// 输出
record plugin-output {
body: option<list<u8>>,
mime-type: mime-type,
}
/// 初始化插件
export init-plugin: func();
/// 执行插件
export run-plugin: func(input: plugin-input) -> result<plugin-output,string>;
}