Skip to content

Commit 3520a0e

Browse files
committed
feat: Replace character compression algorithm to support Chinese and special characters
1 parent d68ea71 commit 3520a0e

1 file changed

Lines changed: 6 additions & 56 deletions

File tree

webapp/packages/plugin-data-viewer/src/TableViewer/TableError.tsx

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Licensed under the Apache License, Version 2.0.
66
* you may not use this file except in compliance with the License.
77
*/
8+
import { compressToEncodedURIComponent } from 'lz-string';
89
import { observable } from 'mobx';
910
import { observer } from 'mobx-react-lite';
1011
import styled, { css, use } from 'reshadow';
@@ -131,61 +132,6 @@ export const TableError = observer<Props>(function TableError({ model, loading,
131132
const errorHidden = errorInfo.error === null;
132133
const quote = internalServerError?.errorType === ServerErrorType.QUOTE_EXCEEDED;
133134

134-
const compress = (input: string) => {
135-
function encodeNumbers(numbers: number[]): string {
136-
// 将数字转换为二进制字符串
137-
const binaryStr = numbers
138-
.map(num => {
139-
let bin = num.toString(2);
140-
while (bin.length < 16) bin = '0' + bin; // 使用 16 位表示每个数字
141-
return bin;
142-
})
143-
.join('');
144-
145-
// 将二进制字符串按 6 位分组并转换为 Base64URL
146-
const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
147-
let result = '';
148-
149-
for (let i = 0; i < binaryStr.length; i += 6) {
150-
let chunk = binaryStr.slice(i, i + 6);
151-
while (chunk.length < 6) chunk += '0'; // 补齐最后一组
152-
result += base64Chars[parseInt(chunk, 2)];
153-
}
154-
155-
return result;
156-
}
157-
158-
const dictionary: { [key: string]: number } = {};
159-
const result: number[] = [];
160-
let dictSize = 256;
161-
162-
// 初始化字典
163-
for (let i = 0; i < 256; i++) {
164-
dictionary[String.fromCharCode(i)] = i;
165-
}
166-
167-
let current = '';
168-
for (let i = 0; i < input.length; i++) {
169-
const char = input.charAt(i);
170-
const combined = current + char;
171-
172-
if (dictionary.hasOwnProperty(combined)) {
173-
current = combined;
174-
} else {
175-
result.push(dictionary[current]);
176-
dictionary[combined] = dictSize++;
177-
current = char;
178-
}
179-
}
180-
181-
if (current !== '') {
182-
result.push(dictionary[current]);
183-
}
184-
185-
// 将数字数组转换为 URL 安全的字符串
186-
return encodeNumbers(result);
187-
};
188-
189135
const onCreateWorkflowNavigate = () => {
190136
const [projectName, instanceName] = connectionSchemaManagerService.currentConnection?.name.split(':') ?? [];
191137
const schema = connectionSchemaManagerService.currentObjectCatalog?.name;
@@ -197,7 +143,11 @@ export const TableError = observer<Props>(function TableError({ model, loading,
197143
sql,
198144
};
199145

200-
window.open(`/transit?from=cloudbeaver&to=create_workflow&project_name=${projectName}&compression_data=${compress(JSON.stringify(data))}`);
146+
window.open(
147+
`/transit?from=cloudbeaver&to=create_workflow&project_name=${projectName}&compression_data=${compressToEncodedURIComponent(
148+
JSON.stringify(data),
149+
)}`,
150+
);
201151
};
202152

203153
let icon = '/icons/error_icon.svg';

0 commit comments

Comments
 (0)