Skip to content

Commit 40f5f57

Browse files
update: 错误内容调整
1 parent 7269a97 commit 40f5f57

4 files changed

Lines changed: 156 additions & 47 deletions

File tree

‎docs/api.md‎

Lines changed: 132 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ sidebar_position: 7
88

99
## 基础信息
1010

11-
**Base URL**: `https://bubble.alemonjs.com/api/robot/v1`
11+
**Base URL**: `https://bubble.alemonjs.com/api/bot/v1`
12+
13+
**Base File URL**: `https://bubble-oss-files.alemonjs.com`
1214

1315
**认证方式**: `Authorization: Bearer YOUR_BOT_TOKEN`
1416

@@ -31,7 +33,7 @@ Authorization: Bearer YOUR_BOT_TOKEN
3133
{
3234
"id": 123,
3335
"name": "MyBot",
34-
"avatar": "https://...",
36+
"avatar": "avatar/avatar/xxx.jpg",
3537
"description": "Bot description"
3638
}
3739
```
@@ -208,7 +210,7 @@ Authorization: Bearer YOUR_BOT_TOKEN
208210
"user": {
209211
"id": 1,
210212
"name": "user1",
211-
"avatar": "https://..."
213+
"avatar": "avatar/avatar/xxx.jpg"
212214
},
213215
"joinedAt": "2025-01-01T00:00:00Z"
214216
}
@@ -233,7 +235,7 @@ Authorization: Bearer YOUR_BOT_TOKEN
233235
"user": {
234236
"id": 1,
235237
"name": "user1",
236-
"avatar": "https://..."
238+
"avatar": "avatar/avatar/xxx.jpg"
237239
},
238240
"roles": [100, 101],
239241
"joinedAt": "2025-01-01T00:00:00Z"
@@ -287,20 +289,138 @@ Authorization: Bearer YOUR_BOT_TOKEN
287289

288290
**限制**:
289291

290-
- 单文件最大 5 MB
291-
- 每日配额:80 GB(发送消息会额外增加配额)
292+
- 单文件最大 15 MB
293+
- 每日配额:80 GB
292294
- 每月配额:2000 GB
295+
- 每月无限额度:10GB
293296

294297
**请求方式**: `multipart/form-data`
295298

296-
**响应示例**:
299+
**例子**:
297300

298-
```json
299-
{
300-
"url": "https://cdn.bubble.alemonjs.com/uploads/xxx.png",
301-
"filename": "image.png",
302-
"size": 102400
301+
```ts
302+
import axios from 'axios'
303+
import FormData from 'form-data'
304+
305+
// 请求参数
306+
type ExtraParams = {
307+
// 可选 频道、线程、群聊
308+
channelId?: string | number
309+
threadId?: string | number
310+
messageId?: string | number
311+
groupThreadId?: string | number
312+
}
313+
314+
/**
315+
* 文件信息接口
316+
*/
317+
interface FileInfo {
318+
path: string // 文件路径
319+
url: string // 访问地址
320+
// 需要拼接成可访问路径 `https://bubble-oss-files.alemonjs.com/${url}`
321+
category: string // 文件类型
322+
size: number // 文件大小
323+
contentType: string // MIME类型
324+
filename: string // 文件名
325+
channelId: string // 频道ID
326+
threadId: string // 线程ID
327+
groupThreadId: string // 群组线程ID
328+
messageId: string // 消息ID
329+
width?: number // 宽度(图片/视频)
330+
height?: number // 高度(图片/视频)
303331
}
332+
333+
/**
334+
* 上传响应接口
335+
*/
336+
interface UploadResponse {
337+
data: {
338+
file: FileInfo
339+
}
340+
}
341+
342+
/**
343+
* 上传配置接口
344+
*/
345+
interface UploadConfig {
346+
token: string
347+
request_proxy?: string
348+
request_config?: Record<string, any>
349+
}
350+
351+
/**
352+
* ============ 单例文件服务 ============
353+
* 萌新直接用,不用管new
354+
*/
355+
class FileService {
356+
private static instance: FileService
357+
private baseURL = 'https://bubble.alemonjs.com/api/bot/v1'
358+
359+
private constructor() {}
360+
361+
// 获取单例
362+
static getInstance(): FileService {
363+
if (!FileService.instance) {
364+
FileService.instance = new FileService()
365+
}
366+
return FileService.instance
367+
}
368+
369+
/**
370+
* 上传文件
371+
* @param file 文件对象 (Buffer/Stream)
372+
* @param filename 文件名
373+
* @param extra 额外参数 (channelId/threadId/messageId)
374+
*/
375+
async upload(
376+
file: File,
377+
filename?: string,
378+
extra?: ExtraParams = {}
379+
) {
380+
// 1. 创建FormData
381+
const form = new FormData()
382+
form.append('file', file, filename || 'file')
383+
384+
if (extra.channelId)
385+
form.append('channelId', String(extra.channelId))
386+
if (extra.threadId)
387+
form.append('threadId', String(extra.threadId))
388+
if (extra.messageId)
389+
form.append('messageId', String(extra.messageId))
390+
if (extra.groupThreadId)
391+
form.append(
392+
'groupThreadId',
393+
String(extra.groupThreadId)
394+
)
395+
396+
// 2. 获取配置(这里改成你的配置获取方式)
397+
const config: UploadConfig = {
398+
token: 'your-token' // 改成从环境变量/配置读取
399+
}
400+
401+
// 3. 创建请求客户端
402+
const client = axios.create({
403+
baseURL: this.baseURL,
404+
timeout: 60000,
405+
headers: {
406+
Authorization: `Bearer ${config.token}`,
407+
...form.getHeaders()
408+
},
409+
...(config.request_config || {})
410+
})
411+
412+
// 5. 发送请求
413+
const response = await client.post<UploadResponse>(
414+
'/files/upload',
415+
form
416+
)
417+
return response.data
418+
}
419+
}
420+
421+
const fileService = FileService.getInstance()
422+
423+
export default fileService
304424
```
305425

306426
### GET /files/quota

‎docs/auth.md‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,28 @@ curl -X GET https://bubble.alemonjs.com/api/bot/v1/me \
4646
```
4747

