3 Commits

Author SHA1 Message Date
245b76e04e Merge pull request 'fix: frontend: Correctly escape filenames in URL parameters' (#69) from fix-url-filenames into main
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 4m51s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Successful in 10s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 10s
Reviewed-on: #69
2026-01-27 18:39:32 +00:00
fa4d8debd0 fix: webserver: catch and report exceptions from open and mkdir, too
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 4m49s
Check code formatting / Check-C-Format (push) Successful in 8s
Check code formatting / Check-Python-Flake8 (push) Successful in 9s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 4s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 10s
Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
2026-01-27 19:11:47 +01:00
0a20b70478 fix: frontend: Correctly escape filenames in URL parameters
All checks were successful
Build RPi Pico firmware image / Build-Firmware (push) Successful in 4m56s
Check code formatting / Check-C-Format (push) Successful in 8s
Check code formatting / Check-Python-Flake8 (push) Successful in 10s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 9s
Run pytests / Check-Pytest (push) Successful in 11s
Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
2026-01-27 18:15:15 +01:00
2 changed files with 11 additions and 8 deletions

View File

@@ -938,7 +938,7 @@
} }
} }
}; };
xhr.open("POST", `/api/v1/audiofiles?type=file&location=${location}`); xhr.open("POST", `/api/v1/audiofiles?type=file&location=${encodeURIComponent(location)}`);
xhr.overrideMimeType("audio/mpeg"); xhr.overrideMimeType("audio/mpeg");
xhr.send(files[0]); xhr.send(files[0]);
} }
@@ -956,7 +956,7 @@
const location = selectedNodes.length === 1 const location = selectedNodes.length === 1
? selectedNodes[0].getAttribute('data-path') + '/' + name.value ? selectedNodes[0].getAttribute('data-path') + '/' + name.value
: '/' + name.value; : '/' + name.value;
const saveRes = await fetch(`/api/v1/audiofiles?type=directory&location=${location}`, const saveRes = await fetch(`/api/v1/audiofiles?type=directory&location=${encodeURIComponent(location)}`,
{method: 'POST'}); {method: 'POST'});
// Reload file list from device // Reload file list from device
onShow('refresh'); onShow('refresh');
@@ -973,7 +973,7 @@
items.sort(); items.sort();
items.reverse(); items.reverse();
for (const item of items) { for (const item of items) {
const saveRes = await fetch(`/api/v1/audiofiles?location=${item}`, const saveRes = await fetch(`/api/v1/audiofiles?location=${encodeURIComponent(item)}`,
{method: 'DELETE'}); {method: 'DELETE'});
if (!saveRes.ok) { if (!saveRes.ok) {
alert(`Failed to delete item ${item}: ${await saveRes.text()}`); alert(`Failed to delete item ${item}: ${await saveRes.text()}`);

View File

@@ -235,16 +235,19 @@ async def audiofile_upload(request):
if type_ == 'directory': if type_ == 'directory':
if length != 0: if length != 0:
return 'directory request may not have content', 400 return 'directory request may not have content', 400
os.mkdir(path)
return '', 204
with open(path, 'wb') as newfile:
try: try:
os.mkdir(path)
except OSError as ex:
return f'error creating directory: {ex}', 500
return '', 204
try:
with open(path, 'wb') as newfile:
if length > Request.max_body_length: if length > Request.max_body_length:
bytes_copied = await stream_to_file(request.stream, newfile, length) bytes_copied = await stream_to_file(request.stream, newfile, length)
else: else:
bytes_copied = newfile.write(request.body) bytes_copied = newfile.write(request.body)
except OSError as ex: except OSError as ex:
return f'error writing data to file: {ex}', 500 return f'error writing data to file: {ex}', 500
if bytes_copied == length: if bytes_copied == length:
return '', 204 return '', 204
else: else: