mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-31 01:24:37 +02:00
Merge pull request #35 from 45Drives/dev-josh
Fix mangling large files during upload
This commit is contained in:
commit
c42ec10342
@ -1,3 +1,3 @@
|
|||||||
## Cockpit Navigator 0.5.5-2
|
## Cockpit Navigator 0.5.6-1
|
||||||
|
|
||||||
* Fix sed command for packaging EL7.
|
* Fix mangling of large files during upload.
|
@ -3,8 +3,8 @@
|
|||||||
"name": "cockpit-navigator",
|
"name": "cockpit-navigator",
|
||||||
"title": "Cockpit Navigator",
|
"title": "Cockpit Navigator",
|
||||||
"prerelease": false,
|
"prerelease": false,
|
||||||
"version": "0.5.5",
|
"version": "0.5.6",
|
||||||
"buildVersion": "2",
|
"buildVersion": "1",
|
||||||
"author": "Josh Boudreau <jboudreau@45drives.com>",
|
"author": "Josh Boudreau <jboudreau@45drives.com>",
|
||||||
"url": "https://github.com/45Drives/cockpit-navigator",
|
"url": "https://github.com/45Drives/cockpit-navigator",
|
||||||
"category": "utils",
|
"category": "utils",
|
||||||
@ -54,8 +54,8 @@
|
|||||||
],
|
],
|
||||||
"changelog": {
|
"changelog": {
|
||||||
"urgency": "medium",
|
"urgency": "medium",
|
||||||
"version": "0.5.5",
|
"version": "0.5.6",
|
||||||
"buildVersion": "2",
|
"buildVersion": "1",
|
||||||
"ignore": [],
|
"ignore": [],
|
||||||
"date": null,
|
"date": null,
|
||||||
"packager": "Josh Boudreau <jboudreau@45drives.com>",
|
"packager": "Josh Boudreau <jboudreau@45drives.com>",
|
||||||
|
@ -148,13 +148,13 @@ export class FileUpload {
|
|||||||
this.chunk_index++;
|
this.chunk_index++;
|
||||||
this.progress.value = this.chunk_index;
|
this.progress.value = this.chunk_index;
|
||||||
if (this.chunk_index < this.num_chunks)
|
if (this.chunk_index < this.num_chunks)
|
||||||
this.reader.readAsArrayBuffer(this.chunks[this.chunk_index]);
|
this.reader.readAsDataURL(this.chunks[this.chunk_index]);
|
||||||
else {
|
else {
|
||||||
this.done();
|
this.done();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
this.reader.readAsArrayBuffer(this.chunks[0]);
|
this.reader.readAsDataURL(this.chunks[0]);
|
||||||
} catch {
|
} catch {
|
||||||
this.reader.onload = () => {};
|
this.reader.onload = () => {};
|
||||||
if (this.using_webkit) {
|
if (this.using_webkit) {
|
||||||
@ -167,27 +167,12 @@ export class FileUpload {
|
|||||||
this.update_rates_interval = setInterval(this.display_xfr_rate.bind(this), 1000);
|
this.update_rates_interval = setInterval(this.display_xfr_rate.bind(this), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {ArrayBuffer} buffer
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
arrayBufferToBase64(buffer) {
|
|
||||||
let binary = '';
|
|
||||||
let bytes = new Uint8Array(buffer);
|
|
||||||
let len = bytes.byteLength;
|
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
binary += String.fromCharCode(bytes[i]);
|
|
||||||
}
|
|
||||||
return window.btoa(binary);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Event} evt
|
* @param {Event} evt
|
||||||
*/
|
*/
|
||||||
write_to_file(evt) {
|
write_to_file(evt) {
|
||||||
var chunk_b64 = this.arrayBufferToBase64(evt.target.result);
|
var chunk_b64 = evt.target.result.replace(/^data:[^\/]+\/[^;]+;base64,/, "");
|
||||||
const seek = this.chunk_index * this.chunk_size;
|
const seek = this.chunk_index * this.chunk_size;
|
||||||
var obj = {
|
var obj = {
|
||||||
seek: seek,
|
seek: seek,
|
||||||
|
@ -31,34 +31,33 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
def write_chunk(chunk, file):
|
def write_chunk(chunk, fd):
|
||||||
if not file:
|
|
||||||
path = sys.argv[1]
|
|
||||||
parent_path = os.path.dirname(path)
|
|
||||||
try:
|
|
||||||
if not os.path.exists(parent_path):
|
|
||||||
os.makedirs(parent_path, exist_ok=True)
|
|
||||||
elif os.path.isfile(parent_path):
|
|
||||||
print(parent_path + ": exists and is not a directory.")
|
|
||||||
sys.exit(1)
|
|
||||||
file = open(path, "wb")
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
sys.exit(1)
|
|
||||||
seek = chunk["seek"]
|
seek = chunk["seek"]
|
||||||
data = base64.b64decode(chunk["chunk"])
|
data = base64.b64decode(chunk["chunk"])
|
||||||
|
os.lseek(fd, seek, os.SEEK_SET)
|
||||||
|
os.write(fd, data)
|
||||||
|
|
||||||
|
def create_path(path):
|
||||||
try:
|
try:
|
||||||
file.seek(seek)
|
if not os.path.exists(path):
|
||||||
file.write(data)
|
os.makedirs(path, exist_ok=True)
|
||||||
|
elif os.path.isfile(path):
|
||||||
|
print(path + ": exists and is not a directory.")
|
||||||
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
file = None
|
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print("Invalid number of arguments.")
|
print("Invalid number of arguments.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
fd = None
|
||||||
|
path = sys.argv[1]
|
||||||
|
parent_path = os.path.dirname(path)
|
||||||
|
create_path(parent_path)
|
||||||
|
try:
|
||||||
|
fd = os.open(sys.argv[1], os.O_WRONLY | os.O_TRUNC | os.O_CREAT)
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
json_in = input()
|
json_in = input()
|
||||||
@ -66,17 +65,13 @@ def main():
|
|||||||
break
|
break
|
||||||
json_list = json_in.split("\n") # need to split in case writes happen faster than reads
|
json_list = json_in.split("\n") # need to split in case writes happen faster than reads
|
||||||
for json_obj in json_list:
|
for json_obj in json_list:
|
||||||
try:
|
|
||||||
obj_in = json.loads(json_obj)
|
obj_in = json.loads(json_obj)
|
||||||
|
write_chunk(obj_in, fd)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
log = open("/var/log/navigator.log", "w")
|
os.close(fd)
|
||||||
log.write(json_in)
|
|
||||||
log.close()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
write_chunk(obj_in, file)
|
os.close(fd)
|
||||||
if file:
|
|
||||||
file.close()
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -32,6 +32,8 @@ rm -rf %{buildroot}
|
|||||||
/usr/share/cockpit/navigator/*
|
/usr/share/cockpit/navigator/*
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Nov 12 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.6-1
|
||||||
|
- Fix mangling of large files during upload.
|
||||||
* Mon Oct 04 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.5-2
|
* Mon Oct 04 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.5-2
|
||||||
- Fix sed command for packaging EL7.
|
- Fix sed command for packaging EL7.
|
||||||
* Mon Oct 04 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.5-1
|
* Mon Oct 04 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.5-1
|
||||||
|
@ -32,6 +32,8 @@ rm -rf %{buildroot}
|
|||||||
/usr/share/cockpit/navigator/*
|
/usr/share/cockpit/navigator/*
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Nov 12 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.6-1
|
||||||
|
- Fix mangling of large files during upload.
|
||||||
* Mon Oct 04 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.5-2
|
* Mon Oct 04 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.5-2
|
||||||
- Fix sed command for packaging EL7.
|
- Fix sed command for packaging EL7.
|
||||||
* Mon Oct 04 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.5-1
|
* Mon Oct 04 2021 Joshua Boudreau <jboudreau@45drives.com> 0.5.5-1
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
cockpit-navigator (0.5.6-1focal) focal; urgency=medium
|
||||||
|
|
||||||
|
* Fix mangling of large files during upload.
|
||||||
|
|
||||||
|
-- Joshua Boudreau <jboudreau@45drives.com> Fri, 12 Nov 2021 08:06:44 -0400
|
||||||
|
|
||||||
cockpit-navigator (0.5.5-2focal) focal; urgency=medium
|
cockpit-navigator (0.5.5-2focal) focal; urgency=medium
|
||||||
|
|
||||||
* Fix sed command for packaging EL7.
|
* Fix sed command for packaging EL7.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user