fix urlencoding in the filemanager
This commit is contained in:
parent
5f284dad1d
commit
4fd2af028d
7 changed files with 35 additions and 47 deletions
|
@ -17,7 +17,7 @@ export function megabytesToHuman (mb: number): string {
|
|||
|
||||
export const randomInt = (low: number, high: number) => Math.floor(Math.random() * (high - low) + low);
|
||||
|
||||
export const cleanDirectoryPath = (path: string) => path.replace(/(^#\/*)|(\/(\/*))|(^$)/g, '/');
|
||||
export const cleanDirectoryPath = (path: string) => path.replace(/(\/(\/*))|(^$)/g, '/');
|
||||
|
||||
export const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
||||
|
||||
|
@ -50,3 +50,16 @@ export function fileBitsToString (mode: string, directory: boolean): string {
|
|||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL-encodes the segments of a path.
|
||||
* This allows to use the path as part of a URL while preserving the slashes.
|
||||
* @param path the path to encode
|
||||
*/
|
||||
export function encodePathSegments (path: string): string {
|
||||
return path.split('/').map(s => encodeURIComponent(s)).join('/');
|
||||
}
|
||||
|
||||
export function hashToPath (hash: string): string {
|
||||
return hash.length > 0 ? decodeURIComponent(hash.substr(1)) : '/';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue