Add automatic classification

This commit is contained in:
Kuba Orlik 2021-11-07 17:44:22 +01:00
parent 729a60a998
commit 0960006a5a
3 changed files with 41 additions and 6 deletions

View File

@ -21,20 +21,22 @@ function Report() {
<th>Adres docelowy</th>
<th>Źródło danych</th>
<th>Treść danych</th>
<th> Klasyfikacja</th>
<th>Klasyfikacja</th>
</tr>
</thead>
<tbody>
{marked_entries.map((entry) => (
<tr>
<td>{entry.request.shorthost}</td>
<td>
<td style={{ overflowWrap: "anywhere" }}>
{entry.source}:{entry.name}
{entry.markedKeys.join(",")}
</td>
<td>{entry.value}</td>
<td style={{ width: "400px", overflowWrap: "anywhere" }}>
{entry.value}
</td>
<td>
<select>
<select value={entry.classification}>
{[
["history", "Historia przeglądania"],
["id", "Sztucznie nadane id"],

View File

@ -1,10 +1,21 @@
import { TCModel } from "@iabtcf/core";
import ExtendedRequest from "./extended-request";
import { getMemory } from "./memory";
import { isJSONObject, isURL, parseToObject } from "./util";
import {
isJSONObject,
isURL,
parseToObject,
reduceConcat,
unique,
} from "./util";
export type Sources = "cookie" | "pathname" | "queryparams" | "header";
export const Classifications = <const>{
id: "Sztucznie nadane ID",
history: "Część historii przeglądania",
};
const id = (function* id() {
let i = 0;
while (true) {
@ -18,6 +29,7 @@ export class StolenDataEntry {
public iab: TCModel | null = null;
public id: number;
public markedKeys: string[] = [];
public classification: keyof typeof Classifications;
constructor(
public request: ExtendedRequest,
@ -31,6 +43,7 @@ export class StolenDataEntry {
// this.isIAB = true;
// } catch (e) {}
this.id = id.next().value as number;
this.classification = this.classify();
}
getPriority() {
@ -112,10 +125,26 @@ export class StolenDataEntry {
this.addMark(key);
}
}
private classify(): keyof typeof Classifications {
if (this.value.includes(this.request.origin)) {
return "history";
} else {
return "id";
}
}
}
export class MergedStolenDataEntry {
constructor(public entries: StolenDataEntry[]) {}
constructor(public entries: StolenDataEntry[]) {
const all_marks = unique(
entries.map((entry) => entry.markedKeys).reduce(reduceConcat, [])
);
for (const entry of entries) {
entry.markedKeys = all_marks;
}
// getMemory().emit("change"); // to trigger render
}
hasValue(value: string) {
return this.entries.some((entry) => entry.value === value);

View File

@ -95,3 +95,7 @@ export function allSubhosts(host: string) {
}
return result;
}
export function reduceConcat<T>(a: T[], b: T[]): T[] {
return a.concat(b);
}