2019-03-03 10:30:12 +01:00
|
|
|
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
|
|
|
|
|
|
|
}
|
2018-11-25 15:22:07 +01:00
|
|
|
|
|
|
|
getExtension(): string {
|
|
|
|
return this.media.name.substr(this.media.name.lastIndexOf('.') + 1);
|
|
|
|
}
|
2018-11-04 19:28:32 +01:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
iconLoaded(): void {
|
2018-11-04 19:28:32 +01:00
|
|
|
this.media.readyIcon = true;
|
|
|
|
}
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
isIconAvailable(): boolean {
|
2018-11-04 19:28:32 +01:00
|
|
|
return this.media.readyIcon;
|
|
|
|
}
|
|
|
|
|
2018-12-04 21:43:07 +01:00
|
|
|
getRelativePath(): string {
|
2021-05-15 10:33:43 +02:00
|
|
|
return encodeURI(Utils.concatUrls(this.media.directory.path,
|
2021-05-04 22:43:19 +02:00
|
|
|
this.media.directory.name,
|
2021-05-15 10:33:43 +02:00
|
|
|
this.media.name))
|
2021-05-04 22:43:19 +02:00
|
|
|
// 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
|
2021-05-15 10:33:43 +02:00
|
|
|
// .replace(new RegExp('%', 'g'), '%25') // order important
|
2021-05-04 22:43:19 +02:00
|
|
|
.replace(new RegExp('#', 'g'), '%23')
|
|
|
|
.replace(new RegExp('\\$', 'g'), '%24');
|
2018-12-04 21:43:07 +01:00
|
|
|
}
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
getIconPath(): string {
|
2018-11-04 19:28:32 +01:00
|
|
|
return Utils.concatUrls(Config.Client.urlBase,
|
|
|
|
'/api/gallery/content/',
|
2021-05-04 22:43:19 +02:00
|
|
|
this.getRelativePath(), 'icon');
|
2018-11-04 19:28:32 +01:00
|
|
|
}
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
getMediaPath(): string {
|
2018-11-04 19:28:32 +01:00
|
|
|
return Utils.concatUrls(Config.Client.urlBase,
|
2021-05-04 22:43:19 +02:00
|
|
|
'/api/gallery/content/', this.getRelativePath());
|
2018-11-04 19:28:32 +01:00
|
|
|
}
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
getBestFitMediaPath(): string {
|
2019-12-23 12:09:41 +01:00
|
|
|
return Utils.concatUrls(this.getMediaPath(), '/bestFit');
|
2019-12-09 14:05:06 +01:00
|
|
|
}
|
|
|
|
|
2018-11-04 19:28:32 +01:00
|
|
|
|
2018-12-04 21:43:07 +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;
|
|
|
|
}
|
|
|
|
}
|