tangled
alpha
login
or
join now
pds.ls
/
pdsls
398
fork
atom
atmosphere explorer
pds.ls
tool
typescript
atproto
398
fork
atom
overview
issues
1
pulls
pipelines
refactor labels
handle.invalid
1 week ago
1bb22c59
bb9374d3
verified
This commit was signed with the committer's
known signature
.
handle.invalid
SSH Key Fingerprint:
SHA256:mBrT4x0JdzLpbVR95g1hjI1aaErfC02kmLRkPXwsYCk=
+18
-29
1 changed file
expand all
collapse all
unified
split
src
views
labels.tsx
+18
-29
src/views/labels.tsx
···
14
14
import { localDateFromTimestamp } from "../utils/date.js";
15
15
16
16
const LABELS_PER_PAGE = 50;
17
17
+
const DEFAULT_LABELER_DID = "did:plc:ar7c4by46qjdydhdevvrndac";
17
18
18
19
const LabelCard = (props: { label: ComAtprotoLabelDefs.Label }) => {
19
20
const label = props.label;
···
76
77
.map((f) => f.trim())
77
78
.filter((f) => f.length > 0);
78
79
79
79
-
const exclusions: { pattern: string; hasWildcard: boolean }[] = [];
80
80
-
const inclusions: { pattern: string; hasWildcard: boolean }[] = [];
80
80
+
const toMatcher = (pattern: string): ((value: string) => boolean) => {
81
81
+
if (pattern.includes("*")) {
82
82
+
const regexPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
83
83
+
const regex = new RegExp(`^${regexPattern}$`);
84
84
+
return (value) => regex.test(value);
85
85
+
}
86
86
+
return (value) => value === pattern;
87
87
+
};
88
88
+
89
89
+
const exclusions: ((value: string) => boolean)[] = [];
90
90
+
const inclusions: ((value: string) => boolean)[] = [];
81
91
82
92
filters.forEach((f) => {
83
93
if (f.startsWith("-")) {
84
84
-
const lower = f.slice(1).toLowerCase();
85
85
-
exclusions.push({
86
86
-
pattern: lower,
87
87
-
hasWildcard: lower.includes("*"),
88
88
-
});
94
94
+
exclusions.push(toMatcher(f.slice(1).toLowerCase()));
89
95
} else {
90
90
-
const lower = f.toLowerCase();
91
91
-
inclusions.push({
92
92
-
pattern: lower,
93
93
-
hasWildcard: lower.includes("*"),
94
94
-
});
96
96
+
inclusions.push(toMatcher(f.toLowerCase()));
95
97
}
96
98
});
97
99
98
98
-
const matchesPattern = (value: string, filter: { pattern: string; hasWildcard: boolean }) => {
99
99
-
if (filter.hasWildcard) {
100
100
-
// Convert wildcard pattern to regex
101
101
-
const regexPattern = filter.pattern
102
102
-
.replace(/[.+?^${}()|[\]\\]/g, "\\$&") // Escape special regex chars except *
103
103
-
.replace(/\*/g, ".*"); // Replace * with .*
104
104
-
const regex = new RegExp(`^${regexPattern}$`);
105
105
-
return regex.test(value);
106
106
-
} else {
107
107
-
return value === filter.pattern;
108
108
-
}
109
109
-
};
110
110
-
111
100
return labels().filter((label) => {
112
101
const labelValue = label.val.toLowerCase();
113
102
114
114
-
if (exclusions.some((exc) => matchesPattern(labelValue, exc))) {
103
103
+
if (exclusions.some((exc) => exc(labelValue))) {
115
104
return false;
116
105
}
117
106
118
118
-
// If there are inclusions, at least one must match
119
107
if (inclusions.length > 0) {
120
120
-
return inclusions.some((inc) => matchesPattern(labelValue, inc));
108
108
+
return inclusions.some((inc) => inc(labelValue));
121
109
}
122
110
123
111
// If only exclusions were specified, include everything not excluded
···
137
125
});
138
126
139
127
const fetchLabels = async (formData: FormData, reset?: boolean) => {
140
140
-
let did = formData.get("did")?.toString()?.trim() || "did:plc:ar7c4by46qjdydhdevvrndac";
128
128
+
let did = formData.get("did")?.toString()?.trim() || DEFAULT_LABELER_DID;
141
129
const uriPatterns = formData.get("uriPatterns")?.toString()?.trim();
142
130
143
131
if (!did || !uriPatterns) {
···
170
158
uriPatterns: uriPatterns.split(",").map((p) => p.trim()),
171
159
sources: [did as `did:${string}:${string}`],
172
160
cursor: cursor(),
161
161
+
limit: LABELS_PER_PAGE,
173
162
},
174
163
});
175
164