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

View File

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

View File

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