Add base64 handling for binary data in filter and grid components

This commit is contained in:
Stela Augustinova
2025-10-29 15:08:57 +01:00
parent aa7fb74312
commit 417334d140
5 changed files with 16 additions and 4 deletions

View File

@@ -10,6 +10,9 @@
if (value?.type == 'Buffer' && _.isArray(value?.data)) {
return 'data:image/png;base64, ' + btoa(String.fromCharCode.apply(null, value?.data));
}
if (value?.$binary?.base64) {
return 'data:image/png;base64, ' + value.$binary.base64;
}
return null;
} catch (err) {
console.log('Error showing picture', err);

View File

@@ -361,6 +361,7 @@
detectSqlFilterBehaviour,
stringifyCellValue,
shouldOpenMultilineDialog,
base64ToHex,
} from 'dbgate-tools';
import { getContext, onDestroy } from 'svelte';
import _, { map } from 'lodash';
@@ -758,7 +759,7 @@
export function saveCellToFileEnabled() {
const value = getSelectedExportableCell();
return _.isString(value) || (value?.type == 'Buffer' && _.isArray(value?.data));
return _.isString(value) || (value?.type == 'Buffer' && _.isArray(value?.data)) || (value?.$binary?.base64);
}
export async function saveCellToFile() {
@@ -771,6 +772,8 @@
fs.promises.writeFile(file, value);
} else if (value?.type == 'Buffer' && _.isArray(value?.data)) {
fs.promises.writeFile(file, window['Buffer'].from(value.data));
} else if (value?.$binary?.base64) {
fs.promises.writeFile(file, window['Buffer'].from(value.$binary.base64, 'base64'));
}
}
}

View File

@@ -15,6 +15,7 @@
import _ from 'lodash';
import { apiCall } from '../utility/api';
import ErrorInfo from '../elements/ErrorInfo.svelte';
import { base64ToHex } from 'dbgate-tools';
export let onConfirm;
export let conid;
@@ -112,7 +113,7 @@
{
fieldName: 'value',
header: 'Value',
formatter: row => (row.value == null ? '(NULL)' : row.value),
formatter: row => (row.value == null ? '(NULL)' : row.value?.$binary?.base64 ? base64ToHex(row.value.$binary.base64) : row.value),
},
]}
>

View File

@@ -15,6 +15,9 @@
if (force && value?.type == 'Buffer' && _.isArray(value.data)) {
return String.fromCharCode.apply(String, value.data);
}
else if (force && value?.$binary?.base64) {
return atob(value.$binary.base64);
}
return stringifyCellValue(value, 'gridCellIntent').value;
}
</script>