Files
cloudbeaver/webapp/packages/core-browser/src/selectFiles.ts
T
sergeyteleshevandEvgenia Bezborodova 9e3e4322a3 Cb 4178 te cloud storage improvements (#2532)
* CB-4178 chore: makes tree nodes names visible in react dev tools

* CB-4178 adds validation for loading files in cloud storage

* CB-4178 pr fixes

* CB-4178 pr fixes

* CB-4178 code cleanup

* CB-4178 selectFiles can return empty array

---------

Co-authored-by: Evgenia Bezborodova <139753579+EvgeniaBzzz@users.noreply.github.com>
2024-04-09 16:35:13 +03:00

42 lines
950 B
TypeScript

/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
export function selectFiles(callback: (files: File[]) => any, multiple?: boolean): void {
let removed = false;
const input = document.createElement('input');
input.type = 'file';
if (multiple) {
input.multiple = true;
}
input.onchange = () => {
callback(input.files?.length ? Array.from(input.files) : []);
removed = true;
input.remove();
};
input.style.position = 'fixed';
input.style.top = '-100px';
input.style.left = '-100px';
input.style.opacity = '0';
input.style.pointerEvents = 'none';
input.style.zIndex = '-1';
document.body.append(input);
input.click();
setTimeout(
() => {
if (!removed) {
input.remove();
}
},
30 * 60 * 1000,
);
}