Initial commit: 七牛云上传飞书机器人

功能:
- 飞书交互卡片支持
- 七牛云文件上传
- 自动 CDN 刷新
- 多存储桶配置
- 跨平台部署(Linux/macOS/Windows)
- Docker 支持
This commit is contained in:
饭团
2026-03-05 14:22:26 +08:00
commit b00567762f
15 changed files with 2286 additions and 0 deletions

185
src/cards/config-card.js Normal file
View File

@@ -0,0 +1,185 @@
/**
* 配置交互卡片模板
*/
class ConfigCard {
static create(configData) {
const bucketsText = Object.entries(configData.buckets || {})
.map(([name, bucket]) => {
return `**🪣 [${name}]**\n` +
`• 存储桶:${bucket.bucket}\n` +
`• 区域:${bucket.region}\n` +
`• 域名:${bucket.domain}\n` +
`• AccessKey: ${bucket.accessKey}`;
})
.join('\n\n');
return {
"config": {
"wide_screen_mode": true
},
"header": {
"template": "grey",
"title": {
"content": "⚙️ 七牛云配置",
"tag": "plain_text"
}
},
"elements": [
{
"tag": "div",
"text": {
"content": bucketsText || '暂无配置,请先添加存储桶配置。',
"tag": "lark_md"
}
},
{
"tag": "hr"
},
{
"tag": "div",
"text": {
"content": "**💡 修改配置**\n\n使用命令`/config set <key> <value>`\n\n示例\n`/config set default.domain https://new-cdn.com`",
"tag": "lark_md"
}
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {
"content": "📤 上传文件",
"tag": "plain_text"
},
"type": "primary",
"value": {
"action": "upload_file",
"type": "upload"
}
},
{
"tag": "button",
"text": {
"content": "❓ 帮助",
"tag": "plain_text"
},
"type": "default",
"value": {
"action": "help",
"type": "help"
}
}
]
}
]
};
}
static createEditForm(bucketName) {
return {
"config": {
"wide_screen_mode": true
},
"header": {
"template": "blue",
"title": {
"content": `✏️ 编辑配置 - ${bucketName}`,
"tag": "plain_text"
}
},
"elements": [
{
"tag": "input",
"label": {
"content": "AccessKey",
"tag": "plain_text"
},
"placeholder": {
"content": "请输入七牛云 AccessKey",
"tag": "plain_text"
},
"name": "access_key"
},
{
"tag": "input",
"label": {
"content": "SecretKey",
"tag": "plain_text"
},
"placeholder": {
"content": "请输入七牛云 SecretKey",
"tag": "plain_text"
},
"name": "secret_key"
},
{
"tag": "input",
"label": {
"content": "存储桶名称",
"tag": "plain_text"
},
"placeholder": {
"content": "例如my-bucket",
"tag": "plain_text"
},
"name": "bucket_name"
},
{
"tag": "input",
"label": {
"content": "区域",
"tag": "plain_text"
},
"placeholder": {
"content": "z0/z1/z2/na0/as0",
"tag": "plain_text"
},
"name": "region"
},
{
"tag": "input",
"label": {
"content": "CDN 域名",
"tag": "plain_text"
},
"placeholder": {
"content": "https://cdn.example.com",
"tag": "plain_text"
},
"name": "domain"
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {
"content": "💾 保存",
"tag": "plain_text"
},
"type": "primary",
"value": {
"action": "save_config",
"bucket": bucketName
}
},
{
"tag": "button",
"text": {
"content": "❌ 取消",
"tag": "plain_text"
},
"type": "default",
"value": {
"action": "cancel"
}
}
]
}
]
};
}
}
module.exports = { ConfigCard };

230
src/cards/upload-card.js Normal file
View File

@@ -0,0 +1,230 @@
/**
* 上传交互卡片模板
*/
class UploadCard {
static create() {
return {
"config": {
"wide_screen_mode": true
},
"header": {
"template": "blue",
"title": {
"content": "🍙 七牛云上传助手",
"tag": "plain_text"
}
},
"elements": [
{
"tag": "div",
"text": {
"content": "**📤 快速上传文件到七牛云**\n\n支持指定路径、多存储桶、自动 CDN 刷新",
"tag": "lark_md"
}
},
{
"tag": "hr"
},
{
"tag": "div",
"text": {
"content": "**💡 使用方式**\n\n• 直接发送文件给我\n• 或使用命令:`/upload [路径] [存储桶]`\n• 支持 `--original` 使用原文件名",
"tag": "lark_md"
}
},
{
"tag": "hr"
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {
"content": "📎 选择文件上传",
"tag": "plain_text"
},
"type": "primary",
"value": {
"action": "upload_file",
"type": "upload"
}
},
{
"tag": "button",
"text": {
"content": "⚙️ 配置",
"tag": "plain_text"
},
"type": "default",
"value": {
"action": "config",
"type": "config"
}
},
{
"tag": "button",
"text": {
"content": "❓ 帮助",
"tag": "plain_text"
},
"type": "default",
"value": {
"action": "help",
"type": "help"
}
}
]
}
]
};
}
static createUploading(fileName) {
return {
"config": {
"wide_screen_mode": true
},
"header": {
"template": "blue",
"title": {
"content": "📤 上传中...",
"tag": "plain_text"
}
},
"elements": [
{
"tag": "div",
"text": {
"content": `**文件:** ${fileName}\n\n正在上传到七牛云,请稍候...`,
"tag": "lark_md"
}
},
{
"tag": "progress_bar",
"tag": "div",
"text": {
"content": "上传进度",
"tag": "plain_text"
},
"value": 50,
"color": "blue"
}
]
};
}
static createSuccess(result) {
return {
"config": {
"wide_screen_mode": true
},
"header": {
"template": "green",
"title": {
"content": "✅ 上传成功",
"tag": "plain_text"
}
},
"elements": [
{
"tag": "div",
"text": {
"content": `**📦 文件:** ${result.key}\n\n` +
`**🔗 链接:** [点击查看](${result.url})\n\n` +
`**🪣 存储桶:** ${result.bucket || 'default'}`,
"tag": "lark_md"
}
},
{
"tag": "hr"
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {
"content": "🔗 复制链接",
"tag": "plain_text"
},
"type": "default",
"value": {
"action": "copy_link",
"url": result.url
}
},
{
"tag": "button",
"text": {
"content": "📤 继续上传",
"tag": "plain_text"
},
"type": "primary",
"value": {
"action": "upload_file",
"type": "upload"
}
}
]
}
]
};
}
static createError(error) {
return {
"config": {
"wide_screen_mode": true
},
"header": {
"template": "red",
"title": {
"content": "❌ 上传失败",
"tag": "plain_text"
}
},
"elements": [
{
"tag": "div",
"text": {
"content": `**错误信息:**\n${error.message}\n\n请检查配置或联系管理员。`,
"tag": "lark_md"
}
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {
"content": "🔄 重试",
"tag": "plain_text"
},
"type": "primary",
"value": {
"action": "upload_file",
"type": "upload"
}
},
{
"tag": "button",
"text": {
"content": "⚙️ 检查配置",
"tag": "plain_text"
},
"type": "default",
"value": {
"action": "config",
"type": "config"
}
}
]
}
]
};
}
}
module.exports = { UploadCard };