Skip to content

Commit beb80fc

Browse files
committed
fix: resolve uuid generator issue and prevent duplicate subscription URL in production
1 parent 8e1e3b8 commit beb80fc

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

frontend/package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"react-hook-form": "^7.48.0",
2929
"react-router-dom": "^6.20.0",
3030
"tailwind-merge": "^2.2.1",
31+
"uuid": "^13.0.0",
3132
"zod": "^3.22.4"
3233
},
3334
"devDependencies": {

frontend/src/lib/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getApiClient } from './api-client'
2+
import { v4 as uuidv4 } from 'uuid'
23
import {
34
LoginResponse,
45
DashboardData,
@@ -294,7 +295,7 @@ export const userAPI = {
294295
createUser: async (email: string, totalGb: number, expiryDatetime?: string | null): Promise<ClientsOutput> => {
295296
const submitData = {
296297
email,
297-
id: crypto.randomUUID(),
298+
id: uuidv4(),
298299
enable: true,
299300
expiry_time: expiryDatetime ? new Date(expiryDatetime + 'T00:00:00').getTime() : 0,
300301
total: Math.floor(totalGb * 1024 * 1024 * 1024),

frontend/src/pages/DashboardPage.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ import {
5656
} from '@/components/ui/dialog'
5757
import { UserFormDialog } from './components/UserFormDialog'
5858

59+
function buildSubUrl(subUrl?: string, subId?: string) {
60+
if (!subUrl || !subId) return ''
61+
62+
if (subId.startsWith('http://') || subId.startsWith('https://')) {
63+
return subId
64+
}
65+
66+
const cleanBase = subUrl.replace(/\/+$/, '')
67+
const cleanId = subId.replace(/^\/+/, '')
68+
69+
return `${cleanBase}/${cleanId}`
70+
}
71+
5972

6073
interface ExpandedRow {
6174
[key: string]: boolean
@@ -645,7 +658,7 @@ export function DashboardPage() {
645658
<>
646659
<div className="p-4 bg-white rounded-lg border">
647660
<QRCodeSVG
648-
value={`${dashboardData.sub_url}/${qrUser.sub_id?.replace(/^\/+|\/+$/g, '')}`}
661+
value={buildSubUrl(dashboardData.sub_url, qrUser.sub_id)}
649662
size={200}
650663
level="M"
651664
/>
@@ -655,7 +668,7 @@ export function DashboardPage() {
655668
<p><strong>User:</strong> {qrUser?.username}</p>
656669
</div>
657670
<div className="p-3 bg-muted rounded-md break-all text-xs font-mono">
658-
{`${dashboardData.sub_url}/${qrUser.sub_id?.replace(new RegExp(`^${dashboardData.sub_url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`), '').replace(/^\/+/, '')}`}
671+
{buildSubUrl(dashboardData.sub_url, qrUser.sub_id)}
659672
</div>
660673
</div>
661674
</>
@@ -780,7 +793,7 @@ function DetailsRow({
780793
{subUrl && user.sub_id && (
781794
<div className="p-3 bg-background rounded-md border">
782795
<div className="text-xs text-muted-foreground mb-1">Subscription Link:</div>
783-
<div className="text-xs font-mono break-all">{`${subUrl}/${user.sub_id?.replace(new RegExp(`^${subUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`), '').replace(/^\/+/, '')}`}</div>
796+
{buildSubUrl(subUrl, user.sub_id)}
784797
</div>
785798
)}
786799
<div className="flex flex-wrap gap-2 pt-2">
@@ -797,7 +810,8 @@ function DetailsRow({
797810
size="sm"
798811
variant="outline"
799812
onClick={() => {
800-
navigator.clipboard.writeText(`${subUrl}/${user.sub_id?.replace(new RegExp(`^${subUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`), '').replace(/^\/+/, '') || user.sub_id}`)
813+
navigator.clipboard.writeText(buildSubUrl(subUrl, user.sub_id))
814+
801815
}}
802816
>
803817
<Copy className="h-4 w-4 mr-2" />
@@ -968,7 +982,8 @@ function MobileUserCard({
968982
className="flex-1 min-w-[80px]"
969983
onClick={(e) => {
970984
e.stopPropagation()
971-
navigator.clipboard.writeText(`${subUrl}/${user.sub_id?.replace(new RegExp(`^${subUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`), '').replace(/^\/+/, '') || user.sub_id}`)
985+
navigator.clipboard.writeText(buildSubUrl(subUrl, user.sub_id))
986+
972987
}}
973988
>
974989
<Copy className="h-3 w-3 mr-1" />

0 commit comments

Comments
 (0)