assistsx-js 0.1.25 → 0.1.27
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/dist/Step.js +2 -2
- package/dist/gallery/gallery.d.ts +60 -0
- package/dist/gallery/gallery.js +142 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/network/http.d.ts +5 -1
- package/dist/network/http.js +3 -2
- package/package.json +1 -1
- package/src/Step.ts +2 -2
- package/src/gallery/gallery.ts +207 -0
- package/src/global.d.ts +4 -0
- package/src/index.ts +2 -1
- package/src/network/http.ts +6 -1
package/dist/Step.js
CHANGED
|
@@ -154,6 +154,8 @@ export class Step {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
+
//步骤执行完成
|
|
158
|
+
stepStore.completeStep();
|
|
157
159
|
}
|
|
158
160
|
catch (e) {
|
|
159
161
|
console.error(`步骤${implnName}执行出错`, e);
|
|
@@ -167,8 +169,6 @@ export class Step {
|
|
|
167
169
|
stepStore.setError(errorMsg);
|
|
168
170
|
throw e;
|
|
169
171
|
}
|
|
170
|
-
//步骤执行结束
|
|
171
|
-
stepStore.completeStep();
|
|
172
172
|
return currentStep;
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 相册操作响应接口定义
|
|
3
|
+
*/
|
|
4
|
+
export interface GalleryResponse {
|
|
5
|
+
success: boolean;
|
|
6
|
+
uri?: string;
|
|
7
|
+
id?: number;
|
|
8
|
+
type?: string;
|
|
9
|
+
message?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 删除相册项响应接口定义
|
|
13
|
+
*/
|
|
14
|
+
export interface GalleryDeleteResponse {
|
|
15
|
+
success: boolean;
|
|
16
|
+
deletedRows: number;
|
|
17
|
+
message?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class Gallery {
|
|
20
|
+
/**
|
|
21
|
+
* 执行异步调用
|
|
22
|
+
* @param method 方法名
|
|
23
|
+
* @param args 参数对象
|
|
24
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
25
|
+
* @returns Promise<调用响应>
|
|
26
|
+
*/
|
|
27
|
+
private asyncCall;
|
|
28
|
+
/**
|
|
29
|
+
* 添加图片到系统相册
|
|
30
|
+
* @param filePath 图片文件路径(必需)
|
|
31
|
+
* @param displayName 显示名称(可选,默认使用文件名)
|
|
32
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
33
|
+
* @returns Promise<相册操作响应>
|
|
34
|
+
*/
|
|
35
|
+
addImageToGallery(filePath: string, displayName?: string, timeout?: number): Promise<GalleryResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* 添加视频到系统相册
|
|
38
|
+
* @param filePath 视频文件路径(必需)
|
|
39
|
+
* @param displayName 显示名称(可选,默认使用文件名)
|
|
40
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
41
|
+
* @returns Promise<相册操作响应>
|
|
42
|
+
*/
|
|
43
|
+
addVideoToGallery(filePath: string, displayName?: string, timeout?: number): Promise<GalleryResponse>;
|
|
44
|
+
/**
|
|
45
|
+
* 从系统相册删除
|
|
46
|
+
* @param uri 媒体文件的URI(必需,格式如:content://media/external/images/media/123)
|
|
47
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
48
|
+
* @returns Promise<删除响应>
|
|
49
|
+
*/
|
|
50
|
+
deleteFromGalleryByUri(uri: string, timeout?: number): Promise<GalleryDeleteResponse>;
|
|
51
|
+
/**
|
|
52
|
+
* 从系统相册删除(通过ID和类型)
|
|
53
|
+
* @param id 媒体文件的ID(必需)
|
|
54
|
+
* @param type 媒体类型,"image" 或 "video"(必需)
|
|
55
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
56
|
+
* @returns Promise<删除响应>
|
|
57
|
+
*/
|
|
58
|
+
deleteFromGalleryById(id: number, type: "image" | "video", timeout?: number): Promise<GalleryDeleteResponse>;
|
|
59
|
+
}
|
|
60
|
+
export declare const gallery: Gallery;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 系统相册相关功能
|
|
3
|
+
* 提供添加图片/视频到相册和从相册删除的功能
|
|
4
|
+
*/
|
|
5
|
+
import { CallResponse } from "../CallResponse";
|
|
6
|
+
import { decodeBase64UTF8, generateUUID } from "../Utils";
|
|
7
|
+
// 回调函数存储对象
|
|
8
|
+
const callbacks = new Map();
|
|
9
|
+
// 初始化全局回调函数
|
|
10
|
+
if (typeof window !== "undefined" && !window.assistsxGalleryCallback) {
|
|
11
|
+
window.assistsxGalleryCallback = (data) => {
|
|
12
|
+
let callbackId;
|
|
13
|
+
try {
|
|
14
|
+
const json = decodeBase64UTF8(data);
|
|
15
|
+
const response = JSON.parse(json);
|
|
16
|
+
callbackId = response.callbackId;
|
|
17
|
+
if (callbackId) {
|
|
18
|
+
const callback = callbacks.get(callbackId);
|
|
19
|
+
if (callback) {
|
|
20
|
+
callback(json);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
console.error("Gallery callback error:", e);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
if (callbackId) {
|
|
29
|
+
callbacks.delete(callbackId);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export class Gallery {
|
|
35
|
+
/**
|
|
36
|
+
* 执行异步调用
|
|
37
|
+
* @param method 方法名
|
|
38
|
+
* @param args 参数对象
|
|
39
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
40
|
+
* @returns Promise<调用响应>
|
|
41
|
+
*/
|
|
42
|
+
async asyncCall(method, args, timeout = 30) {
|
|
43
|
+
const uuid = generateUUID();
|
|
44
|
+
const params = {
|
|
45
|
+
method,
|
|
46
|
+
arguments: args ? args : undefined,
|
|
47
|
+
callbackId: uuid,
|
|
48
|
+
};
|
|
49
|
+
const promise = new Promise((resolve) => {
|
|
50
|
+
callbacks.set(uuid, (data) => {
|
|
51
|
+
resolve(data);
|
|
52
|
+
});
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
callbacks.delete(uuid);
|
|
55
|
+
resolve(JSON.stringify(new CallResponse(0, null, uuid)));
|
|
56
|
+
}, timeout * 1000);
|
|
57
|
+
});
|
|
58
|
+
const result = window.assistsxGallery.call(JSON.stringify(params));
|
|
59
|
+
const promiseResult = await promise;
|
|
60
|
+
if (typeof promiseResult === "string") {
|
|
61
|
+
const responseData = JSON.parse(promiseResult);
|
|
62
|
+
return new CallResponse(responseData.code, responseData.data, responseData.callbackId);
|
|
63
|
+
}
|
|
64
|
+
throw new Error("Call failed");
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 添加图片到系统相册
|
|
68
|
+
* @param filePath 图片文件路径(必需)
|
|
69
|
+
* @param displayName 显示名称(可选,默认使用文件名)
|
|
70
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
71
|
+
* @returns Promise<相册操作响应>
|
|
72
|
+
*/
|
|
73
|
+
async addImageToGallery(filePath, displayName, timeout) {
|
|
74
|
+
var _a;
|
|
75
|
+
if (!filePath) {
|
|
76
|
+
throw new Error("filePath参数不能为空");
|
|
77
|
+
}
|
|
78
|
+
const response = await this.asyncCall("addImageToGallery", { filePath, displayName }, timeout);
|
|
79
|
+
if (!response.isSuccess()) {
|
|
80
|
+
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "添加图片到相册失败");
|
|
81
|
+
}
|
|
82
|
+
return response.data;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 添加视频到系统相册
|
|
86
|
+
* @param filePath 视频文件路径(必需)
|
|
87
|
+
* @param displayName 显示名称(可选,默认使用文件名)
|
|
88
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
89
|
+
* @returns Promise<相册操作响应>
|
|
90
|
+
*/
|
|
91
|
+
async addVideoToGallery(filePath, displayName, timeout) {
|
|
92
|
+
var _a;
|
|
93
|
+
if (!filePath) {
|
|
94
|
+
throw new Error("filePath参数不能为空");
|
|
95
|
+
}
|
|
96
|
+
const response = await this.asyncCall("addVideoToGallery", { filePath, displayName }, timeout);
|
|
97
|
+
if (!response.isSuccess()) {
|
|
98
|
+
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "添加视频到相册失败");
|
|
99
|
+
}
|
|
100
|
+
return response.data;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 从系统相册删除
|
|
104
|
+
* @param uri 媒体文件的URI(必需,格式如:content://media/external/images/media/123)
|
|
105
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
106
|
+
* @returns Promise<删除响应>
|
|
107
|
+
*/
|
|
108
|
+
async deleteFromGalleryByUri(uri, timeout) {
|
|
109
|
+
var _a;
|
|
110
|
+
if (!uri) {
|
|
111
|
+
throw new Error("uri参数不能为空");
|
|
112
|
+
}
|
|
113
|
+
const response = await this.asyncCall("deleteFromGallery", { uri }, timeout);
|
|
114
|
+
if (!response.isSuccess()) {
|
|
115
|
+
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "从相册删除失败");
|
|
116
|
+
}
|
|
117
|
+
return response.data;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 从系统相册删除(通过ID和类型)
|
|
121
|
+
* @param id 媒体文件的ID(必需)
|
|
122
|
+
* @param type 媒体类型,"image" 或 "video"(必需)
|
|
123
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
124
|
+
* @returns Promise<删除响应>
|
|
125
|
+
*/
|
|
126
|
+
async deleteFromGalleryById(id, type, timeout) {
|
|
127
|
+
var _a;
|
|
128
|
+
if (id === undefined || id === null) {
|
|
129
|
+
throw new Error("id参数不能为空");
|
|
130
|
+
}
|
|
131
|
+
if (!type || (type !== "image" && type !== "video")) {
|
|
132
|
+
throw new Error("type参数必须为 'image' 或 'video'");
|
|
133
|
+
}
|
|
134
|
+
const response = await this.asyncCall("deleteFromGallery", { id, type }, timeout);
|
|
135
|
+
if (!response.isSuccess()) {
|
|
136
|
+
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "从相册删除失败");
|
|
137
|
+
}
|
|
138
|
+
return response.data;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// 导出常量实例
|
|
142
|
+
export const gallery = new Gallery();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/network/http.d.ts
CHANGED
|
@@ -24,6 +24,9 @@ export interface HttpDownloadResponse {
|
|
|
24
24
|
savePath: string;
|
|
25
25
|
fileSize: number;
|
|
26
26
|
saveToGallerySuccess?: boolean;
|
|
27
|
+
galleryUri?: string;
|
|
28
|
+
galleryId?: number;
|
|
29
|
+
galleryType?: string;
|
|
27
30
|
headers: Record<string, string>;
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
@@ -96,10 +99,11 @@ export declare class Http {
|
|
|
96
99
|
* @param savePath 保存路径
|
|
97
100
|
* @param headers 请求头
|
|
98
101
|
* @param saveToGallery 是否保存到系统相册(仅支持图片和视频文件),默认 false
|
|
102
|
+
* @param displayName 保存到相册时的显示名称(可选,默认使用文件名)
|
|
99
103
|
* @param timeout 超时时间(秒),默认30秒
|
|
100
104
|
* @returns Promise<下载响应>
|
|
101
105
|
*/
|
|
102
|
-
httpDownload(url: string, savePath: string, headers?: Record<string, string>, saveToGallery?: boolean, timeout?: number): Promise<HttpDownloadResponse>;
|
|
106
|
+
httpDownload(url: string, savePath: string, headers?: Record<string, string>, saveToGallery?: boolean, displayName?: string, timeout?: number): Promise<HttpDownloadResponse>;
|
|
103
107
|
/**
|
|
104
108
|
* 配置 OkHttpClient
|
|
105
109
|
* @param config 配置选项
|
package/dist/network/http.js
CHANGED
|
@@ -145,12 +145,13 @@ export class Http {
|
|
|
145
145
|
* @param savePath 保存路径
|
|
146
146
|
* @param headers 请求头
|
|
147
147
|
* @param saveToGallery 是否保存到系统相册(仅支持图片和视频文件),默认 false
|
|
148
|
+
* @param displayName 保存到相册时的显示名称(可选,默认使用文件名)
|
|
148
149
|
* @param timeout 超时时间(秒),默认30秒
|
|
149
150
|
* @returns Promise<下载响应>
|
|
150
151
|
*/
|
|
151
|
-
async httpDownload(url, savePath, headers, saveToGallery, timeout) {
|
|
152
|
+
async httpDownload(url, savePath, headers, saveToGallery, displayName, timeout) {
|
|
152
153
|
var _a;
|
|
153
|
-
const response = await this.asyncCall("httpDownload", { url, savePath, headers, saveToGallery }, timeout);
|
|
154
|
+
const response = await this.asyncCall("httpDownload", { url, savePath, headers, saveToGallery, displayName }, timeout);
|
|
154
155
|
if (!response.isSuccess()) {
|
|
155
156
|
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "HTTP download failed");
|
|
156
157
|
}
|
package/package.json
CHANGED
package/src/Step.ts
CHANGED
|
@@ -219,6 +219,8 @@ export class Step {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
+
//步骤执行完成
|
|
223
|
+
stepStore.completeStep();
|
|
222
224
|
} catch (e: any) {
|
|
223
225
|
console.error(`步骤${implnName}执行出错`, e);
|
|
224
226
|
//步骤执行出错
|
|
@@ -231,8 +233,6 @@ export class Step {
|
|
|
231
233
|
stepStore.setError(errorMsg);
|
|
232
234
|
throw e
|
|
233
235
|
}
|
|
234
|
-
//步骤执行结束
|
|
235
|
-
stepStore.completeStep();
|
|
236
236
|
return currentStep;
|
|
237
237
|
}
|
|
238
238
|
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 系统相册相关功能
|
|
3
|
+
* 提供添加图片/视频到相册和从相册删除的功能
|
|
4
|
+
*/
|
|
5
|
+
import { CallResponse } from "../CallResponse";
|
|
6
|
+
import { decodeBase64UTF8, generateUUID } from "../Utils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 相册操作响应接口定义
|
|
10
|
+
*/
|
|
11
|
+
export interface GalleryResponse {
|
|
12
|
+
success: boolean;
|
|
13
|
+
uri?: string;
|
|
14
|
+
id?: number;
|
|
15
|
+
type?: string;
|
|
16
|
+
message?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 删除相册项响应接口定义
|
|
21
|
+
*/
|
|
22
|
+
export interface GalleryDeleteResponse {
|
|
23
|
+
success: boolean;
|
|
24
|
+
deletedRows: number;
|
|
25
|
+
message?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 回调函数存储对象
|
|
29
|
+
const callbacks: Map<string, (data: string) => void> = new Map();
|
|
30
|
+
|
|
31
|
+
// 初始化全局回调函数
|
|
32
|
+
if (typeof window !== "undefined" && !window.assistsxGalleryCallback) {
|
|
33
|
+
window.assistsxGalleryCallback = (data: string) => {
|
|
34
|
+
let callbackId: string | undefined;
|
|
35
|
+
try {
|
|
36
|
+
const json = decodeBase64UTF8(data);
|
|
37
|
+
const response = JSON.parse(json);
|
|
38
|
+
callbackId = response.callbackId;
|
|
39
|
+
if (callbackId) {
|
|
40
|
+
const callback = callbacks.get(callbackId);
|
|
41
|
+
if (callback) {
|
|
42
|
+
callback(json);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error("Gallery callback error:", e);
|
|
47
|
+
} finally {
|
|
48
|
+
if (callbackId) {
|
|
49
|
+
callbacks.delete(callbackId);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class Gallery {
|
|
56
|
+
/**
|
|
57
|
+
* 执行异步调用
|
|
58
|
+
* @param method 方法名
|
|
59
|
+
* @param args 参数对象
|
|
60
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
61
|
+
* @returns Promise<调用响应>
|
|
62
|
+
*/
|
|
63
|
+
private async asyncCall(
|
|
64
|
+
method: string,
|
|
65
|
+
args?: any,
|
|
66
|
+
timeout: number = 30
|
|
67
|
+
): Promise<CallResponse> {
|
|
68
|
+
const uuid = generateUUID();
|
|
69
|
+
const params = {
|
|
70
|
+
method,
|
|
71
|
+
arguments: args ? args : undefined,
|
|
72
|
+
callbackId: uuid,
|
|
73
|
+
};
|
|
74
|
+
const promise = new Promise<string>((resolve) => {
|
|
75
|
+
callbacks.set(uuid, (data: string) => {
|
|
76
|
+
resolve(data);
|
|
77
|
+
});
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
callbacks.delete(uuid);
|
|
80
|
+
resolve(JSON.stringify(new CallResponse(0, null, uuid)));
|
|
81
|
+
}, timeout * 1000);
|
|
82
|
+
});
|
|
83
|
+
const result = window.assistsxGallery.call(JSON.stringify(params));
|
|
84
|
+
const promiseResult = await promise;
|
|
85
|
+
if (typeof promiseResult === "string") {
|
|
86
|
+
const responseData = JSON.parse(promiseResult);
|
|
87
|
+
return new CallResponse(
|
|
88
|
+
responseData.code,
|
|
89
|
+
responseData.data,
|
|
90
|
+
responseData.callbackId
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
throw new Error("Call failed");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 添加图片到系统相册
|
|
98
|
+
* @param filePath 图片文件路径(必需)
|
|
99
|
+
* @param displayName 显示名称(可选,默认使用文件名)
|
|
100
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
101
|
+
* @returns Promise<相册操作响应>
|
|
102
|
+
*/
|
|
103
|
+
async addImageToGallery(
|
|
104
|
+
filePath: string,
|
|
105
|
+
displayName?: string,
|
|
106
|
+
timeout?: number
|
|
107
|
+
): Promise<GalleryResponse> {
|
|
108
|
+
if (!filePath) {
|
|
109
|
+
throw new Error("filePath参数不能为空");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const response = await this.asyncCall(
|
|
113
|
+
"addImageToGallery",
|
|
114
|
+
{ filePath, displayName },
|
|
115
|
+
timeout
|
|
116
|
+
);
|
|
117
|
+
if (!response.isSuccess()) {
|
|
118
|
+
throw new Error(response.data?.message || "添加图片到相册失败");
|
|
119
|
+
}
|
|
120
|
+
return response.data as GalleryResponse;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 添加视频到系统相册
|
|
125
|
+
* @param filePath 视频文件路径(必需)
|
|
126
|
+
* @param displayName 显示名称(可选,默认使用文件名)
|
|
127
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
128
|
+
* @returns Promise<相册操作响应>
|
|
129
|
+
*/
|
|
130
|
+
async addVideoToGallery(
|
|
131
|
+
filePath: string,
|
|
132
|
+
displayName?: string,
|
|
133
|
+
timeout?: number
|
|
134
|
+
): Promise<GalleryResponse> {
|
|
135
|
+
if (!filePath) {
|
|
136
|
+
throw new Error("filePath参数不能为空");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const response = await this.asyncCall(
|
|
140
|
+
"addVideoToGallery",
|
|
141
|
+
{ filePath, displayName },
|
|
142
|
+
timeout
|
|
143
|
+
);
|
|
144
|
+
if (!response.isSuccess()) {
|
|
145
|
+
throw new Error(response.data?.message || "添加视频到相册失败");
|
|
146
|
+
}
|
|
147
|
+
return response.data as GalleryResponse;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 从系统相册删除
|
|
152
|
+
* @param uri 媒体文件的URI(必需,格式如:content://media/external/images/media/123)
|
|
153
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
154
|
+
* @returns Promise<删除响应>
|
|
155
|
+
*/
|
|
156
|
+
async deleteFromGalleryByUri(
|
|
157
|
+
uri: string,
|
|
158
|
+
timeout?: number
|
|
159
|
+
): Promise<GalleryDeleteResponse> {
|
|
160
|
+
if (!uri) {
|
|
161
|
+
throw new Error("uri参数不能为空");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const response = await this.asyncCall(
|
|
165
|
+
"deleteFromGallery",
|
|
166
|
+
{ uri },
|
|
167
|
+
timeout
|
|
168
|
+
);
|
|
169
|
+
if (!response.isSuccess()) {
|
|
170
|
+
throw new Error(response.data?.message || "从相册删除失败");
|
|
171
|
+
}
|
|
172
|
+
return response.data as GalleryDeleteResponse;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 从系统相册删除(通过ID和类型)
|
|
177
|
+
* @param id 媒体文件的ID(必需)
|
|
178
|
+
* @param type 媒体类型,"image" 或 "video"(必需)
|
|
179
|
+
* @param timeout 超时时间(秒),默认30秒
|
|
180
|
+
* @returns Promise<删除响应>
|
|
181
|
+
*/
|
|
182
|
+
async deleteFromGalleryById(
|
|
183
|
+
id: number,
|
|
184
|
+
type: "image" | "video",
|
|
185
|
+
timeout?: number
|
|
186
|
+
): Promise<GalleryDeleteResponse> {
|
|
187
|
+
if (id === undefined || id === null) {
|
|
188
|
+
throw new Error("id参数不能为空");
|
|
189
|
+
}
|
|
190
|
+
if (!type || (type !== "image" && type !== "video")) {
|
|
191
|
+
throw new Error("type参数必须为 'image' 或 'video'");
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const response = await this.asyncCall(
|
|
195
|
+
"deleteFromGallery",
|
|
196
|
+
{ id, type },
|
|
197
|
+
timeout
|
|
198
|
+
);
|
|
199
|
+
if (!response.isSuccess()) {
|
|
200
|
+
throw new Error(response.data?.message || "从相册删除失败");
|
|
201
|
+
}
|
|
202
|
+
return response.data as GalleryDeleteResponse;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 导出常量实例
|
|
207
|
+
export const gallery = new Gallery();
|
package/src/global.d.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -20,4 +20,5 @@ export * from "./filesystem/path";
|
|
|
20
20
|
export * from "./filesystem/fileio/file-io";
|
|
21
21
|
export * from "./filesystem/fileutils/file-utils";
|
|
22
22
|
export * from "./ime/ime";
|
|
23
|
-
export * from "./imageutils/image-utils";
|
|
23
|
+
export * from "./imageutils/image-utils";
|
|
24
|
+
export * from "./gallery/gallery";
|
package/src/network/http.ts
CHANGED
|
@@ -33,6 +33,9 @@ export interface HttpDownloadResponse {
|
|
|
33
33
|
savePath: string;
|
|
34
34
|
fileSize: number;
|
|
35
35
|
saveToGallerySuccess?: boolean;
|
|
36
|
+
galleryUri?: string;
|
|
37
|
+
galleryId?: number;
|
|
38
|
+
galleryType?: string;
|
|
36
39
|
headers: Record<string, string>;
|
|
37
40
|
}
|
|
38
41
|
|
|
@@ -225,6 +228,7 @@ export class Http {
|
|
|
225
228
|
* @param savePath 保存路径
|
|
226
229
|
* @param headers 请求头
|
|
227
230
|
* @param saveToGallery 是否保存到系统相册(仅支持图片和视频文件),默认 false
|
|
231
|
+
* @param displayName 保存到相册时的显示名称(可选,默认使用文件名)
|
|
228
232
|
* @param timeout 超时时间(秒),默认30秒
|
|
229
233
|
* @returns Promise<下载响应>
|
|
230
234
|
*/
|
|
@@ -233,11 +237,12 @@ export class Http {
|
|
|
233
237
|
savePath: string,
|
|
234
238
|
headers?: Record<string, string>,
|
|
235
239
|
saveToGallery?: boolean,
|
|
240
|
+
displayName?: string,
|
|
236
241
|
timeout?: number
|
|
237
242
|
): Promise<HttpDownloadResponse> {
|
|
238
243
|
const response = await this.asyncCall(
|
|
239
244
|
"httpDownload",
|
|
240
|
-
{ url, savePath, headers, saveToGallery },
|
|
245
|
+
{ url, savePath, headers, saveToGallery, displayName },
|
|
241
246
|
timeout
|
|
242
247
|
);
|
|
243
248
|
if (!response.isSuccess()) {
|