lazycat-sdk-dev
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese懒猫微服 SDK 与扩展开发指南
Lazycat MicroServer SDK and Extension Development Guide
你是一个专业的懒猫微服原生开发工程师。当用户希望用 Node.js/Go 从零开发一款微服应用,并希望调用微服底层系统 API(如获取设备列表、注册文件关联)时,请遵循本指南。
You are a professional native development engineer for Lazycat MicroServer. When users want to develop a microserver application from scratch using Node.js/Go and call the underlying system APIs of the microserver (such as obtaining device lists, registering file associations), please follow this guide.
1. 引入 Lzc-SDK (@lazycatcloud/sdk)
1. Introduce Lzc-SDK (@lazycatcloud/sdk)
官方提供了 JavaScript/TypeScript 和 Go 版本的 SDK。这让应用可以直接与懒猫微服的系统层、包管理层进行 gRPC 通信。
The official provides SDKs for JavaScript/TypeScript and Go versions. This allows applications to directly conduct gRPC communication with the system layer and package management layer of Lazycat MicroServer.
JavaScript / TypeScript 示例
JavaScript / TypeScript Example
SDK 内部使用 ,可以直接在浏览器前端代码中使用。
安装:
用法:
grpc-webnpm install @lazycatcloud/sdkjavascript
import { lzcAPIGateway } from "@lazycatcloud/sdk"
// 初始化网关,使用当前页面的 origin (如 https://myapp.heiyu.space)
const lzcapi = new lzcAPIGateway(window.location.origin, false)
// 示例:获取微服内的应用列表
async function fetchApps() {
const apps = await lzcapi.pkgm.QueryApplication({ appidList: [] })
console.log(apps)
}The SDK uses internally and can be used directly in browser front-end code.
Installation:
Usage:
grpc-webnpm install @lazycatcloud/sdkjavascript
import { lzcAPIGateway } from "@lazycatcloud/sdk"
// 初始化网关,使用当前页面的 origin (如 https://myapp.heiyu.space)
const lzcapi = new lzcAPIGateway(window.location.origin, false)
// 示例:获取微服内的应用列表
async function fetchApps() {
const apps = await lzcapi.pkgm.QueryApplication({ appidList: [] })
console.log(apps)
}Go 语言示例
Go Language Example
由于原生支持 gRPC,Go 是开发高性能后端的好选择。
安装:
用法:
go get -u gitee.com/linakesi/lzc-sdk/lang/gogo
import (
lzcsdk "gitee.com/linakesi/lzc-sdk/lang/go"
"gitee.com/linakesi/lzc-sdk/lang/go/common"
)
// 初始化 API
lzcapi, err := lzcsdk.NewAPIGateway(context.TODO())
// 示例:获取设备列表
request := &common.ListEndDeviceRequest{Uid: "admin"}
devices, err := lzcapi.Devices.ListEndDevices(ctx, request)Due to native gRPC support, Go is a good choice for developing high-performance backends.
Installation:
Usage:
go get -u gitee.com/linakesi/lzc-sdk/lang/gogo
import (
lzcsdk "gitee.com/linakesi/lzc-sdk/lang/go"
"gitee.com/linakesi/lzc-sdk/lang/go/common"
)
// 初始化 API
lzcapi, err := lzcsdk.NewAPIGateway(context.TODO())
// 示例:获取设备列表
request := &common.ListEndDeviceRequest{Uid: "admin"}
devices, err := lzcapi.Devices.ListEndDevices(ctx, request)2. 注册文件类型关联 (file_handler
)
file_handler2. Register File Type Association (file_handler
)
file_handler如果你开发了一个阅读器、播放器或编辑器,你希望用户在“懒猫网盘”里双击某类文件时,直接唤起你的应用来处理。
配置方法 ():
在 块中声明 。
lzc-manifest.ymlapplicationfile_handler示例:配置一个 Markdown 编辑器
yaml
application:
file_handler:
mime:
- text/markdown # 标准的 mime type
- x-lzc-extension/md # 或者指定具体的文件后缀 (懒猫特有语法)
# - */* # (高危) 匹配所有文件,适合"MD5计算器"等工具
actions:
# 当用户在网盘打开该文件时触发。%u 会被自动替换为实际的网盘文件路径。
open: /edit?filepath=%u应用内的处理:
当网盘唤起你的应用时,浏览器会跳转到 。你的前端或后端代码只需要解析 URL 中的 参数,然后通过挂载的 (或 API) 去读取该文件内容即可。
https://你的应用域名/edit?filepath=/用户/文档/test.mdfilepath/lzcapp/run/mnt/homeIf you have developed a reader, player or editor, you want your application to be directly invoked for processing when users double-click a certain type of file in "Lazycat Cloud Drive".
Configuration Method ():
Declare in the block.
lzc-manifest.ymlfile_handlerapplicationExample: Configure a Markdown Editor
yaml
application:
file_handler:
mime:
- text/markdown # 标准的 mime type
- x-lzc-extension/md # 或者指定具体的文件后缀 (懒猫特有语法)
# - */* # (高危) 匹配所有文件,适合"MD5计算器"等工具
actions:
# 当用户在网盘打开该文件时触发。%u 会被自动替换为实际的网盘文件路径。
open: /edit?filepath=%uIn-App Processing:
When the cloud drive invokes your application, the browser will redirect to . Your front-end or back-end code only needs to parse the parameter in the URL, and then read the file content through the mounted (or API).
https://your application domain/edit?filepath=/user/documents/test.mdfilepath/lzcapp/run/mnt/home平台兼容性说明
Platform Compatibility Notes
如果需要查看具体支持的 gRPC 方法列表(Go/JS)或了解更多的官方库(如前端专用的 选择器,或者内嵌的小型数据库 ),请主动读取本技能包 目录下的相关 Markdown 文档。
lzc-file-pickerslzc-minidbreferences/If you need to view the specific list of supported gRPC methods (Go/JS) or learn more official libraries (such as the front-end dedicated selector, or the embedded small database ), please actively read the relevant Markdown documents in the directory of this skill package.
lzc-file-pickerslzc-minidbreferences/