1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-10 11:10:35 +02:00

Fixing issue with filenames containing # and % fixes #276 and fixes #272

This commit is contained in:
Patrik J. Braun 2021-05-04 22:43:19 +02:00
parent 0c2a21145f
commit a8d636776b
4 changed files with 15 additions and 11 deletions

View File

@ -98,7 +98,7 @@ export class RenderingMWs {
delete (err.details); // do not send back error object to the client side
// hide error details for non developers
if (!(req.session.user && req.session.user.role >= UserRoles.Developer)) {
if (!(req.session && req.session.user && req.session.user.role >= UserRoles.Developer)) {
delete (err.detailsStr);
}
}

View File

@ -106,7 +106,7 @@ export class Utils {
.replace(new RegExp('/+', 'g'), '/');
}
static concatUrls(...args: Array<string>): string {
static concatUrls(...args: string[]): string {
let url = '';
for (const item of args) {
if (item === '' || typeof item === 'undefined') {

View File

@ -1,7 +1,7 @@
import {Utils} from '../../../../common/Utils';
import {MediaIcon} from './MediaIcon';
import {Config} from '../../../../common/config/public/Config';
import {MediaBaseDTO, MediaDTO, MediaDTOUtils} from '../../../../common/entities/MediaDTO';
import {MediaBaseDTO, MediaDTOUtils} from '../../../../common/entities/MediaDTO';
export class Media extends MediaIcon {
@ -54,8 +54,7 @@ export class Media extends MediaIcon {
getReplacementThumbnailPath(): string {
const size = this.getReplacementThumbnailSize();
return Utils.concatUrls(Config.Client.urlBase,
'/api/gallery/content/',
this.media.directory.path, this.media.directory.name, this.media.name, 'thumbnail', size.toString());
'/api/gallery/content/', this.getRelativePath(), 'thumbnail', size.toString());
}
@ -66,8 +65,7 @@ export class Media extends MediaIcon {
getThumbnailPath(): string {
const size = this.getThumbnailSize();
return Utils.concatUrls(Config.Client.urlBase,
'/api/gallery/content/',
this.media.directory.path, this.media.directory.name, this.media.name, 'thumbnail', size.toString());
'/api/gallery/content/', this.getRelativePath(), 'thumbnail', size.toString());
}

View File

@ -24,19 +24,25 @@ export class MediaIcon {
}
getRelativePath(): string {
return Utils.concatUrls(this.media.directory.path, this.media.directory.name, this.media.name);
return Utils.concatUrls(this.media.directory.path,
this.media.directory.name,
this.media.name)
// do not escape all urls with encodeURIComponent because that make the URL ugly and not needed
// do not escape before concatUrls as that would make prevent optimizations
.replace(new RegExp('%', 'g'), '%25') // order important
.replace(new RegExp('#', 'g'), '%23')
.replace(new RegExp('\\$', 'g'), '%24');
}
getIconPath(): string {
return Utils.concatUrls(Config.Client.urlBase,
'/api/gallery/content/',
this.media.directory.path, this.media.directory.name, this.media.name, 'icon');
this.getRelativePath(), 'icon');
}
getMediaPath(): string {
return Utils.concatUrls(Config.Client.urlBase,
'/api/gallery/content/',
this.media.directory.path, this.media.directory.name, this.media.name);
'/api/gallery/content/', this.getRelativePath());
}
getBestFitMediaPath(): string {