regex check validity of hf token
Browse files
src/lib/components/InferencePlayground/InferencePlayground.svelte
CHANGED
@@ -133,9 +133,15 @@
|
|
133 |
function handleTokenSubmit(e: Event) {
|
134 |
const form = e.target as HTMLFormElement;
|
135 |
const formData = new FormData(form);
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
}
|
140 |
|
141 |
onDestroy(() => {
|
|
|
133 |
function handleTokenSubmit(e: Event) {
|
134 |
const form = e.target as HTMLFormElement;
|
135 |
const formData = new FormData(form);
|
136 |
+
const submittedHfToken = (formData.get("hf-token") as string).trim() ?? "";
|
137 |
+
const RE_HF_TOKEN = /\bhf_[a-zA-Z0-9]{34}\b/;
|
138 |
+
if (RE_HF_TOKEN.test(submittedHfToken)) {
|
139 |
+
hfToken = submittedHfToken;
|
140 |
+
submit();
|
141 |
+
showTokenModal = false;
|
142 |
+
} else {
|
143 |
+
alert("Please provide a valid HF token.");
|
144 |
+
}
|
145 |
}
|
146 |
|
147 |
onDestroy(() => {
|