1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-27 02:09:16 +02:00

implementing autocomplete caching

This commit is contained in:
Patrik Braun 2017-07-29 23:39:06 +02:00
parent 340838f070
commit ebbe4009f5
7 changed files with 68 additions and 13 deletions

View File

@ -38,7 +38,7 @@ Full node install description: https://raspberrypi.stackexchange.com/questions/4
```bash
cd ~
wget https://github.com/bpatrik/pigallery2/releases/download/1.0.0-beta.3/pigallery2.zip
wget https://github.com/bpatrik/pigallery2/releases/download/1.0.0-rc.1/pigallery2.zip
unzip pigallery2
cd pigallery2
npm install
@ -59,6 +59,12 @@ npm start
To configure it. Run `PiGallery2` first to create `config.json` file, then edit it and restart.
Default user: `admin` pass: `admin`
### Using nginx
https://stackoverflow.com/questions/5009324/node-js-nginx-what-now
### making https
https://certbot.eff.org/
## Feature list
* **Rendering directories as it is**
@ -91,9 +97,10 @@ Default user: `admin` pass: `admin`
* instant search, auto complete
* sharing
* setting link expiration time
* Nice design - `In progress`
* Nice design
* responsive design (phone, tablet desktop support)
* Setup page - `In progress`
* Setup page
* video support - `future plan`
* **Markdown based blogging support** - `future plan`
* you can write some note in the blog.md for every directory
* bug free :) - `In progress`

View File

@ -4,6 +4,7 @@ export module ClientConfig {
instantSearchEnabled: boolean
autocompleteEnabled: boolean
InstantSearchTimeout: number;
autocompleteCacheTimeout: number;
}
export interface SharingConfig {
@ -15,6 +16,7 @@ export module ClientConfig {
enabled: boolean;
googleApiKey: string;
}
export interface ThumbnailConfig {
iconSize: number;
thumbnailSizes: Array<number>;
@ -35,6 +37,7 @@ export module ClientConfig {
}
}
/**
* These configuration will be available at frontend and backend too
*/
@ -50,7 +53,8 @@ export class PublicConfigClass {
enabled: true,
instantSearchEnabled: true,
autocompleteEnabled: true,
InstantSearchTimeout: 3000
InstantSearchTimeout: 3000,
autocompleteCacheTimeout: 1000 * 60 * 60
},
Sharing: {
enabled: true,

View File

@ -3,16 +3,47 @@ import {PhotoDTO} from "../../../common/entities/PhotoDTO";
import {DirectoryDTO} from "../../../common/entities/DirectoryDTO";
import {Utils} from "../../../common/Utils";
import {Config} from "../../../common/config/public/Config";
import {AutoCompleteItem} from "../../../common/entities/AutoCompleteItem";
interface AutoCompleteCacheItem {
timestamp: number;
items: Array<AutoCompleteItem>;
}
@Injectable()
export class GalleryCacheService {
private static CONTENT_PREFIX = "content:";
private static AUTO_COMPLETE_PREFIX = "content:";
public getAutoComplete(text: string): Array<AutoCompleteItem> {
const key = GalleryCacheService.AUTO_COMPLETE_PREFIX + text;
const tmp = localStorage.getItem(key);
if (tmp != null) {
const value: AutoCompleteCacheItem = JSON.parse(tmp);
if (value.timestamp < Date.now() - Config.Client.Search.autocompleteCacheTimeout) {
localStorage.removeItem(key);
return null;
}
return value.items;
}
return null;
}
public setAutoComplete(text, items: Array<AutoCompleteItem>): void {
const tmp: AutoCompleteCacheItem = {
timestamp: Date.now(),
items: items
};
localStorage.setItem(GalleryCacheService.AUTO_COMPLETE_PREFIX + text, JSON.stringify(tmp));
}
public getDirectory(directoryName: string): DirectoryDTO {
if (Config.Client.enableCache == false) {
return null;
}
let value = localStorage.getItem(Utils.concatUrls(directoryName));
let value = localStorage.getItem(GalleryCacheService.CONTENT_PREFIX + Utils.concatUrls(directoryName));
if (value != null) {
let directory: DirectoryDTO = JSON.parse(value);
@ -27,7 +58,7 @@ export class GalleryCacheService {
return;
}
const key = Utils.concatUrls(directory.path, directory.name);
const key = GalleryCacheService.CONTENT_PREFIX + Utils.concatUrls(directory.path, directory.name);
if (directory.isPartial == true && localStorage.getItem(key)) {
return;
}

View File

@ -1,16 +1,23 @@
import {Injectable} from "@angular/core";
import {NetworkService} from "../../model/network/network.service";
import {AutoCompleteItem} from "../../../../common/entities/AutoCompleteItem";
import {GalleryCacheService} from "../cache.gallery.service";
@Injectable()
export class AutoCompleteService {
constructor(private _networkService: NetworkService) {
constructor(private _networkService: NetworkService,
private galleryCacheService: GalleryCacheService) {
}
public autoComplete(text: string): Promise<Array<AutoCompleteItem>> {
return this._networkService.getJson<Array<AutoCompleteItem>>("/autocomplete/" + text);
public async autoComplete(text: string): Promise<Array<AutoCompleteItem>> {
let items: Array<AutoCompleteItem> = this.galleryCacheService.getAutoComplete(text);
if (items == null) {
items = await this._networkService.getJson<Array<AutoCompleteItem>>("/autocomplete/" + text);
this.galleryCacheService.setAutoComplete(text, items);
}
return items;
}

View File

@ -13,7 +13,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" (click)="shareModal.hide()" aria-label="Close"><span
<button type="button" class="close" (click)="hideModal()" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="shareModalLabel">Share</h4>
</div>

View File

@ -81,7 +81,6 @@ export class GalleryShareComponent implements OnInit, OnDestroy {
}
this.url = "loading..";
this.sharing = await this._sharingService.updateSharing(this.currentDir, this.sharing.id, this.input.includeSubfolders, this.input.password, this.calcValidity());
console.log(this.sharing);
this.url = Config.Client.publicUrl + "/share/" + this.sharing.sharingKey
}
@ -101,9 +100,15 @@ export class GalleryShareComponent implements OnInit, OnDestroy {
this._notification.success("Url has been copied to clipboard");
}
hodiModel() {
this.childModal.hide();
this.sharing = null;
}
}
export enum ValidityTypes{
export enum ValidityTypes {
Minutes = 0, Hours = 1, Days = 2, Months = 3
}

View File

@ -19,7 +19,8 @@ export class SettingsService {
enabled: true,
autocompleteEnabled: true,
instantSearchEnabled: true,
InstantSearchTimeout: 0
InstantSearchTimeout: 0,
autocompleteCacheTimeout: 1000 * 60 * 60
},
concurrentThumbnailGenerations: null,
Thumbnail: {