diff --git a/packages/api/src/public-share.ts b/packages/api/src/public-share.ts index 4487d3cc..157e60a8 100644 --- a/packages/api/src/public-share.ts +++ b/packages/api/src/public-share.ts @@ -1,4 +1,5 @@ import { Hono } from 'hono' +import type { Context } from 'hono' import { zValidator } from '@hono/zod-validator' import { shareService } from '@shumai/core/src/share/share' import { assetService } from '@shumai/core/src/asset/asset' @@ -11,6 +12,12 @@ import { auth } from '@shumai/core/src/auth/auth' import { prisma } from '@shumai/db' import { createCommentRequestSchema } from '@shumai/dtos' import { notificationService } from '@shumai/core/src/notification/notification' +import { + ShareLinkNotFoundError, + ShareLinkDisabledError, + ShareLinkExpiredError, + ShareLinkPasswordInvalidError, +} from '@shumai/core/src/share/errors' const app = new Hono() @@ -30,6 +37,22 @@ function toFieldInfo( } } +export function handlePublicShareError(c: Context, err: unknown) { + if (err instanceof ShareLinkPasswordInvalidError) { + return c.json({ error: 'Unauthorized' }, 401) + } + if (err instanceof ShareLinkExpiredError || err instanceof ShareLinkDisabledError) { + const msg = err instanceof Error ? err.message : String(err) + return c.json({ error: msg }, 403) + } + if (err instanceof ShareLinkNotFoundError) { + const msg = err instanceof Error ? err.message : String(err) + return c.json({ error: msg }, 404) + } + const msg = err instanceof Error ? err.message : String(err) + return c.json({ error: msg }, 500) +} + const sharedChildrenRequestSchema = paginationParamsSchema.extend({ assetType: z.string().optional(), }) @@ -37,8 +60,10 @@ const sharedChildrenRequestSchema = paginationParamsSchema.extend({ const route = app .get('/shares/:shareId/info', async (c) => { const shareId = c.req.param('shareId') + const password = c.req.header('x-share-password') try { const shareLink = await shareService.getShareLink(shareId) + await shareService.verifyPublicAccess(shareLink.rootFolderId, password) return c.json({ id: shareLink.id, name: shareLink.name, @@ -52,7 +77,7 @@ const route = app defaultSortOrder: shareLink.defaultSortOrder, }) } catch (err) { - return c.json({ error: (err as Error).message }, 404) + return handlePublicShareError(c, err) } }) .get('/shares/:shareId/fields', async (c) => { @@ -72,14 +97,7 @@ const route = app .map((f) => toFieldInfo(f.field, f.visible)), ) } catch (err) { - const msg = (err as Error).message - if (msg === 'Invalid password for share link') { - return c.json({ error: 'Unauthorized' }, 401) - } - if (msg === 'Share link has expired' || msg === 'Share link is disabled') { - return c.json({ error: msg }, 403) - } - return c.json({ error: msg }, 500) + return handlePublicShareError(c, err) } }) .get( @@ -112,14 +130,7 @@ const route = app return c.json(res) } catch (err) { - const msg = (err as Error).message - if (msg === 'Invalid password for share link') { - return c.json({ error: 'Unauthorized' }, 401) - } - if (msg === 'Share link has expired' || msg === 'Share link is disabled') { - return c.json({ error: msg }, 403) - } - return c.json({ error: msg }, 500) + return handlePublicShareError(c, err) } }, ) @@ -133,14 +144,7 @@ const route = app const asset = await assetService.getAsset({ assetId: fileId }) return c.json(asset) } catch (err) { - const msg = (err as Error).message - if (msg === 'Invalid password for share link') { - return c.json({ error: 'Unauthorized' }, 401) - } - if (msg === 'Share link has expired' || msg === 'Share link is disabled') { - return c.json({ error: msg }, 403) - } - return c.json({ error: msg }, 500) + return handlePublicShareError(c, err) } }) .get( @@ -158,14 +162,7 @@ const route = app const res = await assetService.listComments(targetFileId, req) return c.json(res) } catch (err) { - const msg = (err as Error).message - if (msg === 'Invalid password for share link') { - return c.json({ error: 'Unauthorized' }, 401) - } - if (msg === 'Share link has expired' || msg === 'Share link is disabled') { - return c.json({ error: msg }, 403) - } - return c.json({ error: msg }, 500) + return handlePublicShareError(c, err) } }, ) @@ -237,14 +234,7 @@ const route = app return c.json(comment, 201) } catch (err) { - const msg = (err as Error).message - if (msg === 'Invalid password for share link') { - return c.json({ error: 'Unauthorized' }, 401) - } - if (msg === 'Share link has expired' || msg === 'Share link is disabled') { - return c.json({ error: msg }, 403) - } - return c.json({ error: msg }, 500) + return handlePublicShareError(c, err) } }, ) diff --git a/packages/api/src/share.test.ts b/packages/api/src/share.test.ts index a5f84db8..b29102a4 100644 --- a/packages/api/src/share.test.ts +++ b/packages/api/src/share.test.ts @@ -6,6 +6,7 @@ import { authMiddleware } from './middleware/auth' import { shareService } from '@shumai/core/src/share/share' import { assetService } from '@shumai/core/src/asset/asset' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz' +import { ShareLinkPasswordInvalidError, ShareLinkExpiredError } from '@shumai/core/src/share/errors' vi.mock('./middleware/auth', () => ({ // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -57,15 +58,74 @@ describe('Share API', () => { createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), }) + vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({ + id: 'share1', + name: 'Public Share', + rootFolderId: 'folder1', + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } as any) const res = await app.request('/shares/share1/info', { method: 'GET', + headers: { 'x-share-password': 'pass' }, }) expect(res.status).toBe(200) const body = await res.json() expect(body.name).toBe('Public Share') expect(body.hasPassword).toBe(true) + expect(shareService.verifyPublicAccess).toHaveBeenCalledWith('folder1', 'pass') + }) + + test('Unauthorized', async () => { + vi.spyOn(shareService, 'getShareLink').mockResolvedValue({ + id: 'share1', + name: 'Public Share', + isDisabled: false, + isExpired: false, + hasPassword: true, + rootFolderId: 'folder1', + projectId: 'project1', + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + }) + vi.spyOn(shareService, 'verifyPublicAccess').mockRejectedValue( + new ShareLinkPasswordInvalidError('Invalid password for share link'), + ) + + const res = await app.request('/shares/share1/info', { + method: 'GET', + headers: { 'x-share-password': 'wrong' }, + }) + + expect(res.status).toBe(401) + const body = await res.json() + expect(body.error).toBe('Unauthorized') + }) + + test('Expired/Disabled', async () => { + vi.spyOn(shareService, 'getShareLink').mockResolvedValue({ + id: 'share1', + name: 'Public Share', + isDisabled: false, + isExpired: false, + hasPassword: true, + rootFolderId: 'folder1', + projectId: 'project1', + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + }) + vi.spyOn(shareService, 'verifyPublicAccess').mockRejectedValue( + new ShareLinkExpiredError('Share link has expired'), + ) + + const res = await app.request('/shares/share1/info', { + method: 'GET', + }) + + expect(res.status).toBe(403) + const body = await res.json() + expect(body.error).toBe('Share link has expired') }) }) diff --git a/packages/core/src/share/errors.ts b/packages/core/src/share/errors.ts new file mode 100644 index 00000000..10fb0177 --- /dev/null +++ b/packages/core/src/share/errors.ts @@ -0,0 +1,31 @@ +export class ShareLinkNotFoundError extends Error { + constructor(message: string) { + super(message) + this.name = 'ShareLinkNotFoundError' + Object.setPrototypeOf(this, ShareLinkNotFoundError.prototype) + } +} + +export class ShareLinkDisabledError extends Error { + constructor(message: string) { + super(message) + this.name = 'ShareLinkDisabledError' + Object.setPrototypeOf(this, ShareLinkDisabledError.prototype) + } +} + +export class ShareLinkExpiredError extends Error { + constructor(message: string) { + super(message) + this.name = 'ShareLinkExpiredError' + Object.setPrototypeOf(this, ShareLinkExpiredError.prototype) + } +} + +export class ShareLinkPasswordInvalidError extends Error { + constructor(message: string) { + super(message) + this.name = 'ShareLinkPasswordInvalidError' + Object.setPrototypeOf(this, ShareLinkPasswordInvalidError.prototype) + } +} diff --git a/packages/core/src/share/share.ts b/packages/core/src/share/share.ts index 232cba03..9a73bd31 100644 --- a/packages/core/src/share/share.ts +++ b/packages/core/src/share/share.ts @@ -9,6 +9,12 @@ import { } from '@shumai/dtos' import { PaginatedData, paginateQuery } from '@shumai/core/src/pagination' import { getAvatarUrl } from '@shumai/core/src/user/avatar' +import { + ShareLinkNotFoundError, + ShareLinkDisabledError, + ShareLinkExpiredError, + ShareLinkPasswordInvalidError, +} from './errors' export class ShareService { async createShareLink( @@ -143,7 +149,7 @@ export class ShareService { where: { id: shareLinkId }, include: { creator: true }, }) - if (!shareLink) throw new Error('Share link not found') + if (!shareLink) throw new ShareLinkNotFoundError('Share link not found') return await this.toShareLinkInfo(shareLink) } @@ -264,7 +270,7 @@ export class ShareService { ` if (rows.length === 0) { - throw new Error('Asset is not shared') + throw new ShareLinkNotFoundError('Asset is not shared') } const shareRootId = rows[0].shareRootId @@ -273,19 +279,19 @@ export class ShareService { }) if (!shareLink) { - throw new Error('Share link not found for this asset') + throw new ShareLinkNotFoundError('Share link not found for this asset') } if (shareLink.isDisabled) { - throw new Error('Share link is disabled') + throw new ShareLinkDisabledError('Share link is disabled') } if (shareLink.expireAt && shareLink.expireAt < new Date()) { - throw new Error('Share link has expired') + throw new ShareLinkExpiredError('Share link has expired') } if (shareLink.password && shareLink.password !== providedPassword) { - throw new Error('Invalid password for share link') + throw new ShareLinkPasswordInvalidError('Invalid password for share link') } return shareLink @@ -301,6 +307,7 @@ export class ShareService { expireAt: l.expireAt?.toISOString(), isDisabled: l.isDisabled, hasPassword: !!l.password, + password: l.password, defaultSortOrder: l.defaultSortOrder, viewMode: l.viewMode, fieldVisibility: l.fieldVisibility as Record | undefined, diff --git a/packages/dtos/src/share.ts b/packages/dtos/src/share.ts index ad2c3317..d19f9436 100644 --- a/packages/dtos/src/share.ts +++ b/packages/dtos/src/share.ts @@ -7,6 +7,7 @@ export interface ShareLinkInfo { expireAt?: string isDisabled: boolean hasPassword: boolean + password?: string | null defaultSortOrder?: string viewMode?: string fieldVisibility?: Record diff --git a/packages/webui/components/public-share-manager.tsx b/packages/webui/components/public-share-manager.tsx index efbc9b83..7a1295f9 100644 --- a/packages/webui/components/public-share-manager.tsx +++ b/packages/webui/components/public-share-manager.tsx @@ -21,48 +21,81 @@ import type { Annotation } from '@/ui/types' import { useNavigate } from '@tanstack/react-router' interface PublicShareManagerProps { - shareInfo: { - id: string - name: string - expireAt: string | null - isDisabled: boolean - isExpired: boolean - hasPassword: boolean - rootFolderId: string - projectId: string - viewMode?: string | null - defaultSortOrder?: string | null - } + shareId: string initialFolderId?: string initialFileId?: string startTime?: number } +interface PublicShareInfo { + id: string + name: string + expireAt: string | null + isDisabled: boolean + isExpired: boolean + hasPassword: boolean + rootFolderId: string + projectId: string + viewMode?: string | null + defaultSortOrder?: string | null +} + export function PublicShareManager({ - shareInfo, + shareId, initialFolderId, initialFileId, startTime, }: PublicShareManagerProps) { const navigate = useNavigate() const [password, setPassword] = useState(() => { - return localStorage.getItem(`share_pwd_${shareInfo.id}`) || '' + return localStorage.getItem(`share_pwd_${shareId}`) || '' }) const [passwordInput, setPasswordInput] = useState('') - const [isPasswordValid, setIsPasswordValid] = useState(!shareInfo.hasPassword || !!password) - const currentFolderId = initialFolderId || shareInfo.rootFolderId + const { + data: shareInfo, + error: shareInfoError, + isLoading: isShareInfoLoading, + } = useQuery({ + queryKey: ['share-info', shareId, password], + queryFn: async () => { + const res = await client.api.shares[':shareId'].info.$get( + { + param: { shareId }, + }, + { + headers: { + 'x-share-password': password, + }, + }, + ) + if (res.status === 401) { + throw new Error('Unauthorized') + } + if (res.status === 403) { + const body = (await res.json()) as { error?: string } + throw new Error(body.error || 'Forbidden') + } + if (!res.ok) { + throw new Error('Failed to fetch share info') + } + return (await res.json()) as unknown as PublicShareInfo + }, + retry: false, + }) + + const currentFolderId = initialFolderId || shareInfo?.rootFolderId const viewingFileId = initialFileId || null const [ancestorFolders, setAncestorFolders] = useState([]) // Fetch ancestors for breadcrumb const { data: folderInfo } = useQuery({ - queryKey: ['public-share-folder', shareInfo.id, currentFolderId, password], + queryKey: ['public-share-folder', shareId, currentFolderId, password], queryFn: async () => { const res = await client.api.shares[':shareId'].files[':fileId'].$get( { - param: { shareId: shareInfo.id, fileId: currentFolderId }, + param: { shareId, fileId: currentFolderId! }, }, { headers: { @@ -73,11 +106,11 @@ export function PublicShareManager({ if (res.status === 401) throw new Error('Unauthorized') return (await res.json()) as unknown as AssetInfo }, - enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, + enabled: !!shareInfo && !!currentFolderId, }) useEffect(() => { - if (folderInfo?.ancestorFolders) { + if (folderInfo?.ancestorFolders && shareInfo) { // Filter ancestors to only those within the share root const rootIndex = folderInfo.ancestorFolders.findIndex((f) => f.id === shareInfo.rootFolderId) if (rootIndex !== -1) { @@ -86,7 +119,7 @@ export function PublicShareManager({ setAncestorFolders([]) } } - }, [folderInfo, shareInfo.rootFolderId, currentFolderId]) + }, [folderInfo, shareInfo, currentFolderId]) const [selectedIds, setSelectedIds] = useState>(new Set()) const [rightSidebarWidth, setRightSidebarWidth] = useState(360) @@ -103,11 +136,11 @@ export function PublicShareManager({ isFetchingNextPage: isFetchingNextFoldersPage, error: foldersError, } = useInfiniteQuery({ - queryKey: ['public-share-children', shareInfo.id, currentFolderId, 'folder', password], + queryKey: ['public-share-children', shareId, currentFolderId, 'folder', password], queryFn: async ({ pageParam }) => { const res = await client.api.shares[':shareId'].folders[':folderId'].children.$get( { - param: { shareId: shareInfo.id, folderId: currentFolderId }, + param: { shareId, folderId: currentFolderId! }, query: { assetType: 'folder', after: pageParam as string, @@ -123,7 +156,7 @@ export function PublicShareManager({ if (res.status === 403) throw new Error('Expired') return (await res.json()) as unknown as AssetInfoPaginatedList }, - enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, + enabled: !!shareInfo && !!currentFolderId, initialPageParam: '', getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined, retry: false, @@ -135,11 +168,11 @@ export function PublicShareManager({ hasNextPage: hasNextPageFiles, isFetchingNextPage: isFetchingNextFilesPage, } = useInfiniteQuery({ - queryKey: ['public-share-children', shareInfo.id, currentFolderId, 'file', password], + queryKey: ['public-share-children', shareId, currentFolderId, 'file', password], queryFn: async ({ pageParam }) => { const res = await client.api.shares[':shareId'].folders[':folderId'].children.$get( { - param: { shareId: shareInfo.id, folderId: currentFolderId }, + param: { shareId, folderId: currentFolderId! }, query: { assetType: 'file', after: pageParam as string, @@ -155,18 +188,18 @@ export function PublicShareManager({ if (res.status === 403) throw new Error('Expired') return (await res.json()) as unknown as AssetInfoPaginatedList }, - enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, + enabled: !!shareInfo && !!currentFolderId, initialPageParam: '', getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined, retry: false, }) const { data: publicFields } = useQuery({ - queryKey: ['public-share-fields', shareInfo.id, password], + queryKey: ['public-share-fields', shareId, password], queryFn: async () => { const res = await client.api.shares[':shareId'].fields.$get( { - param: { shareId: shareInfo.id }, + param: { shareId }, }, { headers: { @@ -177,15 +210,15 @@ export function PublicShareManager({ if (res.status === 401) throw new Error('Unauthorized') return (await res.json()) as unknown as FieldInfo[] }, - enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, + enabled: !!shareInfo, }) const { data: viewingFileData, isLoading: isViewingFileLoading } = useQuery({ - queryKey: ['public-share-file', shareInfo.id, viewingFileId, password], + queryKey: ['public-share-file', shareId, viewingFileId, password], queryFn: async () => { const res = await client.api.shares[':shareId'].files[':fileId'].$get( { - param: { shareId: shareInfo.id, fileId: viewingFileId! }, + param: { shareId, fileId: viewingFileId! }, }, { headers: { @@ -196,16 +229,15 @@ export function PublicShareManager({ if (res.status === 401) throw new Error('Unauthorized') return (await res.json()) as unknown as AssetInfo }, - enabled: !!viewingFileId && isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, + enabled: !!viewingFileId && !!shareInfo, }) useEffect(() => { if (foldersError?.message === 'Unauthorized') { - setIsPasswordValid(false) setPassword('') - localStorage.removeItem(`share_pwd_${shareInfo.id}`) + localStorage.removeItem(`share_pwd_${shareId}`) } - }, [foldersError, shareInfo.id]) + }, [foldersError, shareId]) const folders = useMemo( () => foldersData?.pages.flatMap((page) => page.data ?? []) ?? [], @@ -226,21 +258,20 @@ export function PublicShareManager({ const handlePasswordSubmit = (e: React.FormEvent) => { e.preventDefault() setPassword(passwordInput) - setIsPasswordValid(true) - localStorage.setItem(`share_pwd_${shareInfo.id}`, passwordInput) + localStorage.setItem(`share_pwd_${shareId}`, passwordInput) } const handleItemDoubleClick = (item: AssetInfo) => { if (item.type === 'folder' || item.targetType === 'folder') { navigate({ to: '/share/$shareId/folders/$folderId', - params: { shareId: shareInfo.id, folderId: item.id! }, + params: { shareId, folderId: item.id! }, }) } else { navigate({ to: '/share/$shareId/files/$fileId', params: { - shareId: shareInfo.id, + shareId, fileId: item.versionStack ? item.versionStack.id : item.id!, }, }) @@ -249,17 +280,18 @@ export function PublicShareManager({ } const handleBreadcrumbClick = (folderId: string) => { + if (!shareInfo) return const targetId = folderId === 'root' ? shareInfo.rootFolderId : folderId if (targetId === shareInfo.rootFolderId) { navigate({ to: '/share/$shareId', - params: { shareId: shareInfo.id }, + params: { shareId }, }) } else { navigate({ to: '/share/$shareId/folders/$folderId', - params: { shareId: shareInfo.id, folderId: targetId }, + params: { shareId, folderId: targetId }, }) } setSelectedIds(new Set()) @@ -294,7 +326,7 @@ export function PublicShareManager({ const { setProjectState, clearProjectState } = useTopNavStore() useEffect(() => { - if (isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled) { + if (shareInfo && currentFolderId) { const currentFolderName = currentFolderId === shareInfo.rootFolderId ? shareInfo.name @@ -315,7 +347,7 @@ export function PublicShareManager({ }, isRootFolder: currentFolderId === shareInfo.rootFolderId && !viewingFileId, isPublic: true, - shareId: shareInfo.id, + shareId, fileId: viewingFileId || undefined, onFolderClick: handleBreadcrumbClick, isRightSidebarCollapsed, @@ -325,7 +357,6 @@ export function PublicShareManager({ return () => clearProjectState() }, [ - isPasswordValid, shareInfo, currentFolderId, folders, @@ -339,49 +370,73 @@ export function PublicShareManager({ let content - if (shareInfo.isExpired || shareInfo.isDisabled) { + if (isShareInfoLoading && !shareInfoError) { content = ( -
- - -
- -
- Share {shareInfo.isDisabled ? 'Disabled' : 'Expired'} -
- - {shareInfo.isDisabled - ? 'This share link has been disabled by the owner.' - : 'This share link has expired and is no longer accessible.'} - -
+
+
) - } else if (!isPasswordValid) { + } else if (shareInfoError) { + if (shareInfoError.message === 'Unauthorized') { + const isPasswordWrong = password !== '' + content = ( +
+ + +
+ +
+ Password Protected +
+ +
+
+ setPasswordInput(e.target.value)} + autoFocus + /> + {isPasswordWrong && ( +

+ Incorrect password. Please try again. +

+ )} +
+ +
+
+
+
+ ) + } else { + const isExpired = shareInfoError.message.includes('expired') + const isDisabled = shareInfoError.message.includes('disabled') + content = ( +
+ + +
+ +
+ + {isExpired ? 'Share Expired' : isDisabled ? 'Share Disabled' : 'Error'} + +
+ + {shareInfoError.message} + +
+
+ ) + } + } else if (!shareInfo) { content = ( -
- - -
- -
- Password Protected -
- -
- setPasswordInput(e.target.value)} - autoFocus - /> - -
-
-
+
+
) } else { @@ -406,37 +461,39 @@ export function PublicShareManager({ )}
) : ( - { - if (e.metaKey || e.ctrlKey) { - const next = new Set(selectedIds) - if (next.has(item.id!)) next.delete(item.id!) - else next.add(item.id!) - setSelectedIds(next) - } else { - setSelectedIds(new Set([item.id!])) - } - }} - onItemDoubleClick={handleItemDoubleClick} - onSaveField={() => {}} - displayStyle={(shareInfo.viewMode as 'card' | 'list') ?? 'card'} - onClearSelection={() => setSelectedIds(new Set())} - fetchNextFoldersPage={fetchNextFoldersPage} - hasNextFoldersPage={hasNextPageFolders} - isFetchingNextFoldersPage={isFetchingNextFoldersPage} - fetchNextFilesPage={fetchNextFilesPage} - hasNextFilesPage={hasNextPageFiles} - isFetchingNextFilesPage={isFetchingNextFilesPage} - isShareView={true} - isPublic={true} - /> + currentFolderId && ( + { + if (e.metaKey || e.ctrlKey) { + const next = new Set(selectedIds) + if (next.has(item.id!)) next.delete(item.id!) + else next.add(item.id!) + setSelectedIds(next) + } else { + setSelectedIds(new Set([item.id!])) + } + }} + onItemDoubleClick={handleItemDoubleClick} + onSaveField={() => {}} + displayStyle={(shareInfo.viewMode as 'card' | 'list') ?? 'card'} + onClearSelection={() => setSelectedIds(new Set())} + fetchNextFoldersPage={fetchNextFoldersPage} + hasNextFoldersPage={hasNextPageFolders} + isFetchingNextFoldersPage={isFetchingNextFoldersPage} + fetchNextFilesPage={fetchNextFilesPage} + hasNextFilesPage={hasNextPageFiles} + isFetchingNextFilesPage={isFetchingNextFilesPage} + isShareView={true} + isPublic={true} + /> + ) )} {!isRightSidebarCollapsed && ( @@ -457,7 +514,7 @@ export function PublicShareManager({ publicFields={publicFields} onCommentSelect={handleCommentSelect} isPublic={true} - shareId={shareInfo.id} + shareId={shareId} currentTime={currentTime} onTyping={() => { if (videoRef.current) { diff --git a/packages/webui/components/share-settings-sidebar.tsx b/packages/webui/components/share-settings-sidebar.tsx index 6dbc71bd..6e6d4ac0 100644 --- a/packages/webui/components/share-settings-sidebar.tsx +++ b/packages/webui/components/share-settings-sidebar.tsx @@ -45,10 +45,14 @@ export function ShareSettingsSidebar({ onSortOrderChange, }: ShareSettingsSidebarProps) { const queryClient = useQueryClient() - const [password, setPassword] = useState('') + const [password, setPassword] = useState(shareLink.password || '') const [expireAt, setExpireAt] = useState( shareLink.expireAt ? new Date(shareLink.expireAt) : undefined, ) + + React.useEffect(() => { + setPassword(shareLink.password || '') + }, [shareLink.password]) const [isPasswordEnabled, setIsPasswordEnabled] = useState(shareLink.hasPassword) const [isExpireEnabled, setIsExpireEnabled] = useState(!!shareLink.expireAt) @@ -146,10 +150,10 @@ export function ShareSettingsSidebar({ {isPasswordEnabled && (
setPassword(e.target.value)} - placeholder={shareLink.hasPassword ? '••••••••' : 'Set password'} + placeholder="Enter password" className="text-xs" />