don't allow download of files with size 0

This commit is contained in:
joshuaboud 2021-12-15 14:57:20 -04:00
parent a285fde2e0
commit 97be59f606
No known key found for this signature in database
GPG Key ID: 17EFB59E2A8BF50E

View File

@ -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,6 +32,12 @@ export class NavDownloader {
}
async download() {
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',
@ -43,8 +50,10 @@ export class NavDownloader {
},
}));
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);