Compare commits

...
9 Commits
Author SHA1 Message Date
yiling 9325c71b51 Release v0.1.0 2026-06-22 21:45:39 +08:00
Yiling-J 2f746d3ce8 Merge pull request #150 from shumaiOne/feat/secure-share-info
feat(share): secure share info API and fix wrong password feedback
2026-06-22 20:53:56 +08:00
yiling bdceda4cb6 refactor(share): use custom strongly-typed error classes 2026-06-22 20:48:47 +08:00
yiling df6e392bf6 feat(share): expose raw password on settings page 2026-06-22 20:32:46 +08:00
yiling 48b2047a84 feat(share): secure share info API and fix wrong password feedback 2026-06-22 20:21:44 +08:00
yiling 2b360b2b2c chore(docker): update shumai image tag to latest 2026-06-22 15:52:00 +08:00
Yiling-J 5d19e6ddfa Merge pull request #149 from shumaiOne/fix-sidebar-overflow
fix(webui): truncate long folder, collection, and share link names in sidebar
2026-06-22 15:46:18 +08:00
yiling 5e70b6f3ee docs: add note blocks for running binaries under Bun runtime 2026-06-22 15:39:47 +08:00
yiling 8eab02ab28 fix(webui): truncate long folder, collection, and share link names in sidebar 2026-06-22 15:22:44 +08:00
32 changed files with 364 additions and 304 deletions
+3
View File
@@ -134,6 +134,9 @@ AWS_ENDPOINT_URL_S3=http://localhost
#### Step 6: Run Shumai #### Step 6: Run Shumai
> [!IMPORTANT]
> **For Bun Users:** Since the published package binaries contain a `#!/usr/bin/env node` shebang, running the global command directly (e.g., `shumai`) will execute under Node.js. If you installed with Bun and want to run under the Bun runtime, you must prefix all commands with `bun run --bun` (e.g., `bun run --bun shumai`, `bun run --bun shumai -d`, `bun run --bun shumai stop`).
Start the application from your workspace folder: Start the application from your workspace folder:
```bash ```bash
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/agent-app", "name": "@shumai/agent-app",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"bin": { "bin": {
+3
View File
@@ -26,6 +26,9 @@ export SHUMAI_API_KEY="your-developer-api-token"
## Usage ## Usage
> [!IMPORTANT]
> **For Bun Users:** Since the package binary contains a `#!/usr/bin/env node` shebang, running `shumai-cli` directly will run under Node.js. If you wish to run it using Bun, prefix the command with `bun run --bun` (e.g., `bun run --bun shumai-cli project ls`).
Run `shumai-cli` or query specific commands: Run `shumai-cli` or query specific commands:
```bash ```bash
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/cli", "name": "@shumai/cli",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"bin": { "bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/transcode-app", "name": "@shumai/transcode-app",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"bin": { "bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/web-app", "name": "@shumai/web-app",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"dependencies": { "dependencies": {
+1 -1
View File
@@ -17,7 +17,7 @@ services:
retries: 5 retries: 5
shumai: shumai:
image: shumaione/shumai:main image: shumaione/shumai:latest
container_name: shumai_app container_name: shumai_app
ports: ports:
- '3000:3000' - '3000:3000'
+3
View File
@@ -80,3 +80,6 @@ Run this on your sandboxed agent execution nodes (requires sandbox dependencies
npm install -g @shumai-one/shumai-agent npm install -g @shumai-one/shumai-agent
shumai-agent shumai-agent
``` ```
> [!IMPORTANT]
> **For Bun Users:** Since the worker package binaries contain a `#!/usr/bin/env node` shebang, running `shumai-transcode` or `shumai-agent` directly will run under Node.js. If you wish to run them using Bun, prefix the commands with `bun run --bun` (e.g., `bun run --bun shumai-transcode` or `bun run --bun shumai-agent`).
+5
View File
@@ -72,9 +72,14 @@ To handle media processing and security isolation, the host machine must have th
AWS_ENDPOINT_URL_S3=http://localhost AWS_ENDPOINT_URL_S3=http://localhost
``` ```
4. **Start Shumai**: 4. **Start Shumai**:
> [!IMPORTANT]
> **For Bun Users:** Since the published package binaries contain a `#!/usr/bin/env node` shebang, running `shumai` directly will execute under Node.js. If you installed using Bun and want to run it under the Bun runtime, prefix the command with `bun run --bun` (e.g., `bun run --bun shumai`).
```bash ```bash
shumai shumai
``` ```
Open your browser to `http://localhost:3000`. Open your browser to `http://localhost:3000`.
--- ---
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "shumai", "name": "shumai",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"repository": { "repository": {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/agent", "name": "@shumai/agent",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/api", "name": "@shumai/api",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+31 -41
View File
@@ -1,4 +1,5 @@
import { Hono } from 'hono' import { Hono } from 'hono'
import type { Context } from 'hono'
import { zValidator } from '@hono/zod-validator' import { zValidator } from '@hono/zod-validator'
import { shareService } from '@shumai/core/src/share/share' import { shareService } from '@shumai/core/src/share/share'
import { assetService } from '@shumai/core/src/asset/asset' 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 { prisma } from '@shumai/db'
import { createCommentRequestSchema } from '@shumai/dtos' import { createCommentRequestSchema } from '@shumai/dtos'
import { notificationService } from '@shumai/core/src/notification/notification' import { notificationService } from '@shumai/core/src/notification/notification'
import {
ShareLinkNotFoundError,
ShareLinkDisabledError,
ShareLinkExpiredError,
ShareLinkPasswordInvalidError,
} from '@shumai/core/src/share/errors'
const app = new Hono() 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({ const sharedChildrenRequestSchema = paginationParamsSchema.extend({
assetType: z.string().optional(), assetType: z.string().optional(),
}) })
@@ -37,8 +60,10 @@ const sharedChildrenRequestSchema = paginationParamsSchema.extend({
const route = app const route = app
.get('/shares/:shareId/info', async (c) => { .get('/shares/:shareId/info', async (c) => {
const shareId = c.req.param('shareId') const shareId = c.req.param('shareId')
const password = c.req.header('x-share-password')
try { try {
const shareLink = await shareService.getShareLink(shareId) const shareLink = await shareService.getShareLink(shareId)
await shareService.verifyPublicAccess(shareLink.rootFolderId, password)
return c.json({ return c.json({
id: shareLink.id, id: shareLink.id,
name: shareLink.name, name: shareLink.name,
@@ -52,7 +77,7 @@ const route = app
defaultSortOrder: shareLink.defaultSortOrder, defaultSortOrder: shareLink.defaultSortOrder,
}) })
} catch (err) { } catch (err) {
return c.json({ error: (err as Error).message }, 404) return handlePublicShareError(c, err)
} }
}) })
.get('/shares/:shareId/fields', async (c) => { .get('/shares/:shareId/fields', async (c) => {
@@ -72,14 +97,7 @@ const route = app
.map((f) => toFieldInfo(f.field, f.visible)), .map((f) => toFieldInfo(f.field, f.visible)),
) )
} catch (err) { } catch (err) {
const msg = (err as Error).message return handlePublicShareError(c, err)
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)
} }
}) })
.get( .get(
@@ -112,14 +130,7 @@ const route = app
return c.json(res) return c.json(res)
} catch (err) { } catch (err) {
const msg = (err as Error).message return handlePublicShareError(c, err)
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)
} }
}, },
) )
@@ -133,14 +144,7 @@ const route = app
const asset = await assetService.getAsset({ assetId: fileId }) const asset = await assetService.getAsset({ assetId: fileId })
return c.json(asset) return c.json(asset)
} catch (err) { } catch (err) {
const msg = (err as Error).message return handlePublicShareError(c, err)
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)
} }
}) })
.get( .get(
@@ -158,14 +162,7 @@ const route = app
const res = await assetService.listComments(targetFileId, req) const res = await assetService.listComments(targetFileId, req)
return c.json(res) return c.json(res)
} catch (err) { } catch (err) {
const msg = (err as Error).message return handlePublicShareError(c, err)
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)
} }
}, },
) )
@@ -237,14 +234,7 @@ const route = app
return c.json(comment, 201) return c.json(comment, 201)
} catch (err) { } catch (err) {
const msg = (err as Error).message return handlePublicShareError(c, err)
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)
} }
}, },
) )
+60
View File
@@ -6,6 +6,7 @@ import { authMiddleware } from './middleware/auth'
import { shareService } from '@shumai/core/src/share/share' import { shareService } from '@shumai/core/src/share/share'
import { assetService } from '@shumai/core/src/asset/asset' import { assetService } from '@shumai/core/src/asset/asset'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz' import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { ShareLinkPasswordInvalidError, ShareLinkExpiredError } from '@shumai/core/src/share/errors'
vi.mock('./middleware/auth', () => ({ vi.mock('./middleware/auth', () => ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -57,15 +58,74 @@ describe('Share API', () => {
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
updatedAt: 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', { const res = await app.request('/shares/share1/info', {
method: 'GET', method: 'GET',
headers: { 'x-share-password': 'pass' },
}) })
expect(res.status).toBe(200) expect(res.status).toBe(200)
const body = await res.json() const body = await res.json()
expect(body.name).toBe('Public Share') expect(body.name).toBe('Public Share')
expect(body.hasPassword).toBe(true) 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')
}) })
}) })
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/core", "name": "@shumai/core",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+31
View File
@@ -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)
}
}
+13 -6
View File
@@ -9,6 +9,12 @@ import {
} from '@shumai/dtos' } from '@shumai/dtos'
import { PaginatedData, paginateQuery } from '@shumai/core/src/pagination' import { PaginatedData, paginateQuery } from '@shumai/core/src/pagination'
import { getAvatarUrl } from '@shumai/core/src/user/avatar' import { getAvatarUrl } from '@shumai/core/src/user/avatar'
import {
ShareLinkNotFoundError,
ShareLinkDisabledError,
ShareLinkExpiredError,
ShareLinkPasswordInvalidError,
} from './errors'
export class ShareService { export class ShareService {
async createShareLink( async createShareLink(
@@ -143,7 +149,7 @@ export class ShareService {
where: { id: shareLinkId }, where: { id: shareLinkId },
include: { creator: true }, 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) return await this.toShareLinkInfo(shareLink)
} }
@@ -264,7 +270,7 @@ export class ShareService {
` `
if (rows.length === 0) { if (rows.length === 0) {
throw new Error('Asset is not shared') throw new ShareLinkNotFoundError('Asset is not shared')
} }
const shareRootId = rows[0].shareRootId const shareRootId = rows[0].shareRootId
@@ -273,19 +279,19 @@ export class ShareService {
}) })
if (!shareLink) { 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) { if (shareLink.isDisabled) {
throw new Error('Share link is disabled') throw new ShareLinkDisabledError('Share link is disabled')
} }
if (shareLink.expireAt && shareLink.expireAt < new Date()) { 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) { if (shareLink.password && shareLink.password !== providedPassword) {
throw new Error('Invalid password for share link') throw new ShareLinkPasswordInvalidError('Invalid password for share link')
} }
return shareLink return shareLink
@@ -301,6 +307,7 @@ export class ShareService {
expireAt: l.expireAt?.toISOString(), expireAt: l.expireAt?.toISOString(),
isDisabled: l.isDisabled, isDisabled: l.isDisabled,
hasPassword: !!l.password, hasPassword: !!l.password,
password: l.password,
defaultSortOrder: l.defaultSortOrder, defaultSortOrder: l.defaultSortOrder,
viewMode: l.viewMode, viewMode: l.viewMode,
fieldVisibility: l.fieldVisibility as Record<string, boolean> | undefined, fieldVisibility: l.fieldVisibility as Record<string, boolean> | undefined,
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/db", "name": "@shumai/db",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/dtos", "name": "@shumai/dtos",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1
View File
@@ -7,6 +7,7 @@ export interface ShareLinkInfo {
expireAt?: string expireAt?: string
isDisabled: boolean isDisabled: boolean
hasPassword: boolean hasPassword: boolean
password?: string | null
defaultSortOrder?: string defaultSortOrder?: string
viewMode?: string viewMode?: string
fieldVisibility?: Record<string, boolean> fieldVisibility?: Record<string, boolean>
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/tableprinter", "name": "@shumai/tableprinter",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/transcode", "name": "@shumai/transcode",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
+15 -12
View File
@@ -469,7 +469,7 @@ export function FolderTree({
<ScrollArea <ScrollArea
className={cn( className={cn(
'flex-1 min-h-0 transition-all duration-300 ease-in-out', 'flex-1 min-h-0 transition-all duration-300 ease-in-out [&>div>div]:block!',
isAssetsExpanded isAssetsExpanded
? 'opacity-100 visible pointer-events-auto' ? 'opacity-100 visible pointer-events-auto'
: 'opacity-0 invisible pointer-events-none h-0', : 'opacity-0 invisible pointer-events-none h-0',
@@ -569,7 +569,7 @@ export function FolderTree({
<ScrollArea <ScrollArea
className={cn( className={cn(
'flex-1 min-h-0 transition-all duration-300 ease-in-out', 'flex-1 min-h-0 transition-all duration-300 ease-in-out [&>div>div]:block!',
isCollectionsExpanded isCollectionsExpanded
? 'opacity-100 visible pointer-events-auto' ? 'opacity-100 visible pointer-events-auto'
: 'opacity-0 invisible pointer-events-none h-0', : 'opacity-0 invisible pointer-events-none h-0',
@@ -599,7 +599,7 @@ export function FolderTree({
<div <div
key={collection.id} key={collection.id}
className={cn( className={cn(
'group flex cursor-pointer items-center justify-between rounded-md px-2 py-1 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground', 'group flex cursor-pointer items-center justify-between rounded-md px-2 py-1 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground min-w-0',
isColActive && 'bg-sidebar-accent text-sidebar-accent-foreground font-medium', isColActive && 'bg-sidebar-accent text-sidebar-accent-foreground font-medium',
)} )}
onClick={() => onClick={() =>
@@ -620,7 +620,7 @@ export function FolderTree({
{canEdit && ( {canEdit && (
<div <div
className="opacity-0 group-hover:opacity-100 transition-opacity" className="opacity-0 group-hover:opacity-100 transition-opacity shrink-0"
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
> >
<DropdownMenu modal={false}> <DropdownMenu modal={false}>
@@ -705,7 +705,7 @@ export function FolderTree({
<ScrollArea <ScrollArea
className={cn( className={cn(
'flex-1 min-h-0 transition-all duration-300 ease-in-out', 'flex-1 min-h-0 transition-all duration-300 ease-in-out [&>div>div]:block!',
isSharesExpanded isSharesExpanded
? 'opacity-100 visible pointer-events-auto' ? 'opacity-100 visible pointer-events-auto'
: 'opacity-0 invisible pointer-events-none h-0', : 'opacity-0 invisible pointer-events-none h-0',
@@ -958,7 +958,7 @@ function ShareLinkItem({
<div <div
ref={setDroppableRef} ref={setDroppableRef}
className={cn( className={cn(
'group flex cursor-pointer items-center justify-between rounded-md px-2 py-1 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground', 'group flex cursor-pointer items-center justify-between rounded-md px-2 py-1 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground min-w-0',
isActive && 'bg-sidebar-accent text-sidebar-accent-foreground font-medium', isActive && 'bg-sidebar-accent text-sidebar-accent-foreground font-medium',
isOver && isValidDropTarget && 'bg-sidebar-accent ring-2 ring-primary ring-inset', isOver && isValidDropTarget && 'bg-sidebar-accent ring-2 ring-primary ring-inset',
)} )}
@@ -978,7 +978,7 @@ function ShareLinkItem({
{canEdit && ( {canEdit && (
<div <div
className="opacity-0 group-hover:opacity-100 transition-opacity" className="opacity-0 group-hover:opacity-100 transition-opacity shrink-0"
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
> >
<DropdownMenu modal={false}> <DropdownMenu modal={false}>
@@ -1176,7 +1176,7 @@ function FolderTreeItem({
<div <div
ref={setNodeRef} ref={setNodeRef}
className={cn( className={cn(
'group flex cursor-pointer items-center gap-1 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground', 'group flex cursor-pointer items-center gap-1 rounded-md px-2 py-1.5 text-sm transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground min-w-0',
(isActive || isSelected) && (isActive || isSelected) &&
'bg-sidebar-accent text-sidebar-accent-foreground font-medium', 'bg-sidebar-accent text-sidebar-accent-foreground font-medium',
isDragging && 'opacity-50', isDragging && 'opacity-50',
@@ -1188,7 +1188,10 @@ function FolderTreeItem({
onClick={handleFolderClick} onClick={handleFolderClick}
> >
{!isRoot && ( {!isRoot && (
<button onClick={handleToggleExpand} className="flex h-4 w-4 items-center justify-center"> <button
onClick={handleToggleExpand}
className="flex h-4 w-4 items-center justify-center shrink-0"
>
{isExpanded ? ( {isExpanded ? (
<ChevronDown className="h-3 w-3" /> <ChevronDown className="h-3 w-3" />
) : ( ) : (
@@ -1197,15 +1200,15 @@ function FolderTreeItem({
</button> </button>
)} )}
{isRoot ? ( {isRoot ? (
<Clapperboard className="h-4 w-4 text-sidebar-primary" /> <Clapperboard className="h-4 w-4 text-sidebar-primary shrink-0" />
) : ( ) : (
<Folder className="h-4 w-4 text-sidebar-primary" /> <Folder className="h-4 w-4 text-sidebar-primary shrink-0" />
)} )}
<span className="flex-1 truncate text-sidebar-foreground">{folder.name}</span> <span className="flex-1 truncate text-sidebar-foreground">{folder.name}</span>
{canEdit && !isRoot && ( {canEdit && !isRoot && (
<div <div
className="opacity-0 group-hover:opacity-100 transition-opacity" className="opacity-0 group-hover:opacity-100 transition-opacity shrink-0"
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
> >
<DropdownMenu modal={false}> <DropdownMenu modal={false}>
+173 -116
View File
@@ -21,48 +21,81 @@ import type { Annotation } from '@/ui/types'
import { useNavigate } from '@tanstack/react-router' import { useNavigate } from '@tanstack/react-router'
interface PublicShareManagerProps { interface PublicShareManagerProps {
shareInfo: { shareId: string
id: string
name: string
expireAt: string | null
isDisabled: boolean
isExpired: boolean
hasPassword: boolean
rootFolderId: string
projectId: string
viewMode?: string | null
defaultSortOrder?: string | null
}
initialFolderId?: string initialFolderId?: string
initialFileId?: string initialFileId?: string
startTime?: number 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({ export function PublicShareManager({
shareInfo, shareId,
initialFolderId, initialFolderId,
initialFileId, initialFileId,
startTime, startTime,
}: PublicShareManagerProps) { }: PublicShareManagerProps) {
const navigate = useNavigate() const navigate = useNavigate()
const [password, setPassword] = useState(() => { const [password, setPassword] = useState(() => {
return localStorage.getItem(`share_pwd_${shareInfo.id}`) || '' return localStorage.getItem(`share_pwd_${shareId}`) || ''
}) })
const [passwordInput, setPasswordInput] = useState('') const [passwordInput, setPasswordInput] = useState('')
const [isPasswordValid, setIsPasswordValid] = useState(!shareInfo.hasPassword || !!password)
const currentFolderId = initialFolderId || shareInfo.rootFolderId const {
data: shareInfo,
error: shareInfoError,
isLoading: isShareInfoLoading,
} = useQuery<PublicShareInfo>({
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 viewingFileId = initialFileId || null
const [ancestorFolders, setAncestorFolders] = useState<AncestorFolder[]>([]) const [ancestorFolders, setAncestorFolders] = useState<AncestorFolder[]>([])
// Fetch ancestors for breadcrumb // Fetch ancestors for breadcrumb
const { data: folderInfo } = useQuery({ const { data: folderInfo } = useQuery({
queryKey: ['public-share-folder', shareInfo.id, currentFolderId, password], queryKey: ['public-share-folder', shareId, currentFolderId, password],
queryFn: async () => { queryFn: async () => {
const res = await client.api.shares[':shareId'].files[':fileId'].$get( const res = await client.api.shares[':shareId'].files[':fileId'].$get(
{ {
param: { shareId: shareInfo.id, fileId: currentFolderId }, param: { shareId, fileId: currentFolderId! },
}, },
{ {
headers: { headers: {
@@ -73,11 +106,11 @@ export function PublicShareManager({
if (res.status === 401) throw new Error('Unauthorized') if (res.status === 401) throw new Error('Unauthorized')
return (await res.json()) as unknown as AssetInfo return (await res.json()) as unknown as AssetInfo
}, },
enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, enabled: !!shareInfo && !!currentFolderId,
}) })
useEffect(() => { useEffect(() => {
if (folderInfo?.ancestorFolders) { if (folderInfo?.ancestorFolders && shareInfo) {
// Filter ancestors to only those within the share root // Filter ancestors to only those within the share root
const rootIndex = folderInfo.ancestorFolders.findIndex((f) => f.id === shareInfo.rootFolderId) const rootIndex = folderInfo.ancestorFolders.findIndex((f) => f.id === shareInfo.rootFolderId)
if (rootIndex !== -1) { if (rootIndex !== -1) {
@@ -86,7 +119,7 @@ export function PublicShareManager({
setAncestorFolders([]) setAncestorFolders([])
} }
} }
}, [folderInfo, shareInfo.rootFolderId, currentFolderId]) }, [folderInfo, shareInfo, currentFolderId])
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set()) const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set())
const [rightSidebarWidth, setRightSidebarWidth] = useState(360) const [rightSidebarWidth, setRightSidebarWidth] = useState(360)
@@ -103,11 +136,11 @@ export function PublicShareManager({
isFetchingNextPage: isFetchingNextFoldersPage, isFetchingNextPage: isFetchingNextFoldersPage,
error: foldersError, error: foldersError,
} = useInfiniteQuery<AssetInfoPaginatedList>({ } = useInfiniteQuery<AssetInfoPaginatedList>({
queryKey: ['public-share-children', shareInfo.id, currentFolderId, 'folder', password], queryKey: ['public-share-children', shareId, currentFolderId, 'folder', password],
queryFn: async ({ pageParam }) => { queryFn: async ({ pageParam }) => {
const res = await client.api.shares[':shareId'].folders[':folderId'].children.$get( const res = await client.api.shares[':shareId'].folders[':folderId'].children.$get(
{ {
param: { shareId: shareInfo.id, folderId: currentFolderId }, param: { shareId, folderId: currentFolderId! },
query: { query: {
assetType: 'folder', assetType: 'folder',
after: pageParam as string, after: pageParam as string,
@@ -123,7 +156,7 @@ export function PublicShareManager({
if (res.status === 403) throw new Error('Expired') if (res.status === 403) throw new Error('Expired')
return (await res.json()) as unknown as AssetInfoPaginatedList return (await res.json()) as unknown as AssetInfoPaginatedList
}, },
enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, enabled: !!shareInfo && !!currentFolderId,
initialPageParam: '', initialPageParam: '',
getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined, getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined,
retry: false, retry: false,
@@ -135,11 +168,11 @@ export function PublicShareManager({
hasNextPage: hasNextPageFiles, hasNextPage: hasNextPageFiles,
isFetchingNextPage: isFetchingNextFilesPage, isFetchingNextPage: isFetchingNextFilesPage,
} = useInfiniteQuery<AssetInfoPaginatedList>({ } = useInfiniteQuery<AssetInfoPaginatedList>({
queryKey: ['public-share-children', shareInfo.id, currentFolderId, 'file', password], queryKey: ['public-share-children', shareId, currentFolderId, 'file', password],
queryFn: async ({ pageParam }) => { queryFn: async ({ pageParam }) => {
const res = await client.api.shares[':shareId'].folders[':folderId'].children.$get( const res = await client.api.shares[':shareId'].folders[':folderId'].children.$get(
{ {
param: { shareId: shareInfo.id, folderId: currentFolderId }, param: { shareId, folderId: currentFolderId! },
query: { query: {
assetType: 'file', assetType: 'file',
after: pageParam as string, after: pageParam as string,
@@ -155,18 +188,18 @@ export function PublicShareManager({
if (res.status === 403) throw new Error('Expired') if (res.status === 403) throw new Error('Expired')
return (await res.json()) as unknown as AssetInfoPaginatedList return (await res.json()) as unknown as AssetInfoPaginatedList
}, },
enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, enabled: !!shareInfo && !!currentFolderId,
initialPageParam: '', initialPageParam: '',
getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined, getNextPageParam: (lastPage) => lastPage.pageInfo?.cursor || undefined,
retry: false, retry: false,
}) })
const { data: publicFields } = useQuery({ const { data: publicFields } = useQuery({
queryKey: ['public-share-fields', shareInfo.id, password], queryKey: ['public-share-fields', shareId, password],
queryFn: async () => { queryFn: async () => {
const res = await client.api.shares[':shareId'].fields.$get( const res = await client.api.shares[':shareId'].fields.$get(
{ {
param: { shareId: shareInfo.id }, param: { shareId },
}, },
{ {
headers: { headers: {
@@ -177,15 +210,15 @@ export function PublicShareManager({
if (res.status === 401) throw new Error('Unauthorized') if (res.status === 401) throw new Error('Unauthorized')
return (await res.json()) as unknown as FieldInfo[] return (await res.json()) as unknown as FieldInfo[]
}, },
enabled: isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, enabled: !!shareInfo,
}) })
const { data: viewingFileData, isLoading: isViewingFileLoading } = useQuery({ const { data: viewingFileData, isLoading: isViewingFileLoading } = useQuery({
queryKey: ['public-share-file', shareInfo.id, viewingFileId, password], queryKey: ['public-share-file', shareId, viewingFileId, password],
queryFn: async () => { queryFn: async () => {
const res = await client.api.shares[':shareId'].files[':fileId'].$get( const res = await client.api.shares[':shareId'].files[':fileId'].$get(
{ {
param: { shareId: shareInfo.id, fileId: viewingFileId! }, param: { shareId, fileId: viewingFileId! },
}, },
{ {
headers: { headers: {
@@ -196,16 +229,15 @@ export function PublicShareManager({
if (res.status === 401) throw new Error('Unauthorized') if (res.status === 401) throw new Error('Unauthorized')
return (await res.json()) as unknown as AssetInfo return (await res.json()) as unknown as AssetInfo
}, },
enabled: !!viewingFileId && isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled, enabled: !!viewingFileId && !!shareInfo,
}) })
useEffect(() => { useEffect(() => {
if (foldersError?.message === 'Unauthorized') { if (foldersError?.message === 'Unauthorized') {
setIsPasswordValid(false)
setPassword('') setPassword('')
localStorage.removeItem(`share_pwd_${shareInfo.id}`) localStorage.removeItem(`share_pwd_${shareId}`)
} }
}, [foldersError, shareInfo.id]) }, [foldersError, shareId])
const folders = useMemo( const folders = useMemo(
() => foldersData?.pages.flatMap((page) => page.data ?? []) ?? [], () => foldersData?.pages.flatMap((page) => page.data ?? []) ?? [],
@@ -226,21 +258,20 @@ export function PublicShareManager({
const handlePasswordSubmit = (e: React.FormEvent) => { const handlePasswordSubmit = (e: React.FormEvent) => {
e.preventDefault() e.preventDefault()
setPassword(passwordInput) setPassword(passwordInput)
setIsPasswordValid(true) localStorage.setItem(`share_pwd_${shareId}`, passwordInput)
localStorage.setItem(`share_pwd_${shareInfo.id}`, passwordInput)
} }
const handleItemDoubleClick = (item: AssetInfo) => { const handleItemDoubleClick = (item: AssetInfo) => {
if (item.type === 'folder' || item.targetType === 'folder') { if (item.type === 'folder' || item.targetType === 'folder') {
navigate({ navigate({
to: '/share/$shareId/folders/$folderId', to: '/share/$shareId/folders/$folderId',
params: { shareId: shareInfo.id, folderId: item.id! }, params: { shareId, folderId: item.id! },
}) })
} else { } else {
navigate({ navigate({
to: '/share/$shareId/files/$fileId', to: '/share/$shareId/files/$fileId',
params: { params: {
shareId: shareInfo.id, shareId,
fileId: item.versionStack ? item.versionStack.id : item.id!, fileId: item.versionStack ? item.versionStack.id : item.id!,
}, },
}) })
@@ -249,17 +280,18 @@ export function PublicShareManager({
} }
const handleBreadcrumbClick = (folderId: string) => { const handleBreadcrumbClick = (folderId: string) => {
if (!shareInfo) return
const targetId = folderId === 'root' ? shareInfo.rootFolderId : folderId const targetId = folderId === 'root' ? shareInfo.rootFolderId : folderId
if (targetId === shareInfo.rootFolderId) { if (targetId === shareInfo.rootFolderId) {
navigate({ navigate({
to: '/share/$shareId', to: '/share/$shareId',
params: { shareId: shareInfo.id }, params: { shareId },
}) })
} else { } else {
navigate({ navigate({
to: '/share/$shareId/folders/$folderId', to: '/share/$shareId/folders/$folderId',
params: { shareId: shareInfo.id, folderId: targetId }, params: { shareId, folderId: targetId },
}) })
} }
setSelectedIds(new Set()) setSelectedIds(new Set())
@@ -294,7 +326,7 @@ export function PublicShareManager({
const { setProjectState, clearProjectState } = useTopNavStore() const { setProjectState, clearProjectState } = useTopNavStore()
useEffect(() => { useEffect(() => {
if (isPasswordValid && !shareInfo.isExpired && !shareInfo.isDisabled) { if (shareInfo && currentFolderId) {
const currentFolderName = const currentFolderName =
currentFolderId === shareInfo.rootFolderId currentFolderId === shareInfo.rootFolderId
? shareInfo.name ? shareInfo.name
@@ -315,7 +347,7 @@ export function PublicShareManager({
}, },
isRootFolder: currentFolderId === shareInfo.rootFolderId && !viewingFileId, isRootFolder: currentFolderId === shareInfo.rootFolderId && !viewingFileId,
isPublic: true, isPublic: true,
shareId: shareInfo.id, shareId,
fileId: viewingFileId || undefined, fileId: viewingFileId || undefined,
onFolderClick: handleBreadcrumbClick, onFolderClick: handleBreadcrumbClick,
isRightSidebarCollapsed, isRightSidebarCollapsed,
@@ -325,7 +357,6 @@ export function PublicShareManager({
return () => clearProjectState() return () => clearProjectState()
}, [ }, [
isPasswordValid,
shareInfo, shareInfo,
currentFolderId, currentFolderId,
folders, folders,
@@ -339,49 +370,73 @@ export function PublicShareManager({
let content let content
if (shareInfo.isExpired || shareInfo.isDisabled) { if (isShareInfoLoading && !shareInfoError) {
content = ( content = (
<div className="flex flex-1 items-center justify-center p-4"> <div className="flex flex-1 items-center justify-center bg-background">
<Card className="w-full max-w-md"> <Loader2 className="h-8 w-8 animate-spin text-foreground" />
<CardHeader className="text-center">
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10">
<AlertCircle className="h-6 w-6 text-destructive" />
</div>
<CardTitle>Share {shareInfo.isDisabled ? 'Disabled' : 'Expired'}</CardTitle>
</CardHeader>
<CardContent className="text-center text-muted-foreground">
{shareInfo.isDisabled
? 'This share link has been disabled by the owner.'
: 'This share link has expired and is no longer accessible.'}
</CardContent>
</Card>
</div> </div>
) )
} else if (!isPasswordValid) { } else if (shareInfoError) {
if (shareInfoError.message === 'Unauthorized') {
const isPasswordWrong = password !== ''
content = (
<div className="flex flex-1 items-center justify-center p-4">
<Card className="w-full max-w-md">
<CardHeader className="text-center">
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-primary/10">
<Lock className="h-6 w-6 text-primary" />
</div>
<CardTitle>Password Protected</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handlePasswordSubmit} className="space-y-4">
<div className="space-y-2">
<Input
type="password"
placeholder="Enter password"
value={passwordInput}
onChange={(e) => setPasswordInput(e.target.value)}
autoFocus
/>
{isPasswordWrong && (
<p className="text-sm font-medium text-destructive">
Incorrect password. Please try again.
</p>
)}
</div>
<Button type="submit" className="w-full">
Access Share
</Button>
</form>
</CardContent>
</Card>
</div>
)
} else {
const isExpired = shareInfoError.message.includes('expired')
const isDisabled = shareInfoError.message.includes('disabled')
content = (
<div className="flex flex-1 items-center justify-center p-4">
<Card className="w-full max-w-md">
<CardHeader className="text-center">
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10">
<AlertCircle className="h-6 w-6 text-destructive" />
</div>
<CardTitle>
{isExpired ? 'Share Expired' : isDisabled ? 'Share Disabled' : 'Error'}
</CardTitle>
</CardHeader>
<CardContent className="text-center text-muted-foreground">
{shareInfoError.message}
</CardContent>
</Card>
</div>
)
}
} else if (!shareInfo) {
content = ( content = (
<div className="flex flex-1 items-center justify-center p-4"> <div className="flex flex-1 items-center justify-center bg-background">
<Card className="w-full max-w-md"> <Loader2 className="h-8 w-8 animate-spin text-foreground" />
<CardHeader className="text-center">
<div className="mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-primary/10">
<Lock className="h-6 w-6 text-primary" />
</div>
<CardTitle>Password Protected</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handlePasswordSubmit} className="space-y-4">
<Input
type="password"
placeholder="Enter password"
value={passwordInput}
onChange={(e) => setPasswordInput(e.target.value)}
autoFocus
/>
<Button type="submit" className="w-full">
Access Share
</Button>
</form>
</CardContent>
</Card>
</div> </div>
) )
} else { } else {
@@ -406,37 +461,39 @@ export function PublicShareManager({
)} )}
</div> </div>
) : ( ) : (
<FileBrowser currentFolderId && (
teamId="" <FileBrowser
projectId={shareInfo.projectId} teamId=""
assetId={currentFolderId} projectId={shareInfo.projectId}
folders={folders} assetId={currentFolderId}
files={files} folders={folders}
selectedItem={null} files={files}
selectedIds={selectedIds} selectedItem={null}
onItemSelect={(item, e) => { selectedIds={selectedIds}
if (e.metaKey || e.ctrlKey) { onItemSelect={(item, e) => {
const next = new Set(selectedIds) if (e.metaKey || e.ctrlKey) {
if (next.has(item.id!)) next.delete(item.id!) const next = new Set(selectedIds)
else next.add(item.id!) if (next.has(item.id!)) next.delete(item.id!)
setSelectedIds(next) else next.add(item.id!)
} else { setSelectedIds(next)
setSelectedIds(new Set([item.id!])) } else {
} setSelectedIds(new Set([item.id!]))
}} }
onItemDoubleClick={handleItemDoubleClick} }}
onSaveField={() => {}} onItemDoubleClick={handleItemDoubleClick}
displayStyle={(shareInfo.viewMode as 'card' | 'list') ?? 'card'} onSaveField={() => {}}
onClearSelection={() => setSelectedIds(new Set())} displayStyle={(shareInfo.viewMode as 'card' | 'list') ?? 'card'}
fetchNextFoldersPage={fetchNextFoldersPage} onClearSelection={() => setSelectedIds(new Set())}
hasNextFoldersPage={hasNextPageFolders} fetchNextFoldersPage={fetchNextFoldersPage}
isFetchingNextFoldersPage={isFetchingNextFoldersPage} hasNextFoldersPage={hasNextPageFolders}
fetchNextFilesPage={fetchNextFilesPage} isFetchingNextFoldersPage={isFetchingNextFoldersPage}
hasNextFilesPage={hasNextPageFiles} fetchNextFilesPage={fetchNextFilesPage}
isFetchingNextFilesPage={isFetchingNextFilesPage} hasNextFilesPage={hasNextPageFiles}
isShareView={true} isFetchingNextFilesPage={isFetchingNextFilesPage}
isPublic={true} isShareView={true}
/> isPublic={true}
/>
)
)} )}
{!isRightSidebarCollapsed && ( {!isRightSidebarCollapsed && (
@@ -457,7 +514,7 @@ export function PublicShareManager({
publicFields={publicFields} publicFields={publicFields}
onCommentSelect={handleCommentSelect} onCommentSelect={handleCommentSelect}
isPublic={true} isPublic={true}
shareId={shareInfo.id} shareId={shareId}
currentTime={currentTime} currentTime={currentTime}
onTyping={() => { onTyping={() => {
if (videoRef.current) { if (videoRef.current) {
@@ -45,10 +45,14 @@ export function ShareSettingsSidebar({
onSortOrderChange, onSortOrderChange,
}: ShareSettingsSidebarProps) { }: ShareSettingsSidebarProps) {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const [password, setPassword] = useState('') const [password, setPassword] = useState(shareLink.password || '')
const [expireAt, setExpireAt] = useState<Date | undefined>( const [expireAt, setExpireAt] = useState<Date | undefined>(
shareLink.expireAt ? new Date(shareLink.expireAt) : undefined, shareLink.expireAt ? new Date(shareLink.expireAt) : undefined,
) )
React.useEffect(() => {
setPassword(shareLink.password || '')
}, [shareLink.password])
const [isPasswordEnabled, setIsPasswordEnabled] = useState(shareLink.hasPassword) const [isPasswordEnabled, setIsPasswordEnabled] = useState(shareLink.hasPassword)
const [isExpireEnabled, setIsExpireEnabled] = useState(!!shareLink.expireAt) const [isExpireEnabled, setIsExpireEnabled] = useState(!!shareLink.expireAt)
@@ -146,10 +150,10 @@ export function ShareSettingsSidebar({
{isPasswordEnabled && ( {isPasswordEnabled && (
<div className="flex gap-2 animate-in fade-in slide-in-from-top-1 duration-200"> <div className="flex gap-2 animate-in fade-in slide-in-from-top-1 duration-200">
<Input <Input
type="password" type="text"
value={password} value={password}
onChange={(e) => setPassword(e.target.value)} onChange={(e) => setPassword(e.target.value)}
placeholder={shareLink.hasPassword ? '••••••••' : 'Set password'} placeholder="Enter password"
className="text-xs" className="text-xs"
/> />
<Button size="sm" onClick={() => updateShare({ password })}> <Button size="sm" onClick={() => updateShare({ password })}>
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/webui", "name": "@shumai/webui",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./index.html", "main": "./index.html",
-34
View File
@@ -1,43 +1,9 @@
import { client } from '@/ui/api/client'
import { ProjectFolderSkeleton } from '@/ui/components/loading-skeletons'
import { useQuery } from '@tanstack/react-query'
import { createFileRoute, Outlet } from '@tanstack/react-router' import { createFileRoute, Outlet } from '@tanstack/react-router'
function ShareLayout() { function ShareLayout() {
const { shareId } = Route.useParams()
const {
data: shareInfo,
isLoading,
error,
} = useQuery({
queryKey: ['share-info', shareId],
queryFn: async () => {
const res = await client.api.shares[':shareId'].info.$get({
param: { shareId },
})
if (!res.ok) throw new Error('Failed to fetch share info')
return await res.json()
},
})
if (isLoading) return <ProjectFolderSkeleton />
if (error || !shareInfo)
return (
<div className="flex h-screen items-center justify-center text-destructive">
Share not found or inaccessible.
</div>
)
return <Outlet /> return <Outlet />
} }
export const Route = createFileRoute('/share/$shareId')({ export const Route = createFileRoute('/share/$shareId')({
component: ShareLayout, component: ShareLayout,
beforeLoad: ({ params: { shareId } }) => {
return {
password: localStorage.getItem(`share_pwd_${shareId}`) || '',
}
},
}) })
@@ -1,36 +1,11 @@
import { client } from '@/ui/api/client'
import { PublicShareManager } from '@/ui/components/public-share-manager' import { PublicShareManager } from '@/ui/components/public-share-manager'
import { useQuery } from '@tanstack/react-query'
import { createFileRoute } from '@tanstack/react-router' import { createFileRoute } from '@tanstack/react-router'
function PublicShareFilePage() { function PublicShareFilePage() {
const { shareId, fileId } = Route.useParams() const { shareId, fileId } = Route.useParams()
const { start } = Route.useSearch() const { start } = Route.useSearch()
const { data: shareInfo } = useQuery({ return <PublicShareManager shareId={shareId} initialFileId={fileId} startTime={start} />
queryKey: ['share-info', shareId],
queryFn: async () => {
const res = await client.api.shares[':shareId'].info.$get({
param: { shareId },
})
if (!res.ok) throw new Error('Failed to fetch share info')
return await res.json()
},
})
if (!shareInfo) return null
return (
<PublicShareManager
shareInfo={{
...shareInfo,
expireAt: shareInfo.expireAt ?? null,
isDisabled: shareInfo.isDisabled ?? false,
}}
initialFileId={fileId}
startTime={start}
/>
)
} }
export const Route = createFileRoute('/share/$shareId/files/$fileId')({ export const Route = createFileRoute('/share/$shareId/files/$fileId')({
@@ -1,34 +1,10 @@
import { client } from '@/ui/api/client'
import { PublicShareManager } from '@/ui/components/public-share-manager' import { PublicShareManager } from '@/ui/components/public-share-manager'
import { useQuery } from '@tanstack/react-query'
import { createFileRoute } from '@tanstack/react-router' import { createFileRoute } from '@tanstack/react-router'
function PublicShareFolderPage() { function PublicShareFolderPage() {
const { shareId, folderId } = Route.useParams() const { shareId, folderId } = Route.useParams()
const { data: shareInfo } = useQuery({ return <PublicShareManager shareId={shareId} initialFolderId={folderId} />
queryKey: ['share-info', shareId],
queryFn: async () => {
const res = await client.api.shares[':shareId'].info.$get({
param: { shareId },
})
if (!res.ok) throw new Error('Failed to fetch share info')
return await res.json()
},
})
if (!shareInfo) return null
return (
<PublicShareManager
shareInfo={{
...shareInfo,
expireAt: shareInfo.expireAt ?? null,
isDisabled: shareInfo.isDisabled ?? false,
}}
initialFolderId={folderId}
/>
)
} }
export const Route = createFileRoute('/share/$shareId/folders/$folderId')({ export const Route = createFileRoute('/share/$shareId/folders/$folderId')({
+1 -25
View File
@@ -1,34 +1,10 @@
import { client } from '@/ui/api/client'
import { PublicShareManager } from '@/ui/components/public-share-manager' import { PublicShareManager } from '@/ui/components/public-share-manager'
import { useQuery } from '@tanstack/react-query'
import { createFileRoute } from '@tanstack/react-router' import { createFileRoute } from '@tanstack/react-router'
function PublicShareIndexPage() { function PublicShareIndexPage() {
const { shareId } = Route.useParams() const { shareId } = Route.useParams()
const { data: shareInfo } = useQuery({ return <PublicShareManager shareId={shareId} />
queryKey: ['share-info', shareId],
queryFn: async () => {
const res = await client.api.shares[':shareId'].info.$get({
param: { shareId },
})
if (!res.ok) throw new Error('Failed to fetch share info')
return await res.json()
},
})
if (!shareInfo) return null
return (
<PublicShareManager
shareInfo={{
...shareInfo,
expireAt: shareInfo.expireAt ?? null,
isDisabled: shareInfo.isDisabled ?? false,
}}
initialFolderId={shareInfo.rootFolderId}
/>
)
} }
export const Route = createFileRoute('/share/$shareId/')({ export const Route = createFileRoute('/share/$shareId/')({
+1 -1
View File
@@ -1 +1 @@
export const APP_VERSION = '0.0.11' export const APP_VERSION = '0.1.0'
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@shumai/workflow-core", "name": "@shumai/workflow-core",
"version": "0.0.11", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",