-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprivacy.service.ts
44 lines (35 loc) · 1.09 KB
/
privacy.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {Injectable} from '@angular/core';
import {Observable, of} from 'rxjs';
import {StorageService} from './storage.service';
export type Privacy = 'all' | 'local' | 'none' | 'nobanner';
@Injectable({
providedIn: 'root',
})
export class PrivacyService {
constructor(
private storageService: StorageService,
) {
}
get privacy(): Privacy | null {
return this.storageService.get('privacy') as Privacy;
}
set privacy(value: Privacy | null) {
this.storageService.set('privacy', value === 'none' ? null : value);
}
get allowLocalStorage(): boolean {
const privacy = this.privacy;
return privacy !== null && privacy !== 'none' && privacy !== 'nobanner';
}
getStorage(key: string): string | null {
return this.allowLocalStorage ? this.storageService.get(key) : null;
}
getStorage$(key: string): Observable<string | null> {
return this.allowLocalStorage ? this.storageService.get$(key) : of(null);
}
setStorage(key: string, value: string | null): void {
if (!this.allowLocalStorage) {
return;
}
this.storageService.set(key, value);
}
}