@xiongtao.xt/tau-plugins 0.11.0 → 0.12.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/UPLOAD.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 资源上传插件
|
|
2
|
+
|
|
3
|
+
需要 SDK 0.12.0 和包含资源上传插件能力的 Tau 0.59.0 客户端。上传返回正文可直接引用的 HTTP(S) 地址;数据库和资源目录同步使用 SYNC.md 的另一套接口。
|
|
4
|
+
|
|
5
|
+
在 activate 中注册提供方:
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
context.upload.register({
|
|
9
|
+
id: context.pluginId,
|
|
10
|
+
name: "我的资源存储",
|
|
11
|
+
async upload(file, config) {
|
|
12
|
+
// 用 context.fetch 请求服务商,认证与路径由本次 config 决定。
|
|
13
|
+
// file.name 已唯一命名,file.mimeType 是 MIME,file.content 为 Uint8Array。
|
|
14
|
+
return uploadToStorage(context.fetch, file, config);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
context.settings.register({
|
|
18
|
+
id: "upload",
|
|
19
|
+
title: "我的资源存储",
|
|
20
|
+
target: "upload",
|
|
21
|
+
component: UploadSettings,
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
UploadSettings 接收 PluginSettingsProps。读取 uploadConfig.value,在用户保存时调用 await uploadConfig.save(config),宿主保存并选中该提供方;不要将同一份上传配置再存到 context.storage。配置是 JsonValue,读取时自行校验字段并给出错误提示。组件在资源存储设置页显示;插件详情页提供跳转入口。
|
|
26
|
+
|
|
27
|
+
每个插件只能注册一个上传提供方,id 必须等于 context.pluginId。宿主负责压缩、文件唯一命名、本地保存和跨窗口转发。插件只负责远端上传和返回资源地址,不读取用户文件路径,也不修改笔记内容。
|
|
28
|
+
|
|
29
|
+
请求通过 context.fetch 发送,失败抛出错误,不返回空地址或吞掉失败。停用插件会取消上下文请求并拒绝迟到结果。插件在渲染进程执行,不使用 Node 模块或额外后台入口。
|
|
30
|
+
|
|
31
|
+
返回地址必须长期可引用;不要返回短期签名 URL。桶或仓库的公开读取策略由用户配置,上传成功不等于匿名用户可以访问。不要自动修改用户桶权限。需要自定义公开域名时由插件设置提供,按对象路径返回完整 URL。
|
|
32
|
+
|
|
33
|
+
完成后验证:本地模式不调用插件、远端上传成功及失败、保存配置、停用、独立窗口上传、重启恢复。README.md 应说明如何配置公开访问和常见服务商错误。
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import type { PluginEditorExtension } from "./editor";
|
|
|
8
8
|
import type { MarkdownCodec } from "../../markdown/src/index";
|
|
9
9
|
import type { PluginSettings } from "./settings";
|
|
10
10
|
import type { PluginSync } from "./sync";
|
|
11
|
+
import type { PluginUpload } from "./upload";
|
|
11
12
|
import type { PluginSidebar } from "./sidebar";
|
|
12
13
|
import type { PluginExcerpts, PluginMaterials } from "./excerpts";
|
|
13
14
|
import type { PluginMCP } from "./mcp";
|
|
@@ -39,6 +40,7 @@ export interface PluginContext {
|
|
|
39
40
|
readonly editor: PluginEditor;
|
|
40
41
|
readonly settings: PluginSettings;
|
|
41
42
|
readonly sync: PluginSync;
|
|
43
|
+
readonly upload: PluginUpload;
|
|
42
44
|
readonly sidebar: PluginSidebar;
|
|
43
45
|
readonly excerpts: PluginExcerpts;
|
|
44
46
|
readonly materials: PluginMaterials;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PluginDefinition } from "./contract";
|
|
2
|
+
export type * from "./upload";
|
|
2
3
|
export type { JsonValue, Disposable, PluginStorage, PluginCommand, PluginContext, PluginInstance, PluginDefinition, } from "./contract";
|
|
3
4
|
export type { PluginSettings, PluginSettingsDefinition, PluginSettingsProps, PluginSettingsHandle, } from "./settings";
|
|
4
5
|
export * from "./editor";
|
|
@@ -3,6 +3,10 @@ import type { Disposable, PluginContext } from "./index";
|
|
|
3
3
|
import type { JsonValue } from "./json";
|
|
4
4
|
export interface PluginSettingsProps {
|
|
5
5
|
readonly context: PluginContext;
|
|
6
|
+
readonly uploadConfig?: {
|
|
7
|
+
readonly value: JsonValue;
|
|
8
|
+
save(value: JsonValue): Promise<void>;
|
|
9
|
+
};
|
|
6
10
|
readonly syncConfig?: {
|
|
7
11
|
readonly value: JsonValue;
|
|
8
12
|
save(value: JsonValue): Promise<void>;
|
|
@@ -13,7 +17,7 @@ export interface PluginSettingsDefinition {
|
|
|
13
17
|
title: string;
|
|
14
18
|
description?: string;
|
|
15
19
|
/** 同步提供方的配置表单挂载到宿主同步设置。 */
|
|
16
|
-
target?: "sync";
|
|
20
|
+
target?: "sync" | "upload";
|
|
17
21
|
component: ComponentType<PluginSettingsProps>;
|
|
18
22
|
}
|
|
19
23
|
export interface PluginSettingsHandle extends Disposable {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Disposable, JsonValue } from "./contract";
|
|
2
|
+
export interface UploadFile {
|
|
3
|
+
/** 宿主已完成压缩和唯一命名,插件只负责追加远端路径前缀。 */
|
|
4
|
+
name: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
content: Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export interface UploadProviderDefinition {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
/** 返回可供正文直接引用的HTTP(S)地址,不返回临时签名URL。 */
|
|
12
|
+
upload(file: UploadFile, config: JsonValue): Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
export interface PluginUpload {
|
|
15
|
+
register(definition: UploadProviderDefinition): Disposable;
|
|
16
|
+
}
|