mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-31 01:24:37 +02:00
don't allow download of files with size 0
This commit is contained in:
parent
a285fde2e0
commit
97be59f606
@ -17,6 +17,7 @@
|
||||
along with Cockpit Navigator. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ModalPrompt } from "./ModalPrompt.js";
|
||||
import { NavFile } from "./NavFile.js";
|
||||
|
||||
export class NavDownloader {
|
||||
@ -31,20 +32,28 @@ export class NavDownloader {
|
||||
}
|
||||
|
||||
async download() {
|
||||
let query = window.btoa(JSON.stringify({
|
||||
payload: 'fsread1',
|
||||
binary: 'raw',
|
||||
path: this.path,
|
||||
superuser: false,
|
||||
max_read_size: this.read_size,
|
||||
external: {
|
||||
'content-disposition': 'attachment; filename="' + this.filename + '"',
|
||||
'content-type': 'application/x-xz, application/octet-stream'
|
||||
},
|
||||
}));
|
||||
let prefix = (new URL(cockpit.transport.uri('channel/' + cockpit.transport.csrf_token))).pathname;
|
||||
let href = ""
|
||||
if (this.read_size === 0) {
|
||||
new ModalPrompt().alert("Cannot download file with size 0.");
|
||||
return;
|
||||
// TODO: figure this out
|
||||
} else {
|
||||
let query = window.btoa(JSON.stringify({
|
||||
payload: 'fsread1',
|
||||
binary: 'raw',
|
||||
path: this.path,
|
||||
superuser: false,
|
||||
max_read_size: this.read_size,
|
||||
external: {
|
||||
'content-disposition': 'attachment; filename="' + this.filename + '"',
|
||||
'content-type': 'application/x-xz, application/octet-stream'
|
||||
},
|
||||
}));
|
||||
let prefix = (new URL(cockpit.transport.uri('channel/' + cockpit.transport.csrf_token))).pathname;
|
||||
href = prefix + "?" + query;
|
||||
}
|
||||
var a = document.createElement("a");
|
||||
a.href = prefix + "?" + query;
|
||||
a.href = href
|
||||
a.style.display = "none";
|
||||
a.download = this.filename;
|
||||
document.body.appendChild(a);
|
||||
|
Loading…
x
Reference in New Issue
Block a user