Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

improve auto generate short link + whitelist issues

Steven Tey03c34dfd232c
diff --git a/apps/web/lib/edge-config/is-blacklisted-domain.ts b/apps/web/lib/edge-config/is-blacklisted-domain.ts
index e27b557cb5..b5b53dcfea 100644
--- a/apps/web/lib/edge-config/is-blacklisted-domain.ts
+++ b/apps/web/lib/edge-config/is-blacklisted-domain.ts
@@ -22,6 +22,10 @@ export const isBlacklistedDomain = async ({
whitelistedDomains,
} = await getAll(["domains", "terms", "whitelistedDomains"]);
+ if (whitelistedDomains.includes(apexDomain)) {
+ return "whitelisted";
+ }
+
const blacklistedTermsRegex = new RegExp(
blacklistedTerms
.map((term: string) => term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
@@ -35,10 +39,6 @@ export const isBlacklistedDomain = async ({
return true;
}
- if (whitelistedDomains.includes(apexDomain)) {
- return "whitelisted";
- }
-
return false;
} catch (e) {
return false;
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index e32a23f139..021eee4e6d 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -52,7 +52,7 @@ import {
} from "react";
import { toast } from "sonner";
import { mutate } from "swr";
-import { useDebounce, useDebouncedCallback } from "use-debounce";
+import { useDebounce } from "use-debounce";
import AndroidSection from "./android-section";
import CloakingSection from "./cloaking-section";
import CommentsSection from "./comments-section";
@@ -131,27 +131,16 @@ function AddEditLinkModal({
const { domain, key, url, password, proxy } = data;
- const generateRandomKey = useDebouncedCallback(async () => {
- if (generatingRandomKey) return;
-
- if (domain && workspaceId) {
- setKeyError(null);
- setGeneratingRandomKey(true);
- const res = await fetch(
- `/api/links/random?domain=${domain}&workspaceId=${workspaceId}`,
- );
- const key = await res.json();
- setData((prev) => ({ ...prev, key }));
- setGeneratingRandomKey(false);
- }
- }, 500);
-
- useEffect(() => {
- // if there's no key, generate a random key
- if (showAddEditLinkModal && url.length > 0 && !key) {
- generateRandomKey();
- }
- }, [showAddEditLinkModal, url]);
+ const generateRandomKey = async () => {
+ setKeyError(null);
+ setGeneratingRandomKey(true);
+ const res = await fetch(
+ `/api/links/random?domain=${domain}&workspaceId=${workspaceId}`,
+ );
+ const key = await res.json();
+ setData((prev) => ({ ...prev, key }));
+ setGeneratingRandomKey(false);
+ };
const runKeyChecks = async (value: string) => {
const res = await fetch(
@@ -405,7 +394,6 @@ function AddEditLinkModal({
onSubmit={async (e) => {
e.preventDefault();
setSaving(true);
- generateRandomKey.cancel();
// @ts-ignore – exclude extra attributes from `data` object before sending to API
const { user, tags, tagId, ...rest } = data;
const bodyData = {
@@ -571,6 +559,7 @@ function AddEditLinkModal({
) : (
<div className="flex items-center">
<ButtonTooltip
+ tabIndex={-1}
tooltipContent="Generate a random key"
onClick={generateRandomKey}
disabled={generatingRandomKey || generatingAIKey}
@@ -583,6 +572,7 @@ function AddEditLinkModal({
)}
</ButtonTooltip>
<ButtonTooltip
+ tabIndex={-1}
tooltipContent="Generate a key using AI"
onClick={generateAIKey}
disabled={
@@ -605,6 +595,7 @@ function AddEditLinkModal({
<div className="relative mt-1 flex rounded-md shadow-sm">
<div>
<select
+ tabIndex={-1}
disabled={props && lockKey}
value={domain}
onChange={(e) => {
@@ -640,6 +631,13 @@ function AddEditLinkModal({
// if the key is changed, check if key exists
if (e.target.value && props?.key !== e.target.value) {
runKeyChecks(e.target.value);
+ } else if (
+ domain &&
+ workspaceId &&
+ url.length > 0 &&
+ !saving
+ ) {
+ generateRandomKey();
}
}}
disabled={props && lockKey}