aboutsummaryrefslogtreecommitdiff
path: root/src/shared/settings/Blacklist.ts
diff options
context:
space:
mode:
authorShin'ya UEOKA <ueokande@i-beam.org>2019-10-06 12:51:43 +0000
committerShin'ya UEOKA <ueokande@i-beam.org>2019-10-08 11:43:10 +0000
commitfa6dfb0395826041349c604edcbcbaa316fc95d8 (patch)
tree761cc8da5ec0c047e6b3dddb762e3b015688691e /src/shared/settings/Blacklist.ts
parent7528fe831fa4e17e5c427e89025ac76b078a9313 (diff)
Add partial blacklist form
Diffstat (limited to 'src/shared/settings/Blacklist.ts')
-rw-r--r--src/shared/settings/Blacklist.ts24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/shared/settings/Blacklist.ts b/src/shared/settings/Blacklist.ts
index 5648611..0cfbd71 100644
--- a/src/shared/settings/Blacklist.ts
+++ b/src/shared/settings/Blacklist.ts
@@ -1,3 +1,5 @@
+import Key from './Key';
+
export type BlacklistItemJSON = string | {
url: string,
keys: string[],
@@ -31,7 +33,9 @@ export class BlacklistItem {
public readonly keys: string[];
- private constructor(
+ private readonly keyEntities: Key[];
+
+ constructor(
pattern: string,
partial: boolean,
keys: string[]
@@ -40,6 +44,7 @@ export class BlacklistItem {
this.regex = regexFromWildcard(pattern);
this.partial = partial;
this.keys = keys;
+ this.keyEntities = this.keys.map(Key.fromMapKey);
}
static fromJSON(raw: any): BlacklistItem {
@@ -81,17 +86,20 @@ export class BlacklistItem {
: this.regex.test(url.host);
}
- includeKey(url: URL, keys: string): boolean {
+ includeKey(url: URL, key: Key): boolean {
if (!this.matches(url)) {
return false;
}
- return !this.partial || this.keys.includes(keys);
+ if (!this.partial) {
+ return true;
+ }
+ return this.keyEntities.some(k => k.equals(key));
}
}
export default class Blacklist {
constructor(
- private blacklist: BlacklistItem[],
+ public readonly items: BlacklistItem[],
) {
}
@@ -104,14 +112,14 @@ export default class Blacklist {
}
toJSON(): BlacklistJSON {
- return this.blacklist.map(item => item.toJSON());
+ return this.items.map(item => item.toJSON());
}
includesEntireBlacklist(url: URL): boolean {
- return this.blacklist.some(item => !item.partial && item.matches(url));
+ return this.items.some(item => !item.partial && item.matches(url));
}
- includeKey(url: URL, key: string) {
- return this.blacklist.some(item => item.includeKey(url, key));
+ includeKey(url: URL, key: Key) {
+ return this.items.some(item => item.includeKey(url, key));
}
}