@perk-net/perk-pushplus-sdk 1.0.0 → 1.0.1
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/README.md +42 -0
- package/dist/index.cjs +224 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +149 -1
- package/dist/index.d.ts +149 -1
- package/dist/index.global.js +224 -5
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +223 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/image-api.ts +241 -0
- package/src/client.ts +3 -0
- package/src/config.ts +1 -1
- package/src/http.ts +101 -6
- package/src/index.ts +11 -0
- package/src/models.ts +62 -0
package/dist/index.d.cts
CHANGED
|
@@ -70,6 +70,18 @@ interface HttpRequestOptions {
|
|
|
70
70
|
headers?: Record<string, string>;
|
|
71
71
|
body?: string | null;
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* 二进制请求体(multipart 上传等场景使用)。
|
|
75
|
+
*
|
|
76
|
+
* 接受 fetch `BodyInit` 中的常见二进制形态。
|
|
77
|
+
*/
|
|
78
|
+
type HttpRawBody = Uint8Array | ArrayBuffer | Blob | null;
|
|
79
|
+
interface HttpRawRequestOptions {
|
|
80
|
+
method: string;
|
|
81
|
+
url: string;
|
|
82
|
+
headers?: Record<string, string>;
|
|
83
|
+
body?: HttpRawBody;
|
|
84
|
+
}
|
|
73
85
|
interface HttpResponse {
|
|
74
86
|
statusCode: number;
|
|
75
87
|
body: string;
|
|
@@ -79,10 +91,24 @@ interface HttpResponse {
|
|
|
79
91
|
*
|
|
80
92
|
* SDK 默认提供基于 `fetch` 的实现(Node 18+ 内置 / 浏览器原生)。
|
|
81
93
|
* 调用方也可以自行实现并通过 `PushPlusClient` 注入以使用其它客户端(如 axios/undici/got)。
|
|
94
|
+
*
|
|
95
|
+
* `executeRaw` 用于二进制请求体场景(如图片 multipart 上传)。
|
|
96
|
+
* 自定义实现可选择覆写以正确处理二进制;未覆写时调用方应通过
|
|
97
|
+
* {@link callExecuteRaw} 适配回退到 `execute`。
|
|
82
98
|
*/
|
|
83
99
|
interface HttpRequester {
|
|
84
100
|
execute(options: HttpRequestOptions): Promise<HttpResponse>;
|
|
101
|
+
/** 可选:执行带二进制 body 的请求。 */
|
|
102
|
+
executeRaw?(options: HttpRawRequestOptions): Promise<HttpResponse>;
|
|
85
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* 调用 {@link HttpRequester} 的二进制通道。
|
|
106
|
+
*
|
|
107
|
+
* - 若实现类提供了 `executeRaw`(推荐对二进制场景覆写),则直接使用;
|
|
108
|
+
* - 否则按 UTF-8 把字节解码成字符串后回退到 {@link HttpRequester.execute},
|
|
109
|
+
* 适用于 body 本身是文本的场景。
|
|
110
|
+
*/
|
|
111
|
+
declare function callExecuteRaw(requester: HttpRequester, options: HttpRawRequestOptions): Promise<HttpResponse>;
|
|
86
112
|
/**
|
|
87
113
|
* 基于 fetch 的请求执行器。
|
|
88
114
|
*
|
|
@@ -98,6 +124,8 @@ declare class FetchHttpRequester implements HttpRequester {
|
|
|
98
124
|
private readonly fetchImpl;
|
|
99
125
|
constructor(config: ResolvedPushPlusConfig, fetchImpl?: typeof fetch);
|
|
100
126
|
execute(options: HttpRequestOptions): Promise<HttpResponse>;
|
|
127
|
+
executeRaw(options: HttpRawRequestOptions): Promise<HttpResponse>;
|
|
128
|
+
private doExecute;
|
|
101
129
|
}
|
|
102
130
|
/**
|
|
103
131
|
* 是否处于成功的 HTTP 状态码区间(2xx)。
|
|
@@ -706,6 +734,63 @@ interface PreTestRequest {
|
|
|
706
734
|
contentType?: number;
|
|
707
735
|
message?: string;
|
|
708
736
|
}
|
|
737
|
+
/**
|
|
738
|
+
* 图片服务 - 获取上传凭证响应。
|
|
739
|
+
*
|
|
740
|
+
* 对应文档「十二. 图片服务接口 / 1. 获取上传凭证」。
|
|
741
|
+
* 返回七牛云表单上传所需的 token 及上传域名、存储桶等信息。
|
|
742
|
+
*/
|
|
743
|
+
interface ImageUploadToken {
|
|
744
|
+
/** 七牛云上传凭证。 */
|
|
745
|
+
uploadToken?: string;
|
|
746
|
+
/** 七牛云上传域名,例如 `https://upload.qiniup.com`。 */
|
|
747
|
+
uploadHost?: string;
|
|
748
|
+
/** 七牛云上传地址,一般等同于 `uploadHost + "/"`。 */
|
|
749
|
+
uploadUrl?: string;
|
|
750
|
+
/** 七牛云存储桶名称。 */
|
|
751
|
+
bucket?: string;
|
|
752
|
+
/** 凭证有效时间(秒)。 */
|
|
753
|
+
expiresIn?: number;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* 图片服务 - 上传图片响应(由七牛云直接返回)。
|
|
757
|
+
*
|
|
758
|
+
* 注意:该响应不是 PushPlus 统一的 `{code, msg, data}` 结构,
|
|
759
|
+
* 判断成功使用 `errno === 0`。
|
|
760
|
+
*/
|
|
761
|
+
interface ImageUploadResult {
|
|
762
|
+
/** 错误码;0 表示成功。 */
|
|
763
|
+
errno?: number;
|
|
764
|
+
/** 文件扩展名,例如 `.png`。 */
|
|
765
|
+
ext?: string;
|
|
766
|
+
/** 文件名。 */
|
|
767
|
+
fname?: string;
|
|
768
|
+
/** 文件大小(字节)。 */
|
|
769
|
+
fsize?: number;
|
|
770
|
+
/** 七牛云文件 hash。 */
|
|
771
|
+
hash?: string;
|
|
772
|
+
/** 对象存储中的路径 key。 */
|
|
773
|
+
key?: string;
|
|
774
|
+
/** MIME 类型,例如 `image/png`。 */
|
|
775
|
+
mimeType?: string;
|
|
776
|
+
/** 响应说明。 */
|
|
777
|
+
msg?: string;
|
|
778
|
+
/** 缩略图地址。 */
|
|
779
|
+
thumbnail?: string;
|
|
780
|
+
/** 图片访问地址。 */
|
|
781
|
+
url?: string;
|
|
782
|
+
}
|
|
783
|
+
/** 图片服务 - 图片列表项。 */
|
|
784
|
+
interface ImageItem {
|
|
785
|
+
/** 图片 id。 */
|
|
786
|
+
id?: number;
|
|
787
|
+
/** 图片地址。 */
|
|
788
|
+
imgUrl?: string;
|
|
789
|
+
/** 缩略图地址。 */
|
|
790
|
+
thumbnail?: string;
|
|
791
|
+
/** 创建时间。 */
|
|
792
|
+
createTime?: string;
|
|
793
|
+
}
|
|
709
794
|
|
|
710
795
|
/**
|
|
711
796
|
* API 基类,提供请求执行与统一错误处理。
|
|
@@ -837,6 +922,68 @@ declare class FriendApi extends OpenAbstractApi {
|
|
|
837
922
|
editRemark(id: number, remark: string): Promise<void>;
|
|
838
923
|
}
|
|
839
924
|
|
|
925
|
+
/**
|
|
926
|
+
* 二进制图片输入。
|
|
927
|
+
*
|
|
928
|
+
* - `Uint8Array`:Node 与浏览器通用(Buffer 是 Uint8Array 的子类)
|
|
929
|
+
* - `ArrayBuffer`:原始字节缓冲
|
|
930
|
+
* - `Blob`/`File`:浏览器与 Node 18+ 都支持
|
|
931
|
+
*/
|
|
932
|
+
type ImageFileInput = Uint8Array | ArrayBuffer | Blob;
|
|
933
|
+
/** 通用上传选项。 */
|
|
934
|
+
interface ImageUploadOptions {
|
|
935
|
+
/** 文件名(建议带扩展名,如 `logo.png`)。 */
|
|
936
|
+
fileName: string;
|
|
937
|
+
/** 文件 MIME 类型;未指定时按文件名后缀猜测。 */
|
|
938
|
+
contentType?: string;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* 开放接口 - 图片服务(文档「十二. 图片服务接口」)。
|
|
942
|
+
*
|
|
943
|
+
* 包含 4 个接口:
|
|
944
|
+
*
|
|
945
|
+
* 1. {@link ImageApi.getUploadToken} 获取上传凭证
|
|
946
|
+
* 2. {@link ImageApi.upload} 上传图片到七牛云(multipart/form-data,**不**带 access-key)
|
|
947
|
+
* 3. {@link ImageApi.list} 已上传图片列表
|
|
948
|
+
* 4. {@link ImageApi.delete} 主动删除图片
|
|
949
|
+
*
|
|
950
|
+
* 另外提供 {@link ImageApi.uploadBytes} 等便捷方法,
|
|
951
|
+
* 内部自动「先取凭证 → 再上传」。仅支持图片类型,30 天有效期。
|
|
952
|
+
*/
|
|
953
|
+
declare class ImageApi extends OpenAbstractApi {
|
|
954
|
+
constructor(config: ResolvedPushPlusConfig, http: HttpRequester, mgr: AccessKeyManager);
|
|
955
|
+
/** 1. 获取上传凭证。 */
|
|
956
|
+
getUploadToken(): Promise<ImageUploadToken>;
|
|
957
|
+
/**
|
|
958
|
+
* 2. 上传图片到七牛云。
|
|
959
|
+
*
|
|
960
|
+
* 使用「获取上传凭证」返回的 `uploadUrl` 与 `uploadToken`,
|
|
961
|
+
* 按七牛云表单上传规范以 `multipart/form-data` 提交。该请求
|
|
962
|
+
* **不会** 携带 PushPlus 的 `access-key` 头。
|
|
963
|
+
*/
|
|
964
|
+
upload(token: ImageUploadToken, file: ImageFileInput, options: ImageUploadOptions): Promise<ImageUploadResult>;
|
|
965
|
+
/**
|
|
966
|
+
* 2. 上传图片到七牛云(低层方法)。直接指定上传地址与 token。
|
|
967
|
+
*/
|
|
968
|
+
uploadToQiniu(uploadUrl: string, uploadToken: string, file: ImageFileInput, options: ImageUploadOptions): Promise<ImageUploadResult>;
|
|
969
|
+
/**
|
|
970
|
+
* 便捷方法:自动获取上传凭证后上传字节数组 / Blob / ArrayBuffer。
|
|
971
|
+
*
|
|
972
|
+
* @example
|
|
973
|
+
* ```ts
|
|
974
|
+
* await client.image.uploadBytes(buffer, { fileName: 'a.png' });
|
|
975
|
+
* await client.image.uploadBytes(blob, { fileName: 'b.jpg', contentType: 'image/jpeg' });
|
|
976
|
+
* ```
|
|
977
|
+
*/
|
|
978
|
+
uploadBytes(file: ImageFileInput, options: ImageUploadOptions): Promise<ImageUploadResult>;
|
|
979
|
+
/** 3. 图片列表。 */
|
|
980
|
+
list(query?: PageQuery): Promise<PageResult<ImageItem>>;
|
|
981
|
+
/**
|
|
982
|
+
* 4. 主动删除图片;未删除的图片默认 30 天后由系统自动清理。
|
|
983
|
+
*/
|
|
984
|
+
delete(id: number): Promise<void>;
|
|
985
|
+
}
|
|
986
|
+
|
|
840
987
|
/**
|
|
841
988
|
* 本地限流守卫:当 PushPlus 服务端返回 ErrorCode.RATE_LIMITED(code=900)时,
|
|
842
989
|
* 在内存里按 token 维度记录"解禁时间",期间任何发送类调用都会直接抛 PushPlusError,
|
|
@@ -1115,6 +1262,7 @@ declare class PushPlusClient {
|
|
|
1115
1262
|
readonly clawBot: ClawBotApi;
|
|
1116
1263
|
readonly setting: SettingApi;
|
|
1117
1264
|
readonly pre: PreApi;
|
|
1265
|
+
readonly image: ImageApi;
|
|
1118
1266
|
constructor(options?: PushPlusClientOptions);
|
|
1119
1267
|
/** 与 Java SDK 风格一致的 Builder 入口。 */
|
|
1120
1268
|
static builder(): PushPlusClientBuilder;
|
|
@@ -1205,4 +1353,4 @@ declare const CallbackParser: {
|
|
|
1205
1353
|
parse: typeof parseCallback;
|
|
1206
1354
|
};
|
|
1207
1355
|
|
|
1208
|
-
export { AbstractApi, AccessKeyApi, AccessKeyManager, type AccessKeyResult, type ApiResponse, type BatchSendRequest, BatchSendRequestBuilder, type BatchSendResult, CallbackEvent, CallbackParser, type CallbackPayload, Channel, ChannelApi, ClawBotApi, type ClawBotInfo, type ClawBotMessage, type ClawBotQrCode, type CpItem, DEFAULT_BASE_URL, ErrorCode, FetchHttpRequester, FriendApi, type FriendInfo, type FriendItem, type FriendQrCode, type HttpRequestOptions, type HttpRequester, type HttpResponse, type MailDetail, type MailItem, MessageApi, type MessageCompleteInfo, type MessageItem, type MessageTokenAddRequest, MessageTokenApi, type MessageTokenEditRequest, type MessageTokenItem, type MessageTokenOption, type MpItem, OpenAbstractApi, OpenMessageApi, type PageQuery, type PageResult, PreApi, type PreDetail, type PreItem, type PreSaveRequest, type PreTestRequest, PushPlusClient, PushPlusClientBuilder, type PushPlusClientOptions, type PushPlusConfig, PushPlusError, PushPlusException, RateLimitGuard, type ResolvedPushPlusConfig, type SendCount, type SendMessageResult, type SendRequest, SendRequestBuilder, SendStatus, SendStatusDescription, SettingApi, Template, type TopicAddRequest, TopicApi, type TopicDetail, type TopicEditRequest, type TopicItem, type TopicListQuery, type TopicQrCode, TopicUserApi, type TopicUserInfo, type TopicUserItem, type TopicUserListQuery, UserApi, type UserDefaultDetail, type UserDefaultItem, type UserDefaultSaveRequest, type UserInfo, type UserLimitTime, WebhookApi, type WebhookItem, type WebhookSaveRequest, WebhookType, WebhookTypeDescription, batchSendRequest, errorCodeFromValue, isRateLimitedCode, isSuccessfulHttpStatus, parseCallback, resolveConfig, sendRequest };
|
|
1356
|
+
export { AbstractApi, AccessKeyApi, AccessKeyManager, type AccessKeyResult, type ApiResponse, type BatchSendRequest, BatchSendRequestBuilder, type BatchSendResult, CallbackEvent, CallbackParser, type CallbackPayload, Channel, ChannelApi, ClawBotApi, type ClawBotInfo, type ClawBotMessage, type ClawBotQrCode, type CpItem, DEFAULT_BASE_URL, ErrorCode, FetchHttpRequester, FriendApi, type FriendInfo, type FriendItem, type FriendQrCode, type HttpRawBody, type HttpRawRequestOptions, type HttpRequestOptions, type HttpRequester, type HttpResponse, ImageApi, type ImageFileInput, type ImageItem, type ImageUploadOptions, type ImageUploadResult, type ImageUploadToken, type MailDetail, type MailItem, MessageApi, type MessageCompleteInfo, type MessageItem, type MessageTokenAddRequest, MessageTokenApi, type MessageTokenEditRequest, type MessageTokenItem, type MessageTokenOption, type MpItem, OpenAbstractApi, OpenMessageApi, type PageQuery, type PageResult, PreApi, type PreDetail, type PreItem, type PreSaveRequest, type PreTestRequest, PushPlusClient, PushPlusClientBuilder, type PushPlusClientOptions, type PushPlusConfig, PushPlusError, PushPlusException, RateLimitGuard, type ResolvedPushPlusConfig, type SendCount, type SendMessageResult, type SendRequest, SendRequestBuilder, SendStatus, SendStatusDescription, SettingApi, Template, type TopicAddRequest, TopicApi, type TopicDetail, type TopicEditRequest, type TopicItem, type TopicListQuery, type TopicQrCode, TopicUserApi, type TopicUserInfo, type TopicUserItem, type TopicUserListQuery, UserApi, type UserDefaultDetail, type UserDefaultItem, type UserDefaultSaveRequest, type UserInfo, type UserLimitTime, WebhookApi, type WebhookItem, type WebhookSaveRequest, WebhookType, WebhookTypeDescription, batchSendRequest, callExecuteRaw, errorCodeFromValue, isRateLimitedCode, isSuccessfulHttpStatus, parseCallback, resolveConfig, sendRequest };
|
package/dist/index.d.ts
CHANGED
|
@@ -70,6 +70,18 @@ interface HttpRequestOptions {
|
|
|
70
70
|
headers?: Record<string, string>;
|
|
71
71
|
body?: string | null;
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* 二进制请求体(multipart 上传等场景使用)。
|
|
75
|
+
*
|
|
76
|
+
* 接受 fetch `BodyInit` 中的常见二进制形态。
|
|
77
|
+
*/
|
|
78
|
+
type HttpRawBody = Uint8Array | ArrayBuffer | Blob | null;
|
|
79
|
+
interface HttpRawRequestOptions {
|
|
80
|
+
method: string;
|
|
81
|
+
url: string;
|
|
82
|
+
headers?: Record<string, string>;
|
|
83
|
+
body?: HttpRawBody;
|
|
84
|
+
}
|
|
73
85
|
interface HttpResponse {
|
|
74
86
|
statusCode: number;
|
|
75
87
|
body: string;
|
|
@@ -79,10 +91,24 @@ interface HttpResponse {
|
|
|
79
91
|
*
|
|
80
92
|
* SDK 默认提供基于 `fetch` 的实现(Node 18+ 内置 / 浏览器原生)。
|
|
81
93
|
* 调用方也可以自行实现并通过 `PushPlusClient` 注入以使用其它客户端(如 axios/undici/got)。
|
|
94
|
+
*
|
|
95
|
+
* `executeRaw` 用于二进制请求体场景(如图片 multipart 上传)。
|
|
96
|
+
* 自定义实现可选择覆写以正确处理二进制;未覆写时调用方应通过
|
|
97
|
+
* {@link callExecuteRaw} 适配回退到 `execute`。
|
|
82
98
|
*/
|
|
83
99
|
interface HttpRequester {
|
|
84
100
|
execute(options: HttpRequestOptions): Promise<HttpResponse>;
|
|
101
|
+
/** 可选:执行带二进制 body 的请求。 */
|
|
102
|
+
executeRaw?(options: HttpRawRequestOptions): Promise<HttpResponse>;
|
|
85
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* 调用 {@link HttpRequester} 的二进制通道。
|
|
106
|
+
*
|
|
107
|
+
* - 若实现类提供了 `executeRaw`(推荐对二进制场景覆写),则直接使用;
|
|
108
|
+
* - 否则按 UTF-8 把字节解码成字符串后回退到 {@link HttpRequester.execute},
|
|
109
|
+
* 适用于 body 本身是文本的场景。
|
|
110
|
+
*/
|
|
111
|
+
declare function callExecuteRaw(requester: HttpRequester, options: HttpRawRequestOptions): Promise<HttpResponse>;
|
|
86
112
|
/**
|
|
87
113
|
* 基于 fetch 的请求执行器。
|
|
88
114
|
*
|
|
@@ -98,6 +124,8 @@ declare class FetchHttpRequester implements HttpRequester {
|
|
|
98
124
|
private readonly fetchImpl;
|
|
99
125
|
constructor(config: ResolvedPushPlusConfig, fetchImpl?: typeof fetch);
|
|
100
126
|
execute(options: HttpRequestOptions): Promise<HttpResponse>;
|
|
127
|
+
executeRaw(options: HttpRawRequestOptions): Promise<HttpResponse>;
|
|
128
|
+
private doExecute;
|
|
101
129
|
}
|
|
102
130
|
/**
|
|
103
131
|
* 是否处于成功的 HTTP 状态码区间(2xx)。
|
|
@@ -706,6 +734,63 @@ interface PreTestRequest {
|
|
|
706
734
|
contentType?: number;
|
|
707
735
|
message?: string;
|
|
708
736
|
}
|
|
737
|
+
/**
|
|
738
|
+
* 图片服务 - 获取上传凭证响应。
|
|
739
|
+
*
|
|
740
|
+
* 对应文档「十二. 图片服务接口 / 1. 获取上传凭证」。
|
|
741
|
+
* 返回七牛云表单上传所需的 token 及上传域名、存储桶等信息。
|
|
742
|
+
*/
|
|
743
|
+
interface ImageUploadToken {
|
|
744
|
+
/** 七牛云上传凭证。 */
|
|
745
|
+
uploadToken?: string;
|
|
746
|
+
/** 七牛云上传域名,例如 `https://upload.qiniup.com`。 */
|
|
747
|
+
uploadHost?: string;
|
|
748
|
+
/** 七牛云上传地址,一般等同于 `uploadHost + "/"`。 */
|
|
749
|
+
uploadUrl?: string;
|
|
750
|
+
/** 七牛云存储桶名称。 */
|
|
751
|
+
bucket?: string;
|
|
752
|
+
/** 凭证有效时间(秒)。 */
|
|
753
|
+
expiresIn?: number;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* 图片服务 - 上传图片响应(由七牛云直接返回)。
|
|
757
|
+
*
|
|
758
|
+
* 注意:该响应不是 PushPlus 统一的 `{code, msg, data}` 结构,
|
|
759
|
+
* 判断成功使用 `errno === 0`。
|
|
760
|
+
*/
|
|
761
|
+
interface ImageUploadResult {
|
|
762
|
+
/** 错误码;0 表示成功。 */
|
|
763
|
+
errno?: number;
|
|
764
|
+
/** 文件扩展名,例如 `.png`。 */
|
|
765
|
+
ext?: string;
|
|
766
|
+
/** 文件名。 */
|
|
767
|
+
fname?: string;
|
|
768
|
+
/** 文件大小(字节)。 */
|
|
769
|
+
fsize?: number;
|
|
770
|
+
/** 七牛云文件 hash。 */
|
|
771
|
+
hash?: string;
|
|
772
|
+
/** 对象存储中的路径 key。 */
|
|
773
|
+
key?: string;
|
|
774
|
+
/** MIME 类型,例如 `image/png`。 */
|
|
775
|
+
mimeType?: string;
|
|
776
|
+
/** 响应说明。 */
|
|
777
|
+
msg?: string;
|
|
778
|
+
/** 缩略图地址。 */
|
|
779
|
+
thumbnail?: string;
|
|
780
|
+
/** 图片访问地址。 */
|
|
781
|
+
url?: string;
|
|
782
|
+
}
|
|
783
|
+
/** 图片服务 - 图片列表项。 */
|
|
784
|
+
interface ImageItem {
|
|
785
|
+
/** 图片 id。 */
|
|
786
|
+
id?: number;
|
|
787
|
+
/** 图片地址。 */
|
|
788
|
+
imgUrl?: string;
|
|
789
|
+
/** 缩略图地址。 */
|
|
790
|
+
thumbnail?: string;
|
|
791
|
+
/** 创建时间。 */
|
|
792
|
+
createTime?: string;
|
|
793
|
+
}
|
|
709
794
|
|
|
710
795
|
/**
|
|
711
796
|
* API 基类,提供请求执行与统一错误处理。
|
|
@@ -837,6 +922,68 @@ declare class FriendApi extends OpenAbstractApi {
|
|
|
837
922
|
editRemark(id: number, remark: string): Promise<void>;
|
|
838
923
|
}
|
|
839
924
|
|
|
925
|
+
/**
|
|
926
|
+
* 二进制图片输入。
|
|
927
|
+
*
|
|
928
|
+
* - `Uint8Array`:Node 与浏览器通用(Buffer 是 Uint8Array 的子类)
|
|
929
|
+
* - `ArrayBuffer`:原始字节缓冲
|
|
930
|
+
* - `Blob`/`File`:浏览器与 Node 18+ 都支持
|
|
931
|
+
*/
|
|
932
|
+
type ImageFileInput = Uint8Array | ArrayBuffer | Blob;
|
|
933
|
+
/** 通用上传选项。 */
|
|
934
|
+
interface ImageUploadOptions {
|
|
935
|
+
/** 文件名(建议带扩展名,如 `logo.png`)。 */
|
|
936
|
+
fileName: string;
|
|
937
|
+
/** 文件 MIME 类型;未指定时按文件名后缀猜测。 */
|
|
938
|
+
contentType?: string;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* 开放接口 - 图片服务(文档「十二. 图片服务接口」)。
|
|
942
|
+
*
|
|
943
|
+
* 包含 4 个接口:
|
|
944
|
+
*
|
|
945
|
+
* 1. {@link ImageApi.getUploadToken} 获取上传凭证
|
|
946
|
+
* 2. {@link ImageApi.upload} 上传图片到七牛云(multipart/form-data,**不**带 access-key)
|
|
947
|
+
* 3. {@link ImageApi.list} 已上传图片列表
|
|
948
|
+
* 4. {@link ImageApi.delete} 主动删除图片
|
|
949
|
+
*
|
|
950
|
+
* 另外提供 {@link ImageApi.uploadBytes} 等便捷方法,
|
|
951
|
+
* 内部自动「先取凭证 → 再上传」。仅支持图片类型,30 天有效期。
|
|
952
|
+
*/
|
|
953
|
+
declare class ImageApi extends OpenAbstractApi {
|
|
954
|
+
constructor(config: ResolvedPushPlusConfig, http: HttpRequester, mgr: AccessKeyManager);
|
|
955
|
+
/** 1. 获取上传凭证。 */
|
|
956
|
+
getUploadToken(): Promise<ImageUploadToken>;
|
|
957
|
+
/**
|
|
958
|
+
* 2. 上传图片到七牛云。
|
|
959
|
+
*
|
|
960
|
+
* 使用「获取上传凭证」返回的 `uploadUrl` 与 `uploadToken`,
|
|
961
|
+
* 按七牛云表单上传规范以 `multipart/form-data` 提交。该请求
|
|
962
|
+
* **不会** 携带 PushPlus 的 `access-key` 头。
|
|
963
|
+
*/
|
|
964
|
+
upload(token: ImageUploadToken, file: ImageFileInput, options: ImageUploadOptions): Promise<ImageUploadResult>;
|
|
965
|
+
/**
|
|
966
|
+
* 2. 上传图片到七牛云(低层方法)。直接指定上传地址与 token。
|
|
967
|
+
*/
|
|
968
|
+
uploadToQiniu(uploadUrl: string, uploadToken: string, file: ImageFileInput, options: ImageUploadOptions): Promise<ImageUploadResult>;
|
|
969
|
+
/**
|
|
970
|
+
* 便捷方法:自动获取上传凭证后上传字节数组 / Blob / ArrayBuffer。
|
|
971
|
+
*
|
|
972
|
+
* @example
|
|
973
|
+
* ```ts
|
|
974
|
+
* await client.image.uploadBytes(buffer, { fileName: 'a.png' });
|
|
975
|
+
* await client.image.uploadBytes(blob, { fileName: 'b.jpg', contentType: 'image/jpeg' });
|
|
976
|
+
* ```
|
|
977
|
+
*/
|
|
978
|
+
uploadBytes(file: ImageFileInput, options: ImageUploadOptions): Promise<ImageUploadResult>;
|
|
979
|
+
/** 3. 图片列表。 */
|
|
980
|
+
list(query?: PageQuery): Promise<PageResult<ImageItem>>;
|
|
981
|
+
/**
|
|
982
|
+
* 4. 主动删除图片;未删除的图片默认 30 天后由系统自动清理。
|
|
983
|
+
*/
|
|
984
|
+
delete(id: number): Promise<void>;
|
|
985
|
+
}
|
|
986
|
+
|
|
840
987
|
/**
|
|
841
988
|
* 本地限流守卫:当 PushPlus 服务端返回 ErrorCode.RATE_LIMITED(code=900)时,
|
|
842
989
|
* 在内存里按 token 维度记录"解禁时间",期间任何发送类调用都会直接抛 PushPlusError,
|
|
@@ -1115,6 +1262,7 @@ declare class PushPlusClient {
|
|
|
1115
1262
|
readonly clawBot: ClawBotApi;
|
|
1116
1263
|
readonly setting: SettingApi;
|
|
1117
1264
|
readonly pre: PreApi;
|
|
1265
|
+
readonly image: ImageApi;
|
|
1118
1266
|
constructor(options?: PushPlusClientOptions);
|
|
1119
1267
|
/** 与 Java SDK 风格一致的 Builder 入口。 */
|
|
1120
1268
|
static builder(): PushPlusClientBuilder;
|
|
@@ -1205,4 +1353,4 @@ declare const CallbackParser: {
|
|
|
1205
1353
|
parse: typeof parseCallback;
|
|
1206
1354
|
};
|
|
1207
1355
|
|
|
1208
|
-
export { AbstractApi, AccessKeyApi, AccessKeyManager, type AccessKeyResult, type ApiResponse, type BatchSendRequest, BatchSendRequestBuilder, type BatchSendResult, CallbackEvent, CallbackParser, type CallbackPayload, Channel, ChannelApi, ClawBotApi, type ClawBotInfo, type ClawBotMessage, type ClawBotQrCode, type CpItem, DEFAULT_BASE_URL, ErrorCode, FetchHttpRequester, FriendApi, type FriendInfo, type FriendItem, type FriendQrCode, type HttpRequestOptions, type HttpRequester, type HttpResponse, type MailDetail, type MailItem, MessageApi, type MessageCompleteInfo, type MessageItem, type MessageTokenAddRequest, MessageTokenApi, type MessageTokenEditRequest, type MessageTokenItem, type MessageTokenOption, type MpItem, OpenAbstractApi, OpenMessageApi, type PageQuery, type PageResult, PreApi, type PreDetail, type PreItem, type PreSaveRequest, type PreTestRequest, PushPlusClient, PushPlusClientBuilder, type PushPlusClientOptions, type PushPlusConfig, PushPlusError, PushPlusException, RateLimitGuard, type ResolvedPushPlusConfig, type SendCount, type SendMessageResult, type SendRequest, SendRequestBuilder, SendStatus, SendStatusDescription, SettingApi, Template, type TopicAddRequest, TopicApi, type TopicDetail, type TopicEditRequest, type TopicItem, type TopicListQuery, type TopicQrCode, TopicUserApi, type TopicUserInfo, type TopicUserItem, type TopicUserListQuery, UserApi, type UserDefaultDetail, type UserDefaultItem, type UserDefaultSaveRequest, type UserInfo, type UserLimitTime, WebhookApi, type WebhookItem, type WebhookSaveRequest, WebhookType, WebhookTypeDescription, batchSendRequest, errorCodeFromValue, isRateLimitedCode, isSuccessfulHttpStatus, parseCallback, resolveConfig, sendRequest };
|
|
1356
|
+
export { AbstractApi, AccessKeyApi, AccessKeyManager, type AccessKeyResult, type ApiResponse, type BatchSendRequest, BatchSendRequestBuilder, type BatchSendResult, CallbackEvent, CallbackParser, type CallbackPayload, Channel, ChannelApi, ClawBotApi, type ClawBotInfo, type ClawBotMessage, type ClawBotQrCode, type CpItem, DEFAULT_BASE_URL, ErrorCode, FetchHttpRequester, FriendApi, type FriendInfo, type FriendItem, type FriendQrCode, type HttpRawBody, type HttpRawRequestOptions, type HttpRequestOptions, type HttpRequester, type HttpResponse, ImageApi, type ImageFileInput, type ImageItem, type ImageUploadOptions, type ImageUploadResult, type ImageUploadToken, type MailDetail, type MailItem, MessageApi, type MessageCompleteInfo, type MessageItem, type MessageTokenAddRequest, MessageTokenApi, type MessageTokenEditRequest, type MessageTokenItem, type MessageTokenOption, type MpItem, OpenAbstractApi, OpenMessageApi, type PageQuery, type PageResult, PreApi, type PreDetail, type PreItem, type PreSaveRequest, type PreTestRequest, PushPlusClient, PushPlusClientBuilder, type PushPlusClientOptions, type PushPlusConfig, PushPlusError, PushPlusException, RateLimitGuard, type ResolvedPushPlusConfig, type SendCount, type SendMessageResult, type SendRequest, SendRequestBuilder, SendStatus, SendStatusDescription, SettingApi, Template, type TopicAddRequest, TopicApi, type TopicDetail, type TopicEditRequest, type TopicItem, type TopicListQuery, type TopicQrCode, TopicUserApi, type TopicUserInfo, type TopicUserItem, type TopicUserListQuery, UserApi, type UserDefaultDetail, type UserDefaultItem, type UserDefaultSaveRequest, type UserInfo, type UserLimitTime, WebhookApi, type WebhookItem, type WebhookSaveRequest, WebhookType, WebhookTypeDescription, batchSendRequest, callExecuteRaw, errorCodeFromValue, isRateLimitedCode, isSuccessfulHttpStatus, parseCallback, resolveConfig, sendRequest };
|