4848
```javascript
49-
const response = await fetch(
50-
'https://bubble.alemonjs.com/api/bot/v1/me',
51-
{
52-
headers: {
53-
'Authorization': `Bearer ${BOT_TOKEN}`,
54-
'Content-Type': 'application/json'
55-
}
49+
const BASE_URL = 'https://bubble.alemonjs.com/api/bot'
50+
const BASE_URL_V1 = `${BASE_URL}/v1`
51+
const response = await fetch(`${BASE_URL_V1}/me`, {
52+
headers: {
53+
'Authorization': `Bearer ${BOT_TOKEN}`,
54+
'Content-Type': 'application/json'
5655
}
57-
)
56+
})
5857
```
5958

6059
### WebSocket
6160

6261
在建立 WebSocket 连接时,通过 Header 传递 Token:
6362

6463
```javascript
65-
const ws = new WebSocket(
66-
'wss://bubble.alemonjs.com/api/bot/gateway',
67-
{
68-
headers: {
69-
Authorization: `Bearer ${BOT_TOKEN}`
70-
}
64+
const BASE_URL = 'https://bubble.alemonjs.com/api/bot'
65+
const BASE_URL_V1 = `${BASE_URL}/v1`
66+
const ws = new WebSocket(`${BASE_URL}/gateway`, {
67+
headers: {
68+
Authorization: `Bearer ${BOT_TOKEN}`
7169
}
72-
)
70+
})
7371
```
7472

7573
:::warning 重要

‎docs/gateway.md‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ wss://bubble.alemonjs.com/api/bot/gateway
1919
使用 Bot Token 通过 Authorization Header 连接:
2020

2121
```javascript
22-
const ws = new WebSocket(
23-
'wss://bubble.alemonjs.com/api/bot/gateway',
24-
{
25-
headers: {
26-
Authorization: `Bearer ${BOT_TOKEN}`
27-
}
22+
const BASE_URL = 'https://bubble.alemonjs.com/api/bot'
23+
const BASE_URL_V1 = `${BASE_URL}/v1`
24+
const GATEWAY_URL = `${BASE_URL}/gateway`
25+
const ws = new WebSocket(GATEWAY_URL, {
26+
headers: {
27+
Authorization: `Bearer ${BOT_TOKEN}`
2828
}
29-
)
29+
})
3030
```
3131

3232
### 2. 接收 HELLO
@@ -194,8 +194,9 @@ ws.send(
194194
import WebSocket from 'ws'
195195

196196
const BOT_TOKEN = process.env.BOT_TOKEN
197-
const GATEWAY_URL =
198-
'wss://bubble.alemonjs.com/api/bot/gateway'
197+
const BASE_URL = 'https://bubble.alemonjs.com/api/bot'
198+
const BASE_URL_V1 = `${BASE_URL}/v1`
199+
const GATEWAY_URL = `${BASE_URL}/gateway`
199200

200201
function connect() {
201202
const ws = new WebSocket(GATEWAY_URL, {

‎docusaurus.config.ts‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default defineConfig({
2525
docs: {
2626
sidebarPath: './sidebars.ts',
2727
editUrl:
28-
'https://github.com/lemonade-lab/alemonjs-docs'
28+
'https://github.com/lemonade-lab/bubble.dev'
2929
},
3030
theme: {
3131
customCss: './src/css/custom.css'
@@ -63,15 +63,6 @@ export default defineConfig({
6363
}
6464
]
6565
},
66-
// {
67-
// title: '社区',
68-
// items: [
69-
// {
70-
// label: '群聊',
71-
// href: 'https://qm.qq.com/q/aZYMNqUQc'
72-
// }
73-
// ]
74-
// },
7566
{
7667
title: '更多',
7768
items: [
@@ -99,7 +90,6 @@ export default defineConfig({
9990
indexBlog: false,
10091
indexPages: true,
10192
hashed: true,
102-
// language: ['en', 'zh'],
10393
language: ['zh'],
10494
searchResultLimits: 10,
10595
searchResultContextMaxLength: 50

0 commit comments

Comments
 (0)