Webengineering-Filemanager/Frontend/static/js/dropdown.js

30 lines
981 B
JavaScript
Raw Normal View History

function download_file(path, mimetype) {
let file = path.split('/');
let filename = file[file.length - 1];
httpGetAsync(base_url + path, null, function (response, code) {
if (code === 200) {
let element = document.createElement('a');
element.setAttribute('href', 'data:' + mimetype + ',' + encodeURIComponent(response));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
} else {
create_error_view("Error " + response);
}
});
}
function remove_file(filename) {
httpDeleteAsync(base_url + filename, null, function (response, code) {
if (code === 200) {
create_success_view("Successfully deleted.");
path_changed();
} else {
create_error_view(response);
}
});
}