1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/model/query.service.ts
Patrik J. Braun 609c788d91 improving API performance by removing null properties
adding photo caption reading
2018-12-05 17:29:33 +01:00

58 lines
1.8 KiB
TypeScript

import {Injectable} from '@angular/core';
import {ShareService} from '../gallery/share.service';
import {PhotoDTO} from '../../../common/entities/PhotoDTO';
import {MediaDTO} from '../../../common/entities/MediaDTO';
import {QueryParams} from '../../../common/QueryParams';
import {Utils} from '../../../common/Utils';
import {GalleryService} from '../gallery/gallery.service';
import {Config} from '../../../common/config/public/Config';
import {DirectoryDTO} from '../../../common/entities/DirectoryDTO';
@Injectable()
export class QueryService {
constructor(private shareService: ShareService,
private galleryService: GalleryService) {
}
getMediaStringId(media: MediaDTO): string {
if (this.galleryService.isSearchResult()) {
return Utils.concatUrls(media.directory.path, media.directory.name, media.name);
} else {
return media.name;
}
}
getParams(media?: MediaDTO): { [key: string]: string } {
const query: { [key: string]: string } = {};
if (media) {
query[QueryParams.gallery.photo] = this.getMediaStringId(media);
}
if (Config.Client.Sharing.enabled === true) {
if (this.shareService.isSharing()) {
query[QueryParams.gallery.sharingKey_short] = this.shareService.getSharingKey();
}
}
return query;
}
getParamsForDirs(directory: DirectoryDTO) {
const params: { [key: string]: any } = {};
if (Config.Client.Sharing.enabled === true) {
if (this.shareService.isSharing()) {
params[QueryParams.gallery.sharingKey_short] = this.shareService.getSharingKey();
}
}
if (directory && directory.lastModified && directory.lastScanned &&
!directory.isPartial) {
params['knownLastModified'] = directory.lastModified;
params['knownLastScanned'] = directory.lastScanned;
}
return params;
}
}