mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 04:36:00 +00:00
Add base64 handling for binary data in filter and grid components
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { arrayToHexString, evalFilterBehaviour, isTypeDateTime } from 'dbgate-tools';
|
import { arrayToHexString, base64ToHex, evalFilterBehaviour, isTypeDateTime } from 'dbgate-tools';
|
||||||
import { format, toDate } from 'date-fns';
|
import { format, toDate } from 'date-fns';
|
||||||
import _isString from 'lodash/isString';
|
import _isString from 'lodash/isString';
|
||||||
import _cloneDeepWith from 'lodash/cloneDeepWith';
|
import _cloneDeepWith from 'lodash/cloneDeepWith';
|
||||||
@@ -24,7 +24,9 @@ export function getFilterValueExpression(value, dataType?) {
|
|||||||
if (value.type == 'Buffer' && Array.isArray(value.data)) {
|
if (value.type == 'Buffer' && Array.isArray(value.data)) {
|
||||||
return '0x' + arrayToHexString(value.data);
|
return '0x' + arrayToHexString(value.data);
|
||||||
}
|
}
|
||||||
|
if (value?.$binary?.base64) {
|
||||||
|
return base64ToHex(value.$binary.base64);
|
||||||
|
}
|
||||||
return `="${value}"`;
|
return `="${value}"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
if (value?.type == 'Buffer' && _.isArray(value?.data)) {
|
if (value?.type == 'Buffer' && _.isArray(value?.data)) {
|
||||||
return 'data:image/png;base64, ' + btoa(String.fromCharCode.apply(null, 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;
|
return null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Error showing picture', err);
|
console.log('Error showing picture', err);
|
||||||
|
|||||||
@@ -361,6 +361,7 @@
|
|||||||
detectSqlFilterBehaviour,
|
detectSqlFilterBehaviour,
|
||||||
stringifyCellValue,
|
stringifyCellValue,
|
||||||
shouldOpenMultilineDialog,
|
shouldOpenMultilineDialog,
|
||||||
|
base64ToHex,
|
||||||
} from 'dbgate-tools';
|
} from 'dbgate-tools';
|
||||||
import { getContext, onDestroy } from 'svelte';
|
import { getContext, onDestroy } from 'svelte';
|
||||||
import _, { map } from 'lodash';
|
import _, { map } from 'lodash';
|
||||||
@@ -758,7 +759,7 @@
|
|||||||
|
|
||||||
export function saveCellToFileEnabled() {
|
export function saveCellToFileEnabled() {
|
||||||
const value = getSelectedExportableCell();
|
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() {
|
export async function saveCellToFile() {
|
||||||
@@ -771,6 +772,8 @@
|
|||||||
fs.promises.writeFile(file, value);
|
fs.promises.writeFile(file, value);
|
||||||
} else if (value?.type == 'Buffer' && _.isArray(value?.data)) {
|
} else if (value?.type == 'Buffer' && _.isArray(value?.data)) {
|
||||||
fs.promises.writeFile(file, window['Buffer'].from(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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { apiCall } from '../utility/api';
|
import { apiCall } from '../utility/api';
|
||||||
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
import ErrorInfo from '../elements/ErrorInfo.svelte';
|
||||||
|
import { base64ToHex } from 'dbgate-tools';
|
||||||
|
|
||||||
export let onConfirm;
|
export let onConfirm;
|
||||||
export let conid;
|
export let conid;
|
||||||
@@ -112,7 +113,7 @@
|
|||||||
{
|
{
|
||||||
fieldName: 'value',
|
fieldName: 'value',
|
||||||
header: '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),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
if (force && value?.type == 'Buffer' && _.isArray(value.data)) {
|
if (force && value?.type == 'Buffer' && _.isArray(value.data)) {
|
||||||
return String.fromCharCode.apply(String, 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;
|
return stringifyCellValue(value, 'gridCellIntent').value;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user