bizydraft 0.2.49__py3-none-any.whl → 0.2.87__py3-none-any.whl
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.
Potentially problematic release.
This version of bizydraft might be problematic. Click here for more details.
- bizydraft/env.py +3 -0
- bizydraft/hijack_nodes.py +60 -42
- bizydraft/hijack_routes.py +36 -3
- bizydraft/oss_utils.py +231 -2
- bizydraft/patch_handlers.py +197 -8
- bizydraft/static/js/aiAppHandler.js +460 -425
- bizydraft/static/js/clipspaceToOss.js +386 -0
- bizydraft/static/js/disableComfyWebSocket.js +64 -0
- bizydraft/static/js/freezeModeHandler.js +425 -404
- bizydraft/static/js/handleStyle.js +128 -36
- bizydraft/static/js/hookLoad/configLoader.js +74 -0
- bizydraft/static/js/hookLoad/media.js +684 -0
- bizydraft/static/js/hookLoad/model.js +322 -0
- bizydraft/static/js/hookLoadMedia.js +196 -0
- bizydraft/static/js/hookLoadModel.js +207 -256
- bizydraft/static/js/main.js +2 -0
- bizydraft/static/js/nodeFocusHandler.js +118 -106
- bizydraft/static/js/nodeParamsFilter.js +91 -89
- bizydraft/static/js/postEvent.js +1207 -967
- bizydraft/static/js/socket.js +55 -50
- bizydraft/static/js/tool.js +71 -63
- bizydraft/static/js/uploadFile.js +49 -41
- bizydraft/static/js/workflow_io.js +193 -0
- {bizydraft-0.2.49.dist-info → bizydraft-0.2.87.dist-info}/METADATA +1 -1
- bizydraft-0.2.87.dist-info/RECORD +34 -0
- bizydraft/static/js/hookLoadImage.js +0 -177
- bizydraft-0.2.49.dist-info/RECORD +0 -28
- {bizydraft-0.2.49.dist-info → bizydraft-0.2.87.dist-info}/WHEEL +0 -0
- {bizydraft-0.2.49.dist-info → bizydraft-0.2.87.dist-info}/top_level.txt +0 -0
bizydraft/static/js/socket.js
CHANGED
|
@@ -1,109 +1,114 @@
|
|
|
1
1
|
export class WebSocketClient {
|
|
2
2
|
constructor(url, protocols) {
|
|
3
|
+
const host = "api.bizyair.cn";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (url.startsWith('ws://') || url.startsWith('wss://')) {
|
|
5
|
+
if (url.startsWith("ws://") || url.startsWith("wss://")) {
|
|
7
6
|
this.url = url;
|
|
8
7
|
} else {
|
|
9
|
-
this.url = `${
|
|
8
|
+
this.url = `${
|
|
9
|
+
location.protocol == "http:" ? "wss" : "wss"
|
|
10
|
+
}://${host}${url}`;
|
|
10
11
|
}
|
|
11
|
-
this.protocols = protocols
|
|
12
|
-
this.reconnectDelay = 1000
|
|
13
|
-
this.maxReconnectDelay = 30000
|
|
14
|
-
this.keepAliveInterval = 10000
|
|
15
|
-
this.ws = null
|
|
16
|
-
this.keepAliveTimer = null
|
|
17
|
-
this.reconnectTimer = null
|
|
18
|
-
|
|
19
|
-
this.connect()
|
|
12
|
+
this.protocols = protocols;
|
|
13
|
+
this.reconnectDelay = 1000;
|
|
14
|
+
this.maxReconnectDelay = 30000;
|
|
15
|
+
this.keepAliveInterval = 10000;
|
|
16
|
+
this.ws = null;
|
|
17
|
+
this.keepAliveTimer = null;
|
|
18
|
+
this.reconnectTimer = null;
|
|
19
|
+
|
|
20
|
+
this.connect();
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
connect() {
|
|
23
|
-
this.ws = new WebSocket(this.url, this.protocols)
|
|
24
|
+
this.ws = new WebSocket(this.url, this.protocols);
|
|
24
25
|
this.ws.onopen = () => {
|
|
25
|
-
this.onOpen()
|
|
26
|
-
}
|
|
26
|
+
this.onOpen();
|
|
27
|
+
};
|
|
27
28
|
|
|
28
29
|
this.ws.onmessage = (message) => {
|
|
29
|
-
if (message.data !==
|
|
30
|
-
this.onMessage(message)
|
|
30
|
+
if (message.data !== "pong") {
|
|
31
|
+
this.onMessage(message);
|
|
31
32
|
}
|
|
32
|
-
}
|
|
33
|
+
};
|
|
33
34
|
|
|
34
35
|
this.ws.onerror = (error) => {
|
|
35
|
-
this.onError(error)
|
|
36
|
-
}
|
|
36
|
+
this.onError(error);
|
|
37
|
+
};
|
|
37
38
|
|
|
38
39
|
this.ws.onclose = () => {
|
|
39
|
-
console.warn(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
console.warn(
|
|
41
|
+
"The WebSocket connection has been closed and is ready to be reconnected"
|
|
42
|
+
);
|
|
43
|
+
this.onClose();
|
|
44
|
+
this.scheduleReconnect();
|
|
45
|
+
};
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
startKeepAlive() {
|
|
46
|
-
if (this.keepAliveTimer) return
|
|
49
|
+
if (this.keepAliveTimer) return;
|
|
47
50
|
|
|
48
51
|
this.keepAliveTimer = setInterval(() => {
|
|
49
52
|
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
50
|
-
this.ws.send(
|
|
53
|
+
this.ws.send("ping");
|
|
51
54
|
}
|
|
52
|
-
}, this.keepAliveInterval)
|
|
55
|
+
}, this.keepAliveInterval);
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
stopKeepAlive() {
|
|
56
59
|
if (this.keepAliveTimer) {
|
|
57
|
-
clearInterval(this.keepAliveTimer)
|
|
58
|
-
this.keepAliveTimer = null
|
|
60
|
+
clearInterval(this.keepAliveTimer);
|
|
61
|
+
this.keepAliveTimer = null;
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
scheduleReconnect() {
|
|
63
|
-
if (this.reconnectTimer) return
|
|
66
|
+
if (this.reconnectTimer) return;
|
|
64
67
|
|
|
65
68
|
this.reconnectTimer = setTimeout(() => {
|
|
66
|
-
console.log(`Attempt to reconnect...`)
|
|
67
|
-
this.connect()
|
|
68
|
-
this.reconnectTimer = null
|
|
69
|
-
|
|
70
|
-
this.reconnectDelay = Math.min(
|
|
71
|
-
|
|
69
|
+
console.log(`Attempt to reconnect...`);
|
|
70
|
+
this.connect();
|
|
71
|
+
this.reconnectTimer = null;
|
|
72
|
+
|
|
73
|
+
this.reconnectDelay = Math.min(
|
|
74
|
+
this.reconnectDelay * 2,
|
|
75
|
+
this.maxReconnectDelay
|
|
76
|
+
);
|
|
77
|
+
}, this.reconnectDelay);
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
onOpen() {
|
|
75
|
-
this.reconnectDelay = 2000
|
|
76
|
-
this.startKeepAlive()
|
|
81
|
+
this.reconnectDelay = 2000;
|
|
82
|
+
this.startKeepAlive();
|
|
77
83
|
}
|
|
78
84
|
|
|
79
|
-
|
|
80
85
|
onError(error) {
|
|
81
|
-
console.error(
|
|
86
|
+
console.error("WebSocket Error: ", error);
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
onClose() {
|
|
85
|
-
this.stopKeepAlive()
|
|
90
|
+
this.stopKeepAlive();
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
close() {
|
|
89
94
|
if (this.ws) {
|
|
90
|
-
this.ws.close()
|
|
95
|
+
this.ws.close();
|
|
91
96
|
}
|
|
92
|
-
this.stopKeepAlive()
|
|
97
|
+
this.stopKeepAlive();
|
|
93
98
|
if (this.reconnectTimer) {
|
|
94
|
-
clearTimeout(this.reconnectTimer)
|
|
95
|
-
this.reconnectTimer = null
|
|
99
|
+
clearTimeout(this.reconnectTimer);
|
|
100
|
+
this.reconnectTimer = null;
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
on(event, callback) {
|
|
100
|
-
if (event ===
|
|
105
|
+
if (event === "message") {
|
|
101
106
|
this.onMessage = callback;
|
|
102
|
-
} else if (event ===
|
|
107
|
+
} else if (event === "open") {
|
|
103
108
|
this.onOpen = callback;
|
|
104
|
-
} else if (event ===
|
|
109
|
+
} else if (event === "error") {
|
|
105
110
|
this.onError = callback;
|
|
106
|
-
} else if (event ===
|
|
111
|
+
} else if (event === "close") {
|
|
107
112
|
this.onClose = callback;
|
|
108
113
|
}
|
|
109
114
|
return this;
|
bizydraft/static/js/tool.js
CHANGED
|
@@ -1,60 +1,64 @@
|
|
|
1
1
|
const loadNodeList = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
"LoadImage",
|
|
3
|
+
"LoadImageMask",
|
|
4
|
+
"LoadAudio",
|
|
5
|
+
"LoadVideo",
|
|
6
|
+
"Load3D",
|
|
7
|
+
"VHS_LoadVideo",
|
|
8
|
+
"VHS_LoadAudioUpload",
|
|
9
|
+
];
|
|
9
10
|
const extMap = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
LoadImage: ".png,.jpg,.jpeg,.webp,.gif,.svg,.ico,.bmp,.tiff,.tif,.heic,.heif",
|
|
12
|
+
LoadImageMask:
|
|
13
|
+
".png,.jpg,.jpeg,.webp,.gif,.svg,.ico,.bmp,.tiff,.tif,.heic,.heif",
|
|
14
|
+
LoadAudio: ".mp3,.wav,.ogg,.m4a,.aac,.flac,.wma,.m4r",
|
|
15
|
+
LoadVideo: ".mp4,.mov,.avi,.mkv,.webm,.flv,.wmv,.m4v",
|
|
16
|
+
Load3D: ".glb,.gltf,.fbx,.obj,.dae,.ply,.stl",
|
|
17
|
+
VHS_LoadAudioUpload: ".mp3,.wav,.ogg,.m4a,.aac,.flac,.wma,.m4r",
|
|
18
|
+
VHS_LoadVideo: ".mp4,.mov,.avi,.mkv,.webm,.flv,.wmv,.m4v",
|
|
19
|
+
};
|
|
18
20
|
export function getCookie(name) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const cookies = document.cookie.split(";");
|
|
22
|
+
for (let cookie of cookies) {
|
|
23
|
+
const [key, value] = cookie.trim().split("=");
|
|
24
|
+
if (key === name) {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
23
29
|
}
|
|
24
30
|
export const hideWidget = (node, widget_name) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
const widget = node.widgets.find((widget) => widget.name === widget_name);
|
|
32
|
+
if (!widget) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const originalComputeSize = widget.computeSize;
|
|
36
|
+
const originalType = widget.type;
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
38
|
+
widget.computeSize = () => [0, -4];
|
|
39
|
+
widget.type = "hidden";
|
|
40
|
+
widget.hidden = true;
|
|
41
|
+
widget.options = widget.options || {};
|
|
42
|
+
widget.show = () => {
|
|
43
|
+
widget.computeSize = originalComputeSize;
|
|
44
|
+
widget.type = originalType;
|
|
45
|
+
widget.height = undefined;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
42
48
|
export const computeIsLoadNode = (nodeName) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
49
|
+
return loadNodeList.includes(nodeName);
|
|
50
|
+
};
|
|
46
51
|
export const computeExt = (nodeName) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
52
|
+
return extMap[nodeName] || "";
|
|
53
|
+
};
|
|
50
54
|
/**
|
|
51
55
|
* 判断节点名是否为模型加载类(不包含 bizyair)
|
|
52
56
|
* @param {string} nodeName
|
|
53
57
|
* @returns {boolean}
|
|
54
58
|
*/
|
|
55
59
|
function isModelLoaderType(nodeName) {
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
const regex = /^(\w+).*Loader.*/i;
|
|
61
|
+
return regex.test(nodeName);
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
/**
|
|
@@ -63,25 +67,29 @@ function isModelLoaderType(nodeName) {
|
|
|
63
67
|
* @returns {Object} 处理后的新对象
|
|
64
68
|
*/
|
|
65
69
|
export function processGraphOutput(output) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
const newOutput = JSON.parse(JSON.stringify(output));
|
|
71
|
+
for (const key in newOutput) {
|
|
72
|
+
const node = newOutput[key];
|
|
73
|
+
// 1. 如果 class_type 在 loadNodeList 里,删除 inputs.image_name
|
|
74
|
+
if (
|
|
75
|
+
loadNodeList.includes(node.class_type) &&
|
|
76
|
+
node.inputs &&
|
|
77
|
+
node.inputs.image_name !== undefined
|
|
78
|
+
) {
|
|
79
|
+
delete node.inputs.image_name;
|
|
80
|
+
}
|
|
81
|
+
if (isModelLoaderType(node.class_type)) {
|
|
82
|
+
delete newOutput[key];
|
|
83
|
+
}
|
|
84
|
+
// 2. 如果 class_type 满足 Loader 正则且不包含 bizyair,删除 inputs.model_version_id
|
|
85
|
+
if (isModelLoaderType(node.class_type) && node.inputs) {
|
|
86
|
+
if (node.inputs.model_version_id !== undefined) {
|
|
87
|
+
delete node.inputs.model_version_id;
|
|
88
|
+
}
|
|
89
|
+
if (node.inputs.ckpt_name !== undefined) {
|
|
90
|
+
delete node.inputs.ckpt_name;
|
|
91
|
+
}
|
|
85
92
|
}
|
|
86
|
-
|
|
93
|
+
}
|
|
94
|
+
return newOutput;
|
|
87
95
|
}
|
|
@@ -1,33 +1,39 @@
|
|
|
1
|
-
import { getCookie } from
|
|
1
|
+
import { getCookie } from "./tool.js";
|
|
2
2
|
export async function fileToOss(file) {
|
|
3
3
|
try {
|
|
4
|
-
|
|
5
4
|
// 检查token是否存在
|
|
6
|
-
const apiHost =
|
|
5
|
+
const apiHost = "https://bizyair.cn/api";
|
|
7
6
|
// const apiHost = 'http://localhost:3000/api'
|
|
8
|
-
const authToken = getCookie(
|
|
7
|
+
const authToken = getCookie("bizy_token");
|
|
9
8
|
// console.log(authToken)
|
|
10
9
|
if (!authToken) {
|
|
11
|
-
throw new Error(
|
|
10
|
+
throw new Error("未找到认证Token,请先登录");
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
// 获取上传凭证
|
|
15
|
-
const uploadToken = await fetch(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const uploadToken = await fetch(
|
|
15
|
+
`${apiHost}/special/community/upload_token?file_name=${encodeURIComponent(
|
|
16
|
+
file.name
|
|
17
|
+
)}&file_type=inputs`,
|
|
18
|
+
{
|
|
19
|
+
method: "GET",
|
|
20
|
+
headers: {
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
Authorization: `Bearer ${authToken}`,
|
|
23
|
+
},
|
|
20
24
|
}
|
|
21
|
-
|
|
25
|
+
);
|
|
22
26
|
|
|
23
27
|
// 检查响应状态
|
|
24
28
|
if (!uploadToken.ok) {
|
|
25
29
|
const errorText = await uploadToken.text();
|
|
26
|
-
console.error(
|
|
27
|
-
throw new Error(
|
|
30
|
+
console.error("获取上传凭证失败:", uploadToken.status, errorText);
|
|
31
|
+
throw new Error(
|
|
32
|
+
`获取上传凭证失败: ${uploadToken.status} ${uploadToken.statusText}`
|
|
33
|
+
);
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
const {data} = await uploadToken.json();
|
|
36
|
+
const { data } = await uploadToken.json();
|
|
31
37
|
// console.log('上传凭证响应:', data);
|
|
32
38
|
|
|
33
39
|
// 使用STS凭证上传
|
|
@@ -37,7 +43,7 @@ export async function fileToOss(file) {
|
|
|
37
43
|
securityToken: data.data.file.security_token,
|
|
38
44
|
bucket: data.data.storage.bucket,
|
|
39
45
|
region: data.data.storage.region,
|
|
40
|
-
objectKey: data.data.file.object_key
|
|
46
|
+
objectKey: data.data.file.object_key,
|
|
41
47
|
};
|
|
42
48
|
|
|
43
49
|
// console.log('OSS配置:', ossConfig);
|
|
@@ -53,10 +59,10 @@ export async function fileToOss(file) {
|
|
|
53
59
|
expiration: expiration.toISOString(),
|
|
54
60
|
conditions: [
|
|
55
61
|
// 文件大小限制
|
|
56
|
-
[
|
|
62
|
+
["content-length-range", 0, 1048576000], // 最大1000MB
|
|
57
63
|
// 指定允许的文件名前缀
|
|
58
|
-
[
|
|
59
|
-
]
|
|
64
|
+
["starts-with", "$key", ossConfig.objectKey.split("/")[0]],
|
|
65
|
+
],
|
|
60
66
|
};
|
|
61
67
|
|
|
62
68
|
// Policy Base64编码
|
|
@@ -64,23 +70,23 @@ export async function fileToOss(file) {
|
|
|
64
70
|
// console.log('Policy:', policy);
|
|
65
71
|
|
|
66
72
|
// 构建表单字段
|
|
67
|
-
formData.append(
|
|
68
|
-
formData.append(
|
|
69
|
-
formData.append(
|
|
70
|
-
formData.append(
|
|
73
|
+
formData.append("key", ossConfig.objectKey);
|
|
74
|
+
formData.append("OSSAccessKeyId", ossConfig.accessKeyId);
|
|
75
|
+
formData.append("policy", policy);
|
|
76
|
+
formData.append("success_action_status", "200");
|
|
71
77
|
|
|
72
78
|
// 如果有临时token,需要添加
|
|
73
79
|
if (ossConfig.securityToken) {
|
|
74
|
-
formData.append(
|
|
80
|
+
formData.append("x-oss-security-token", ossConfig.securityToken);
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
// 计算签名 - 阿里云官方要求使用HMAC-SHA1
|
|
78
84
|
const signature = await hmacSha1(policy, ossConfig.accessKeySecret);
|
|
79
85
|
// console.log('计算的签名:', signature);
|
|
80
|
-
formData.append(
|
|
86
|
+
formData.append("signature", signature);
|
|
81
87
|
|
|
82
88
|
// 最后添加文件内容
|
|
83
|
-
formData.append(
|
|
89
|
+
formData.append("file", file);
|
|
84
90
|
|
|
85
91
|
// OSS服务端点
|
|
86
92
|
const host = `https://${ossConfig.bucket}.${ossConfig.region}.aliyuncs.com`;
|
|
@@ -88,15 +94,17 @@ export async function fileToOss(file) {
|
|
|
88
94
|
|
|
89
95
|
// 开始上传
|
|
90
96
|
const uploadResponse = await fetch(host, {
|
|
91
|
-
method:
|
|
92
|
-
body: formData
|
|
97
|
+
method: "POST",
|
|
98
|
+
body: formData,
|
|
93
99
|
});
|
|
94
100
|
|
|
95
101
|
// 检查响应
|
|
96
102
|
if (!uploadResponse.ok) {
|
|
97
103
|
const errorText = await uploadResponse.text();
|
|
98
|
-
console.error(
|
|
99
|
-
throw new Error(
|
|
104
|
+
console.error("上传失败:", uploadResponse.status, errorText);
|
|
105
|
+
throw new Error(
|
|
106
|
+
`上传失败: ${uploadResponse.status} ${uploadResponse.statusText}`
|
|
107
|
+
);
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
// 构建公开访问URL
|
|
@@ -104,23 +112,23 @@ export async function fileToOss(file) {
|
|
|
104
112
|
|
|
105
113
|
// 提交资源
|
|
106
114
|
await fetch(`${apiHost}/special/community/commit_input_resource`, {
|
|
107
|
-
method:
|
|
115
|
+
method: "POST",
|
|
108
116
|
headers: {
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
"Content-Type": "application/json",
|
|
118
|
+
Authorization: `Bearer ${authToken}`,
|
|
111
119
|
},
|
|
112
120
|
body: JSON.stringify({
|
|
113
121
|
object_key: data.data.file.object_key,
|
|
114
122
|
name: file.name,
|
|
115
|
-
})
|
|
116
|
-
})
|
|
123
|
+
}),
|
|
124
|
+
});
|
|
117
125
|
return {
|
|
118
126
|
url: fileUrl,
|
|
119
127
|
ossTokenFile: data.data.file,
|
|
120
|
-
ossTokenStorage: data.data.storage
|
|
128
|
+
ossTokenStorage: data.data.storage,
|
|
121
129
|
};
|
|
122
130
|
} catch (error) {
|
|
123
|
-
console.error(
|
|
131
|
+
console.error("文件上传到OSS失败:", error);
|
|
124
132
|
|
|
125
133
|
throw error;
|
|
126
134
|
}
|
|
@@ -135,16 +143,16 @@ async function hmacSha1(message, key) {
|
|
|
135
143
|
|
|
136
144
|
// 导入密钥
|
|
137
145
|
const cryptoKey = await window.crypto.subtle.importKey(
|
|
138
|
-
|
|
146
|
+
"raw",
|
|
139
147
|
keyData,
|
|
140
|
-
{ name:
|
|
148
|
+
{ name: "HMAC", hash: "SHA-1" },
|
|
141
149
|
false,
|
|
142
|
-
[
|
|
150
|
+
["sign"]
|
|
143
151
|
);
|
|
144
152
|
|
|
145
153
|
// 计算签名
|
|
146
154
|
const signature = await window.crypto.subtle.sign(
|
|
147
|
-
|
|
155
|
+
"HMAC",
|
|
148
156
|
cryptoKey,
|
|
149
157
|
messageData
|
|
150
158
|
);
|
|
@@ -157,7 +165,7 @@ async function hmacSha1(message, key) {
|
|
|
157
165
|
// 将ArrayBuffer转换为Base64字符串
|
|
158
166
|
function arrayBufferToBase64(buffer) {
|
|
159
167
|
const bytes = new Uint8Array(buffer);
|
|
160
|
-
let binary =
|
|
168
|
+
let binary = "";
|
|
161
169
|
for (let i = 0; i < bytes.byteLength; i++) {
|
|
162
170
|
binary += String.fromCharCode(bytes[i]);
|
|
163
171
|
}
|