1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

69 lines
1.9 KiB
TypeScript
Raw Normal View History

import {Utils} from '../../../../common/Utils';
import {Config} from '../../../../common/config/public/Config';
2021-04-01 21:48:38 +02:00
import {MediaBaseDTO, MediaDTO} from '../../../../common/entities/MediaDTO';
2018-11-04 19:28:32 +01:00
export class MediaIcon {
protected replacementSizeCache: number | boolean = false;
2021-04-01 21:48:38 +02:00
constructor(public media: MediaBaseDTO) {
2018-11-04 19:28:32 +01:00
}
getExtension(): string {
return this.media.name.substr(this.media.name.lastIndexOf('.') + 1);
}
2018-11-04 19:28:32 +01:00
iconLoaded(): void {
2018-11-04 19:28:32 +01:00
this.media.readyIcon = true;
}
isIconAvailable(): boolean {
2018-11-04 19:28:32 +01:00
return this.media.readyIcon;
}
getRelativePath(): string {
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 {
2018-11-04 19:28:32 +01:00
return Utils.concatUrls(Config.Client.urlBase,
'/api/gallery/content/',
this.getRelativePath(), 'icon');
2018-11-04 19:28:32 +01:00
}
getMediaPath(): string {
2018-11-04 19:28:32 +01:00
return Utils.concatUrls(Config.Client.urlBase,
'/api/gallery/content/', this.getRelativePath());
2018-11-04 19:28:32 +01:00
}
getBestFitMediaPath(): string {
2019-12-23 12:09:41 +01:00
return Utils.concatUrls(this.getMediaPath(), '/bestFit');
}
2018-11-04 19:28:32 +01:00
equals(other: MediaDTO | MediaIcon): boolean {
2018-11-04 19:28:32 +01:00
// is gridphoto
if (other instanceof MediaIcon) {
return this.media.directory.path === other.media.directory.path &&
this.media.directory.name === other.media.directory.name && this.media.name === other.media.name;
}
// is media
if (other.directory) {
return this.media.directory.path === other.directory.path &&
this.media.directory.name === other.directory.name && this.media.name === other.name;
}
return false;
}
}