@xiongtao.xt/tau-plugins 0.47.0 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -21
- package/docs/README.md +49 -49
- package/docs/ai.md +172 -172
- package/docs/api-support.md +28 -28
- package/docs/backend.md +168 -168
- package/docs/content-metrics.md +43 -43
- package/docs/editor-collaboration.md +185 -185
- package/docs/editor.md +635 -635
- package/docs/excerpts.md +126 -126
- package/docs/flashcards.md +127 -127
- package/docs/getting-started.md +46 -46
- package/docs/mcp.md +173 -173
- package/docs/plugin-basics.md +211 -211
- package/docs/portability.md +114 -114
- package/docs/providers/README.md +111 -111
- package/docs/providers/asr.md +50 -44
- package/docs/providers/images.md +69 -69
- package/docs/providers/publish.md +146 -146
- package/docs/providers/sync.md +120 -114
- package/docs/providers/tts.md +48 -48
- package/docs/providers/upload.md +116 -116
- package/docs/providers/video.md +118 -118
- package/docs/release.md +132 -132
- package/docs/services.md +159 -159
- package/docs/site-data.md +90 -90
- package/docs/skills.md +128 -128
- package/docs/storage-and-network.md +68 -68
- package/docs/ui.md +568 -568
- package/docs/user-data.md +714 -714
- package/docs/websocket.md +37 -37
- package/docs/whiteboard-collaboration.md +65 -65
- package/docs/whiteboard.md +337 -337
- package/package.json +1 -1
- package/types/packages/plugins/src/provider-form.d.ts +35 -1
package/docs/providers/sync.md
CHANGED
|
@@ -1,114 +1,120 @@
|
|
|
1
|
-
# 同步存储
|
|
2
|
-
|
|
3
|
-
同步存储提供方让用户把笔记库同步到你接入的存储服务(对象存储、网盘等)。你只需要实现"读写远端文件"的几个基本操作;同步什么、怎么命名、版本与冲突、断点恢复都由 Tau 负责。
|
|
4
|
-
|
|
5
|
-
先读[服务提供方](README.md)了解共同的写法。
|
|
6
|
-
|
|
7
|
-
## 注册
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
import type { SyncProvider } from "@tau/plugins/sync";
|
|
11
|
-
|
|
12
|
-
context.sync.register({
|
|
13
|
-
id: context.pluginId,
|
|
14
|
-
name: "我的存储",
|
|
15
|
-
create: config => createStorage(context, parseConfig(config)),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
function createStorage(context: PluginContext, config: MyConfig): SyncProvider {
|
|
19
|
-
return {
|
|
20
|
-
async uploadFile(name, bytes) {
|
|
21
|
-
/* ... */ return true;
|
|
22
|
-
},
|
|
23
|
-
async downloadFile(name) {
|
|
24
|
-
/* ... */ return new Uint8Array();
|
|
25
|
-
},
|
|
26
|
-
async fileExists(name) {
|
|
27
|
-
/* ... */ return false;
|
|
28
|
-
},
|
|
29
|
-
async listFiles(prefix) {
|
|
30
|
-
/* ... */ return [];
|
|
31
|
-
},
|
|
32
|
-
async createFileIfAbsent(name, bytes) {
|
|
33
|
-
/* ... */ return true;
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
类型 `SyncProvider`、`SyncProviderDefinition`、`RemoteFileInfo` 从 `@tau/plugins/sync` 导入。
|
|
40
|
-
|
|
41
|
-
## 需要实现的方法
|
|
42
|
-
|
|
43
|
-
| 方法 | 返回 | 说明 |
|
|
44
|
-
| --------------------------------- | --------------------------- | ------------------------------------------------------------ |
|
|
45
|
-
| `uploadFile(name, bytes)` | `Promise<boolean>` | 上传对象,已存在时覆盖 |
|
|
46
|
-
| `downloadFile(name)` | `Promise<Uint8Array>` | 下载对象 |
|
|
47
|
-
| `fileExists(name)` | `Promise<boolean>` | 对象是否存在 |
|
|
48
|
-
| `listFiles(prefix?)` | `Promise<RemoteFileInfo[]>` | 列出前缀下的全部对象,**分页由你在内部处理完**,返回完整列表 |
|
|
49
|
-
| `createFileIfAbsent(name, bytes)` | `Promise<boolean>` | 只在对象不存在时创建,已存在时返回 `false` |
|
|
50
|
-
|
|
51
|
-
`RemoteFileInfo` 包含 `name`、`path`(相对路径)、`size`,以及可选的 `lastModified`、`hash`。
|
|
52
|
-
|
|
53
|
-
### createFileIfAbsent 必须是原子的
|
|
54
|
-
|
|
55
|
-
Tau 用它来保证多台设备同时同步时不会互相覆盖。它必须使用存储服务本身的条件写入能力(如 S3 的 `If-None-Match: *`),**不能用"先查是否存在、再上传"来模拟**,那样在并发时会出错。
|
|
56
|
-
|
|
57
|
-
请求失败、无法确定结果时直接抛出错误,Tau 会按自己的规则核实。
|
|
58
|
-
|
|
59
|
-
## 配置表单
|
|
60
|
-
|
|
61
|
-
同步与上传的配置表单只声明字段,不写界面。Tau 在插件详情 › 设置里按平台渲染(桌面为设置行,手机为分组行与推入式选择页),负责保存、必填校验、连接测试和服务选用;设置 › 同步 / 资源存储只列出各服务的摘要与状态。
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
context.settings.register({
|
|
65
|
-
id: "sync",
|
|
66
|
-
title: "我的存储",
|
|
67
|
-
target: "sync",
|
|
68
|
-
form: {
|
|
69
|
-
groups: [
|
|
70
|
-
{
|
|
71
|
-
title: "账号",
|
|
72
|
-
fields: [
|
|
73
|
-
{ key: "accessKey", label: "Access Key", type: "text" },
|
|
74
|
-
{ key: "secretKey", label: "Secret Key", type: "secret" },
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
title: "存储位置",
|
|
79
|
-
fields: [
|
|
80
|
-
{ key: "bucket", label: "Bucket", type: "text", summary: true },
|
|
81
|
-
{ key: "prefix", label: "目录", type: "text", optional: true, placeholder: "sync" },
|
|
82
|
-
{
|
|
83
|
-
key: "style",
|
|
84
|
-
label: "地址模式",
|
|
85
|
-
type: "choice",
|
|
86
|
-
default: "path",
|
|
87
|
-
options: [{ value: "path", label: "路径模式" }, { value: "host", label: "虚拟主机模式" }],
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
// 可选:保存前补全或校验,抛出的错误原样显示给用户
|
|
93
|
-
beforeSave: async (values, signal) => values,
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
| 字段类型 | 用途 |
|
|
99
|
-
| --------------- | -------------------------------------------------------------------- |
|
|
100
|
-
| `text` | 普通文本 |
|
|
101
|
-
| `secret` | 密钥、令牌、密码;不能作摘要 |
|
|
102
|
-
| `url` | 地址 |
|
|
103
|
-
| `choice` | 固定选项,`default` 为缺省值 |
|
|
104
|
-
| `remote-choice` | 按已填的值远程加载选项(如仓库、分支),`dependsOn` 中的字段变化时清空 |
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
-
|
|
109
|
-
-
|
|
110
|
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
1
|
+
# 同步存储
|
|
2
|
+
|
|
3
|
+
同步存储提供方让用户把笔记库同步到你接入的存储服务(对象存储、网盘等)。你只需要实现"读写远端文件"的几个基本操作;同步什么、怎么命名、版本与冲突、断点恢复都由 Tau 负责。
|
|
4
|
+
|
|
5
|
+
先读[服务提供方](README.md)了解共同的写法。
|
|
6
|
+
|
|
7
|
+
## 注册
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import type { SyncProvider } from "@tau/plugins/sync";
|
|
11
|
+
|
|
12
|
+
context.sync.register({
|
|
13
|
+
id: context.pluginId,
|
|
14
|
+
name: "我的存储",
|
|
15
|
+
create: config => createStorage(context, parseConfig(config)),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function createStorage(context: PluginContext, config: MyConfig): SyncProvider {
|
|
19
|
+
return {
|
|
20
|
+
async uploadFile(name, bytes) {
|
|
21
|
+
/* ... */ return true;
|
|
22
|
+
},
|
|
23
|
+
async downloadFile(name) {
|
|
24
|
+
/* ... */ return new Uint8Array();
|
|
25
|
+
},
|
|
26
|
+
async fileExists(name) {
|
|
27
|
+
/* ... */ return false;
|
|
28
|
+
},
|
|
29
|
+
async listFiles(prefix) {
|
|
30
|
+
/* ... */ return [];
|
|
31
|
+
},
|
|
32
|
+
async createFileIfAbsent(name, bytes) {
|
|
33
|
+
/* ... */ return true;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
类型 `SyncProvider`、`SyncProviderDefinition`、`RemoteFileInfo` 从 `@tau/plugins/sync` 导入。
|
|
40
|
+
|
|
41
|
+
## 需要实现的方法
|
|
42
|
+
|
|
43
|
+
| 方法 | 返回 | 说明 |
|
|
44
|
+
| --------------------------------- | --------------------------- | ------------------------------------------------------------ |
|
|
45
|
+
| `uploadFile(name, bytes)` | `Promise<boolean>` | 上传对象,已存在时覆盖 |
|
|
46
|
+
| `downloadFile(name)` | `Promise<Uint8Array>` | 下载对象 |
|
|
47
|
+
| `fileExists(name)` | `Promise<boolean>` | 对象是否存在 |
|
|
48
|
+
| `listFiles(prefix?)` | `Promise<RemoteFileInfo[]>` | 列出前缀下的全部对象,**分页由你在内部处理完**,返回完整列表 |
|
|
49
|
+
| `createFileIfAbsent(name, bytes)` | `Promise<boolean>` | 只在对象不存在时创建,已存在时返回 `false` |
|
|
50
|
+
|
|
51
|
+
`RemoteFileInfo` 包含 `name`、`path`(相对路径)、`size`,以及可选的 `lastModified`、`hash`。
|
|
52
|
+
|
|
53
|
+
### createFileIfAbsent 必须是原子的
|
|
54
|
+
|
|
55
|
+
Tau 用它来保证多台设备同时同步时不会互相覆盖。它必须使用存储服务本身的条件写入能力(如 S3 的 `If-None-Match: *`),**不能用"先查是否存在、再上传"来模拟**,那样在并发时会出错。
|
|
56
|
+
|
|
57
|
+
请求失败、无法确定结果时直接抛出错误,Tau 会按自己的规则核实。
|
|
58
|
+
|
|
59
|
+
## 配置表单
|
|
60
|
+
|
|
61
|
+
同步与上传的配置表单只声明字段,不写界面。Tau 在插件详情 › 设置里按平台渲染(桌面为设置行,手机为分组行与推入式选择页),负责保存、必填校验、连接测试和服务选用;设置 › 同步 / 资源存储只列出各服务的摘要与状态。
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
context.settings.register({
|
|
65
|
+
id: "sync",
|
|
66
|
+
title: "我的存储",
|
|
67
|
+
target: "sync",
|
|
68
|
+
form: {
|
|
69
|
+
groups: [
|
|
70
|
+
{
|
|
71
|
+
title: "账号",
|
|
72
|
+
fields: [
|
|
73
|
+
{ key: "accessKey", label: "Access Key", type: "text" },
|
|
74
|
+
{ key: "secretKey", label: "Secret Key", type: "secret" },
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
title: "存储位置",
|
|
79
|
+
fields: [
|
|
80
|
+
{ key: "bucket", label: "Bucket", type: "text", summary: true },
|
|
81
|
+
{ key: "prefix", label: "目录", type: "text", optional: true, placeholder: "sync" },
|
|
82
|
+
{
|
|
83
|
+
key: "style",
|
|
84
|
+
label: "地址模式",
|
|
85
|
+
type: "choice",
|
|
86
|
+
default: "path",
|
|
87
|
+
options: [{ value: "path", label: "路径模式" }, { value: "host", label: "虚拟主机模式" }],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
// 可选:保存前补全或校验,抛出的错误原样显示给用户
|
|
93
|
+
beforeSave: async (values, signal) => values,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
| 字段类型 | 用途 |
|
|
99
|
+
| --------------- | -------------------------------------------------------------------- |
|
|
100
|
+
| `text` | 普通文本 |
|
|
101
|
+
| `secret` | 密钥、令牌、密码;不能作摘要 |
|
|
102
|
+
| `url` | 地址 |
|
|
103
|
+
| `choice` | 固定选项,`default` 为缺省值 |
|
|
104
|
+
| `remote-choice` | 按已填的值远程加载选项(如仓库、分支),`dependsOn` 中的字段变化时清空 |
|
|
105
|
+
| `switch` | 开关,值为 `"true"` / `"false"`,`default` 为布尔;不参与必填校验 |
|
|
106
|
+
| `service-choice` | 由宿主服务选择(目前为 `git.cacheDirectory`,仅桌面),值与 `labelKey` 显示名一起保存;留空即宿主默认 |
|
|
107
|
+
|
|
108
|
+
- 未标 `optional` 的字段都是必填,空值时 Tau 拒绝保存并标在字段上;「可选」由 Tau 显示,不要写进 label。
|
|
109
|
+
- 选项可带 `description`:手机上少量(≤3)带说明的选项平铺为整行单选,桌面在字段说明里显示当前选项的说明。
|
|
110
|
+
- 分组可带 `link: { label, url }`(仅 https),用于服务商控制台等外部链接。
|
|
111
|
+
- 字段可带 `visibleWhen: { key, equals }`,只在另一字段取该值时显示;隐藏时不参与必填校验,已存值保留。
|
|
112
|
+
- `beforeSave` 抛出 `ProviderFieldError(key, message)` 时,错误标在对应字段;其他错误显示在保存结果中。
|
|
113
|
+
- `summary: true` 的字段按顺序拼成服务列表里的摘要,例如「tau-sync · ap-southeast-1」。
|
|
114
|
+
- 配置值一律是字符串;保存时与已存配置合并,未声明的键原样保留。
|
|
115
|
+
- 保存不会改变用户当前选用的服务;选用由用户在设置页或插件设置页单独操作。
|
|
116
|
+
|
|
117
|
+
- 每次同步任务开始时,Tau 用当时的配置调用 `create`,任务过程中配置不变。
|
|
118
|
+
- 关闭设置页不影响进行中的同步。
|
|
119
|
+
- 同步进行中,插件不能被停用或卸载。
|
|
120
|
+
- 停用插件后,配置会保留。
|
package/docs/providers/tts.md
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
# 语音合成
|
|
2
|
-
|
|
3
|
-
语音提供方让用户用你接入的服务朗读文字、生成播客,以及复刻音色。
|
|
4
|
-
|
|
5
|
-
先读[服务提供方](README.md)了解共同的写法。
|
|
6
|
-
|
|
7
|
-
## 注册
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
context.tts.register({
|
|
11
|
-
id: context.pluginId,
|
|
12
|
-
name: "我的语音服务",
|
|
13
|
-
create: (config, modelId) => createVoiceService(context, parseConfig(config), modelId),
|
|
14
|
-
});
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
`create(config, modelId)` 用用户的一个账号配置和所选模型创建实例,不发起网络请求。
|
|
18
|
-
|
|
19
|
-
**用户可以为同一个插件添加多个账号**,每个账号是一份独立的配置。所以不要把"当前的 API Key"存在模块级变量里,一切都从 `create` 收到的 `config` 读取。
|
|
20
|
-
|
|
21
|
-
## 实例
|
|
22
|
-
|
|
23
|
-
| 成员 | 说明 |
|
|
24
|
-
| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
25
|
-
| `getVoices(signal)` | 返回音色列表:`{ id, name, type, description? }`,`type` 为 `system`(预置)、`cloned`(复刻)或 `custom` |
|
|
26
|
-
| `synthesize({ text, voiceId, options }, signal)` | 合成语音,返回 `{ audio: Uint8Array, mime }`。`options` 包含可选的 `speed`、`volume`、`pitch` |
|
|
27
|
-
| `cloneVoice({ file, requestedId?, name? }, signal)` | 可选。用一个参考音频文件复刻音色,返回新建的音色 |
|
|
28
|
-
| `textInstructions` | 可选。当前模型支持的文本标记规则(如停顿、语气标签),Tau 生成播客脚本时会参考 |
|
|
29
|
-
|
|
30
|
-
- 网络请求使用 `context.fetch`,并传入方法收到的 `signal`。
|
|
31
|
-
- `cloneVoice` 的 `file` 是 `{ name, mimeType, content }`,每次一个文件。返回实际创建的音色,不要返回上传文件的 ID。
|
|
32
|
-
|
|
33
|
-
## 配置表单
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
context.settings.register({
|
|
37
|
-
id: "tts", title: "我的语音服务", target: "tts",
|
|
38
|
-
models: [{ id: "speech-model" }],
|
|
39
|
-
form: { groups: [{ title: "账号", fields: [
|
|
40
|
-
{ key: "apiKey", label: "API Key", type: "secret" },
|
|
41
|
-
{ key: "baseUrl", label: "服务地址", type: "url", optional: true },
|
|
42
|
-
] }] },
|
|
43
|
-
});
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
桌面与移动均由宿主在插件页管理多个账号、凭据与模型。models 只提供新账号的初始目录,不覆盖已保存的自定义模型。应用语音设置选择当前账号、模型与音色并提供试听;保存配置不改变当前服务。字段、校验与 beforeSave 用法见[同步配置](sync.md)。
|
|
47
|
-
|
|
48
|
-
特殊交互可继续使用 component,接收 ttsConfig(instanceId、value、models、save);组件只编辑当前账号,不能改其他账号或默认服务。
|
|
1
|
+
# 语音合成
|
|
2
|
+
|
|
3
|
+
语音提供方让用户用你接入的服务朗读文字、生成播客,以及复刻音色。
|
|
4
|
+
|
|
5
|
+
先读[服务提供方](README.md)了解共同的写法。
|
|
6
|
+
|
|
7
|
+
## 注册
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
context.tts.register({
|
|
11
|
+
id: context.pluginId,
|
|
12
|
+
name: "我的语音服务",
|
|
13
|
+
create: (config, modelId) => createVoiceService(context, parseConfig(config), modelId),
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`create(config, modelId)` 用用户的一个账号配置和所选模型创建实例,不发起网络请求。
|
|
18
|
+
|
|
19
|
+
**用户可以为同一个插件添加多个账号**,每个账号是一份独立的配置。所以不要把"当前的 API Key"存在模块级变量里,一切都从 `create` 收到的 `config` 读取。
|
|
20
|
+
|
|
21
|
+
## 实例
|
|
22
|
+
|
|
23
|
+
| 成员 | 说明 |
|
|
24
|
+
| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `getVoices(signal)` | 返回音色列表:`{ id, name, type, description? }`,`type` 为 `system`(预置)、`cloned`(复刻)或 `custom` |
|
|
26
|
+
| `synthesize({ text, voiceId, options }, signal)` | 合成语音,返回 `{ audio: Uint8Array, mime }`。`options` 包含可选的 `speed`、`volume`、`pitch` |
|
|
27
|
+
| `cloneVoice({ file, requestedId?, name? }, signal)` | 可选。用一个参考音频文件复刻音色,返回新建的音色 |
|
|
28
|
+
| `textInstructions` | 可选。当前模型支持的文本标记规则(如停顿、语气标签),Tau 生成播客脚本时会参考 |
|
|
29
|
+
|
|
30
|
+
- 网络请求使用 `context.fetch`,并传入方法收到的 `signal`。
|
|
31
|
+
- `cloneVoice` 的 `file` 是 `{ name, mimeType, content }`,每次一个文件。返回实际创建的音色,不要返回上传文件的 ID。
|
|
32
|
+
|
|
33
|
+
## 配置表单
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
context.settings.register({
|
|
37
|
+
id: "tts", title: "我的语音服务", target: "tts",
|
|
38
|
+
models: [{ id: "speech-model" }],
|
|
39
|
+
form: { groups: [{ title: "账号", fields: [
|
|
40
|
+
{ key: "apiKey", label: "API Key", type: "secret" },
|
|
41
|
+
{ key: "baseUrl", label: "服务地址", type: "url", optional: true },
|
|
42
|
+
] }] },
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
桌面与移动均由宿主在插件页管理多个账号、凭据与模型。models 只提供新账号的初始目录,不覆盖已保存的自定义模型。应用语音设置选择当前账号、模型与音色并提供试听;保存配置不改变当前服务。字段、校验与 beforeSave 用法见[同步配置](sync.md)。
|
|
47
|
+
|
|
48
|
+
特殊交互可继续使用 component,接收 ttsConfig(instanceId、value、models、save);组件只编辑当前账号,不能改其他账号或默认服务。
|
package/docs/providers/upload.md
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
# 资源上传
|
|
2
|
-
|
|
3
|
-
资源上传提供方让用户把编辑器里的图片、附件上传到你接入的存储(图床、对象存储、Git 仓库等),正文中直接引用返回的地址。
|
|
4
|
-
|
|
5
|
-
先读[服务提供方](README.md)了解共同的写法。资源上传与[同步存储](sync.md)是两套独立的接口。
|
|
6
|
-
|
|
7
|
-
## 注册
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
context.upload.register({
|
|
11
|
-
id: context.pluginId,
|
|
12
|
-
name: "我的图床",
|
|
13
|
-
async upload(file, config, signal) {
|
|
14
|
-
const settings = parseConfig(config);
|
|
15
|
-
const response = await context.fetch(`${settings.endpoint}/${encodeURIComponent(file.name)}`, {
|
|
16
|
-
method: "PUT",
|
|
17
|
-
headers: { "Content-Type": file.mimeType, Authorization: `Bearer ${settings.token}` },
|
|
18
|
-
body: file.content,
|
|
19
|
-
signal,
|
|
20
|
-
});
|
|
21
|
-
if (!response.ok) throw new Error(`上传失败:${response.status}`);
|
|
22
|
-
return `${settings.publicBaseUrl}/${encodeURIComponent(file.name)}`;
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
`upload(file, config, signal)`:
|
|
28
|
-
|
|
29
|
-
| 参数 | 说明 |
|
|
30
|
-
| -------- | ---------------------------------------------------------------------------------- |
|
|
31
|
-
| `file` | `{ name, mimeType, content }`。`name` 已由 Tau 唯一命名,`content` 是 `Uint8Array` |
|
|
32
|
-
| `config` | 用户保存的配置 |
|
|
33
|
-
| `signal` | 取消信号,传给 `context.fetch` |
|
|
34
|
-
|
|
35
|
-
返回资源的 HTTP(S) 地址。
|
|
36
|
-
|
|
37
|
-
## 返回的地址
|
|
38
|
-
|
|
39
|
-
- 地址会写进正文,必须**长期有效**。不要返回有过期时间的签名地址。
|
|
40
|
-
- 上传成功不等于任何人都能访问:存储桶或仓库的公开读取需要用户自己设置。不要自动修改用户的存储权限,在 README 里说明怎么配置。
|
|
41
|
-
- 需要自定义公开域名时,在配置表单中声明一个可选的 `url` 字段,按对象路径拼出完整地址。
|
|
42
|
-
|
|
43
|
-
## 配置表单
|
|
44
|
-
|
|
45
|
-
同步与上传的配置表单只声明字段,不写界面。Tau 在插件详情 › 设置里按平台渲染(桌面为设置行,手机为分组行与推入式选择页),负责保存、必填校验、连接测试和服务选用;设置 › 同步 / 资源存储只列出各服务的摘要与状态。
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
context.settings.register({
|
|
49
|
-
id: "upload",
|
|
50
|
-
title: "我的存储",
|
|
51
|
-
target: "upload",
|
|
52
|
-
form: {
|
|
53
|
-
groups: [
|
|
54
|
-
{
|
|
55
|
-
title: "账号",
|
|
56
|
-
fields: [
|
|
57
|
-
{ key: "accessKey", label: "Access Key", type: "text" },
|
|
58
|
-
{ key: "secretKey", label: "Secret Key", type: "secret" },
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
title: "存储位置",
|
|
63
|
-
fields: [
|
|
64
|
-
{ key: "bucket", label: "Bucket", type: "text", summary: true },
|
|
65
|
-
{ key: "prefix", label: "目录", type: "text", optional: true, placeholder: "uploads" },
|
|
66
|
-
{
|
|
67
|
-
key: "style",
|
|
68
|
-
label: "地址模式",
|
|
69
|
-
type: "choice",
|
|
70
|
-
default: "path",
|
|
71
|
-
options: [{ value: "path", label: "路径模式" }, { value: "host", label: "虚拟主机模式" }],
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
// 可选:保存前补全或校验,抛出的错误原样显示给用户
|
|
77
|
-
beforeSave: async (values, signal) => values,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
| 字段类型 | 用途 |
|
|
83
|
-
| --------------- | -------------------------------------------------------------------- |
|
|
84
|
-
| `text` | 普通文本 |
|
|
85
|
-
| `secret` | 密钥、令牌、密码;不能作摘要 |
|
|
86
|
-
| `url` | 地址 |
|
|
87
|
-
| `choice` | 固定选项,`default` 为缺省值 |
|
|
88
|
-
| `remote-choice` | 按已填的值远程加载选项(如仓库、分支),`dependsOn` 中的字段变化时清空 |
|
|
89
|
-
|
|
90
|
-
- 未标 `optional` 的字段都是必填,空值时 Tau 拒绝保存并标在字段上;「可选」由 Tau 显示,不要写进 label。
|
|
91
|
-
- `summary: true` 的字段按顺序拼成服务列表里的摘要,例如「tau-sync · ap-southeast-1」。
|
|
92
|
-
- 配置值一律是字符串;保存时与已存配置合并,未声明的键原样保留。
|
|
93
|
-
- 保存不会改变用户当前选用的服务;选用由用户在设置页或插件设置页单独操作。
|
|
94
|
-
|
|
95
|
-
## 职责划分
|
|
96
|
-
|
|
97
|
-
Tau 负责图片压缩、文件命名、本地保存和多窗口之间的转发;插件只负责把文件传到远端并返回地址。插件拿不到用户的文件路径,也不修改笔记内容。
|
|
98
|
-
|
|
99
|
-
## 在其他功能中使用上传
|
|
100
|
-
|
|
101
|
-
插件自己需要上传文件时(例如上传参考音频),调用 `context.upload.uploadRemote`,它使用用户当前选择的远端上传配置:
|
|
102
|
-
|
|
103
|
-
```ts
|
|
104
|
-
const url = await context.upload.uploadRemote(
|
|
105
|
-
{ name: "sample.mp3", mimeType: "audio/mpeg", content: bytes },
|
|
106
|
-
{ signal }
|
|
107
|
-
);
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
用户选择的是本地存储时,`uploadRemote` 会明确报错,不会自动换成其他存储。取消只是停止等待,不会撤回已经上传的文件。
|
|
111
|
-
|
|
112
|
-
## 测试清单
|
|
113
|
-
|
|
114
|
-
- 用户选择本地存储时,插件不会被调用。
|
|
115
|
-
- 上传成功、失败(认证错误、网络错误)都有正确的结果和提示。
|
|
116
|
-
- 保存配置、停用插件、在独立窗口中上传、重启后再上传。
|
|
1
|
+
# 资源上传
|
|
2
|
+
|
|
3
|
+
资源上传提供方让用户把编辑器里的图片、附件上传到你接入的存储(图床、对象存储、Git 仓库等),正文中直接引用返回的地址。
|
|
4
|
+
|
|
5
|
+
先读[服务提供方](README.md)了解共同的写法。资源上传与[同步存储](sync.md)是两套独立的接口。
|
|
6
|
+
|
|
7
|
+
## 注册
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
context.upload.register({
|
|
11
|
+
id: context.pluginId,
|
|
12
|
+
name: "我的图床",
|
|
13
|
+
async upload(file, config, signal) {
|
|
14
|
+
const settings = parseConfig(config);
|
|
15
|
+
const response = await context.fetch(`${settings.endpoint}/${encodeURIComponent(file.name)}`, {
|
|
16
|
+
method: "PUT",
|
|
17
|
+
headers: { "Content-Type": file.mimeType, Authorization: `Bearer ${settings.token}` },
|
|
18
|
+
body: file.content,
|
|
19
|
+
signal,
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) throw new Error(`上传失败:${response.status}`);
|
|
22
|
+
return `${settings.publicBaseUrl}/${encodeURIComponent(file.name)}`;
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`upload(file, config, signal)`:
|
|
28
|
+
|
|
29
|
+
| 参数 | 说明 |
|
|
30
|
+
| -------- | ---------------------------------------------------------------------------------- |
|
|
31
|
+
| `file` | `{ name, mimeType, content }`。`name` 已由 Tau 唯一命名,`content` 是 `Uint8Array` |
|
|
32
|
+
| `config` | 用户保存的配置 |
|
|
33
|
+
| `signal` | 取消信号,传给 `context.fetch` |
|
|
34
|
+
|
|
35
|
+
返回资源的 HTTP(S) 地址。
|
|
36
|
+
|
|
37
|
+
## 返回的地址
|
|
38
|
+
|
|
39
|
+
- 地址会写进正文,必须**长期有效**。不要返回有过期时间的签名地址。
|
|
40
|
+
- 上传成功不等于任何人都能访问:存储桶或仓库的公开读取需要用户自己设置。不要自动修改用户的存储权限,在 README 里说明怎么配置。
|
|
41
|
+
- 需要自定义公开域名时,在配置表单中声明一个可选的 `url` 字段,按对象路径拼出完整地址。
|
|
42
|
+
|
|
43
|
+
## 配置表单
|
|
44
|
+
|
|
45
|
+
同步与上传的配置表单只声明字段,不写界面。Tau 在插件详情 › 设置里按平台渲染(桌面为设置行,手机为分组行与推入式选择页),负责保存、必填校验、连接测试和服务选用;设置 › 同步 / 资源存储只列出各服务的摘要与状态。
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
context.settings.register({
|
|
49
|
+
id: "upload",
|
|
50
|
+
title: "我的存储",
|
|
51
|
+
target: "upload",
|
|
52
|
+
form: {
|
|
53
|
+
groups: [
|
|
54
|
+
{
|
|
55
|
+
title: "账号",
|
|
56
|
+
fields: [
|
|
57
|
+
{ key: "accessKey", label: "Access Key", type: "text" },
|
|
58
|
+
{ key: "secretKey", label: "Secret Key", type: "secret" },
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
title: "存储位置",
|
|
63
|
+
fields: [
|
|
64
|
+
{ key: "bucket", label: "Bucket", type: "text", summary: true },
|
|
65
|
+
{ key: "prefix", label: "目录", type: "text", optional: true, placeholder: "uploads" },
|
|
66
|
+
{
|
|
67
|
+
key: "style",
|
|
68
|
+
label: "地址模式",
|
|
69
|
+
type: "choice",
|
|
70
|
+
default: "path",
|
|
71
|
+
options: [{ value: "path", label: "路径模式" }, { value: "host", label: "虚拟主机模式" }],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
// 可选:保存前补全或校验,抛出的错误原样显示给用户
|
|
77
|
+
beforeSave: async (values, signal) => values,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| 字段类型 | 用途 |
|
|
83
|
+
| --------------- | -------------------------------------------------------------------- |
|
|
84
|
+
| `text` | 普通文本 |
|
|
85
|
+
| `secret` | 密钥、令牌、密码;不能作摘要 |
|
|
86
|
+
| `url` | 地址 |
|
|
87
|
+
| `choice` | 固定选项,`default` 为缺省值 |
|
|
88
|
+
| `remote-choice` | 按已填的值远程加载选项(如仓库、分支),`dependsOn` 中的字段变化时清空 |
|
|
89
|
+
|
|
90
|
+
- 未标 `optional` 的字段都是必填,空值时 Tau 拒绝保存并标在字段上;「可选」由 Tau 显示,不要写进 label。
|
|
91
|
+
- `summary: true` 的字段按顺序拼成服务列表里的摘要,例如「tau-sync · ap-southeast-1」。
|
|
92
|
+
- 配置值一律是字符串;保存时与已存配置合并,未声明的键原样保留。
|
|
93
|
+
- 保存不会改变用户当前选用的服务;选用由用户在设置页或插件设置页单独操作。
|
|
94
|
+
|
|
95
|
+
## 职责划分
|
|
96
|
+
|
|
97
|
+
Tau 负责图片压缩、文件命名、本地保存和多窗口之间的转发;插件只负责把文件传到远端并返回地址。插件拿不到用户的文件路径,也不修改笔记内容。
|
|
98
|
+
|
|
99
|
+
## 在其他功能中使用上传
|
|
100
|
+
|
|
101
|
+
插件自己需要上传文件时(例如上传参考音频),调用 `context.upload.uploadRemote`,它使用用户当前选择的远端上传配置:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
const url = await context.upload.uploadRemote(
|
|
105
|
+
{ name: "sample.mp3", mimeType: "audio/mpeg", content: bytes },
|
|
106
|
+
{ signal }
|
|
107
|
+
);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
用户选择的是本地存储时,`uploadRemote` 会明确报错,不会自动换成其他存储。取消只是停止等待,不会撤回已经上传的文件。
|
|
111
|
+
|
|
112
|
+
## 测试清单
|
|
113
|
+
|
|
114
|
+
- 用户选择本地存储时,插件不会被调用。
|
|
115
|
+
- 上传成功、失败(认证错误、网络错误)都有正确的结果和提示。
|
|
116
|
+
- 保存配置、停用插件、在独立窗口中上传、重启后再上传。
|