Skip to content

Commit

Permalink
fix(encoding): added support for emojis in the playlists' and files' …
Browse files Browse the repository at this point in the history
…name

re #10
  • Loading branch information
will-moss committed Oct 27, 2024
1 parent 81cf251 commit 464b199
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ const App = () => {

return copy;
};
// Source : https://stackoverflow.com/questions/7449588/why-does-decodeuricomponent-lock-up-my-browser
const _decodeURIComponentSafe = (s) => {
if (!s) return s;
return decodeURIComponent(s.replace(/%(?![0-9a-fA-F]+)/g, "%25"));
};

// Members - Form & Auth management
const [autoconnect, setAutoconnect] = useState(false);
Expand Down Expand Up @@ -290,7 +295,7 @@ const App = () => {

// Method - Recursive video retrieval
const _retrieveVideosRecursively = (path = "") => {
return fetch(_toAuthenticatedUrl(`${window.PUBLIC_URL}/media/${path}`), {
return fetch(_toAuthenticatedUrl(`${window.PUBLIC_URL}/media/${encodeURIComponent(path)}`), {
method: "GET",
cache: "no-cache",
headers: _makeHTTPHeaders(),
Expand Down Expand Up @@ -345,7 +350,7 @@ const App = () => {
.slice(0, -1)
.join(""),
extension: current.url.split(".").at(-1).toLowerCase(),
playlist: decodeURI(current.url).replace(current.name, ""),
playlist: current.url.replace(encodeURIComponent(current.name), ""),
metadataURL: false,
};

Expand All @@ -361,13 +366,12 @@ const App = () => {

_videoFiles = Object.values(_videoFiles);
_storeVideos(_videoFiles);
console.log(_videoFiles);

// Playlist extraction
setPlaylists([...new Set(_videoFiles.map((v) => v.playlist).filter((p) => p))].sort());

// Filter video files retrieved according to the current url-defined playlist
let currentPlaylist = decodeURIComponent(window.location.pathname.substring(1));
let currentPlaylist = _decodeURIComponentSafe(window.location.pathname.substring(1));
if (currentPlaylist && currentPlaylist.substr(-1) !== "/") currentPlaylist += "/";
_videoFiles = _videoFiles.filter((v) => v.playlist === currentPlaylist);

Expand Down

0 comments on commit 464b199

Please sign in to comment.