diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-11-15 16:15:07 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-11-15 16:15:07 -0600 |
| commit | 1e97cd3e0d2e7e92ad3c894d47919bf8d4bfaa97 (patch) | |
| tree | f9384362022b77f306a59ef5f5dbd2a3afc87f5c /src/web | |
| parent | 08816f9b7c8802bc9f78cf8a0cf8fc49b435628b (diff) | |
| download | slskd-1e97cd3e0d2e7e92ad3c894d47919bf8d4bfaa97.tar.gz | |
use UTF8 when calling files APIs
Diffstat (limited to 'src/web')
| -rw-r--r-- | src/web/src/lib/files.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/web/src/lib/files.js b/src/web/src/lib/files.js index 99a82b2c..cbd0bd3c 100644 --- a/src/web/src/lib/files.js +++ b/src/web/src/lib/files.js @@ -1,21 +1,30 @@ import api from './api'; +// paths may contain any unicode character, so they are encoded as UTF-8 before base64 (btoa only accepts Latin-1), +// and the result is URL-encoded because base64 may contain '/', which would otherwise split the route + export const list = async ({ root, subdirectory = '' }) => { const response = ( - await api.get(`/files/${root}/directories/${btoa(subdirectory)}`) + await api.get( + `/files/${root}/directories/${encodeURIComponent(btoa(String.fromCodePoint(...new TextEncoder().encode(subdirectory))))}`, + ) ).data; return response; }; export const deleteDirectory = async ({ root, path }) => { - const response = await api.delete(`/files/${root}/directories/${btoa(path)}`); + const response = await api.delete( + `/files/${root}/directories/${encodeURIComponent(btoa(String.fromCodePoint(...new TextEncoder().encode(path))))}`, + ); return response; }; export const deleteFile = async ({ root, path }) => { - const response = await api.delete(`/files/${root}/files/${btoa(path)}`); + const response = await api.delete( + `/files/${root}/files/${encodeURIComponent(btoa(String.fromCodePoint(...new TextEncoder().encode(path))))}`, + ); return response; }; |
