feat(share): add allow download config to share links (#275)

* feat(share): add allow download config to share links

* fix(share): hide download in public share list page when disabled
This commit is contained in:
Yiling-J
2026-08-08 10:25:02 +08:00
committed by GitHub
parent 70b6c33204
commit d3f5892dd2
39 changed files with 572 additions and 208 deletions
+11 -1
View File
@@ -19,6 +19,7 @@ import {
ShareLinkDisabledError,
ShareLinkExpiredError,
ShareLinkPasswordInvalidError,
ShareLinkDownloadDisabledError,
} from '@shumai/core/src/share/errors'
import { s3Service } from '@shumai/core/src/s3/s3'
import type { AssetInfo } from '@shumai/dtos'
@@ -104,6 +105,10 @@ export function handlePublicShareError(c: Context, err: unknown) {
const msg = err instanceof Error ? err.message : String(err)
return c.json({ error: msg }, 403)
}
if (err instanceof ShareLinkDownloadDisabledError) {
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)
@@ -128,6 +133,7 @@ const route = app
name: shareLink.name,
expireAt: shareLink.expireAt,
isDisabled: shareLink.isDisabled,
allowDownload: shareLink.allowDownload,
isExpired: shareLink.isExpired,
hasPassword: shareLink.hasPassword,
rootFolderId: shareLink.rootFolderId,
@@ -248,7 +254,11 @@ const route = app
const { key } = c.req.valid('json')
try {
await shareService.verifyPublicAccess(fileId, password)
const shareLink = await shareService.verifyPublicAccess(fileId, password)
if (!shareLink.allowDownload) {
throw new ShareLinkDownloadDisabledError('Download is disabled for this share link')
}
if (!key.startsWith('files/')) {
return c.json({ error: 'Invalid key' }, 400)
+67 -3
View File
@@ -96,6 +96,7 @@ describe('Share API', () => {
id: 'share1',
name: 'Public Share',
isDisabled: false,
allowDownload: false,
isExpired: false,
hasPassword: true,
rootFolderId: 'folder1',
@@ -119,6 +120,7 @@ describe('Share API', () => {
const body = await res.json()
expect(body.name).toBe('Public Share')
expect(body.hasPassword).toBe(true)
expect(body.allowDownload).toBe(false)
expect(shareService.verifyPublicAccess).toHaveBeenCalledWith('folder1', 'pass')
})
@@ -127,6 +129,7 @@ describe('Share API', () => {
id: 'share1',
name: 'Public Share',
isDisabled: false,
allowDownload: false,
isExpired: false,
hasPassword: true,
rootFolderId: 'folder1',
@@ -153,6 +156,7 @@ describe('Share API', () => {
id: 'share1',
name: 'Public Share',
isDisabled: false,
allowDownload: false,
isExpired: false,
hasPassword: true,
rootFolderId: 'folder1',
@@ -180,6 +184,7 @@ describe('Share API', () => {
id: 'share1',
name: 'My Share',
isDisabled: false,
allowDownload: false,
rootFolderId: 'folder1',
projectId: 'project1',
password: null,
@@ -217,6 +222,7 @@ describe('Share API', () => {
id: 'share1',
name: 'My Share',
isDisabled: false,
allowDownload: false,
rootFolderId: 'folder1',
projectId: 'project1',
password: null,
@@ -338,6 +344,7 @@ describe('Share API', () => {
id: 'share1',
name: 'My Share',
isDisabled: false,
allowDownload: false,
rootFolderId: 'folder1',
projectId: 'project1',
password: null,
@@ -465,6 +472,7 @@ describe('Share API', () => {
id: 'share1',
name: 'My Share',
isDisabled: false,
allowDownload: false,
rootFolderId: 'folder1',
projectId: 'project1',
password: null,
@@ -502,6 +510,7 @@ describe('Share API', () => {
id: 'share1',
name: 'test-share',
isDisabled: false,
allowDownload: false,
rootFolderId: 'root1',
projectId: 'project1',
isExpired: false,
@@ -539,6 +548,34 @@ describe('Share API', () => {
itemId: 'share1',
})
})
test('Passes allowDownload to service', async () => {
vi.spyOn(shareService, 'createShareLink').mockResolvedValue({
id: 'share1',
name: 'test-share',
isDisabled: false,
allowDownload: false,
rootFolderId: 'root1',
projectId: 'project1',
isExpired: false,
hasPassword: false,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
const res = await app.request('/projects/project1/shares', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'My Share', allowDownload: false }),
})
expect(res.status).toBe(200)
expect(shareService.createShareLink).toHaveBeenCalledWith(
'project1',
{ name: 'My Share', allowDownload: false },
'user1',
)
})
})
describe('GET /projects/:projectId/shares', () => {
@@ -574,6 +611,7 @@ describe('Share API', () => {
id: 'share1',
name: 'test-share',
isDisabled: false,
allowDownload: false,
rootFolderId: 'root1',
projectId: 'project1',
isExpired: false,
@@ -604,6 +642,7 @@ describe('Share API', () => {
id: 'share1',
name: 'test-share',
isDisabled: false,
allowDownload: false,
rootFolderId: 'root1',
projectId: 'project1',
isExpired: false,
@@ -647,6 +686,7 @@ describe('Share API', () => {
id: 'share1',
name: 'test-share',
isDisabled: false,
allowDownload: false,
rootFolderId: 'root1',
projectId: 'project1',
isExpired: false,
@@ -739,9 +779,10 @@ describe('Share API', () => {
describe('POST /shares/:shareId/files/:fileId/download-url', () => {
test('Success for symlink asset in share', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(
{} as unknown as Awaited<ReturnType<typeof shareService.verifyPublicAccess>>,
)
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
allowDownload: true,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any)
vi.spyOn(assetService, 'getDownloadUrl').mockResolvedValue('https://s3.example.com/download')
const res = await app.request('/shares/share1/files/symlink1/download-url', {
@@ -756,5 +797,28 @@ describe('Share API', () => {
expect(shareService.verifyPublicAccess).toHaveBeenCalledWith('symlink1', undefined)
expect(assetService.getDownloadUrl).toHaveBeenCalledWith('symlink1', 'files/target1/fly.png')
})
test('Rejects when allowDownload is disabled', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
id: 'share1',
name: 'No Download',
allowDownload: false,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any)
const getDownloadUrlSpy = vi
.spyOn(assetService, 'getDownloadUrl')
.mockResolvedValue('https://s3.example.com/download')
const res = await app.request('/shares/share1/files/symlink1/download-url', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: 'files/target1/fly.png' }),
})
expect(res.status).toBe(403)
const body = await res.json()
expect(body.error).toBe('Download is disabled for this share link')
expect(getDownloadUrlSpy).not.toHaveBeenCalled()
})
})
})
+8
View File
@@ -30,6 +30,14 @@ export class ShareLinkPasswordInvalidError extends Error {
}
}
export class ShareLinkDownloadDisabledError extends Error {
constructor(message: string) {
super(message)
this.name = 'ShareLinkDownloadDisabledError'
Object.setPrototypeOf(this, ShareLinkDownloadDisabledError.prototype)
}
}
export class ShareLinkWatermarkProcessingError extends Error {
constructor(message = 'Watermark transcoding is currently in progress') {
super(message)
+24
View File
@@ -53,6 +53,7 @@ describe('ShareService', () => {
})
expect(shareLink.name).toBe('Public Share')
expect(shareLink.allowDownload).toBe(true)
expect(shareLink.rootFolderId).toBeDefined()
const asset = await prisma.asset.findUnique({
@@ -62,6 +63,18 @@ describe('ShareService', () => {
expect(asset?.projectId).toBe(projectId)
})
it('creates a share link with allowDownload disabled', async () => {
const shareLink = await shareService.createShareLink(projectId, {
name: 'No Download Share',
allowDownload: false,
})
expect(shareLink.allowDownload).toBe(false)
const fetched = await shareService.getShareLink(shareLink.id)
expect(fetched.allowDownload).toBe(false)
})
it('adds multiple assets to share and handles duplicates', async () => {
// Create real assets
const file1 = await prisma.asset.create({
@@ -244,6 +257,17 @@ describe('ShareService', () => {
expect(rootAsset?.name).toBe('New Name')
})
it('updates allowDownload on a share link', async () => {
const shareLink = await shareService.createShareLink(projectId, { name: 'Toggle Share' })
expect(shareLink.allowDownload).toBe(true)
const disabled = await shareService.updateShareLink(shareLink.id, { allowDownload: false })
expect(disabled.allowDownload).toBe(false)
const reEnabled = await shareService.updateShareLink(shareLink.id, { allowDownload: true })
expect(reEnabled.allowDownload).toBe(true)
})
it('deletes a share link', async () => {
const shareLink = await shareService.createShareLink(projectId, { name: 'To Delete' })
await shareService.deleteShareLink(shareLink.id)
+3
View File
@@ -65,6 +65,7 @@ export class ShareService {
expireAt: req.expireAt ? new Date(req.expireAt) : null,
password: req.password,
isDisabled: req.isDisabled ?? false,
allowDownload: req.allowDownload ?? true,
defaultSortOrder: req.defaultSortOrder,
viewMode: req.viewMode,
projectId: projectId,
@@ -92,6 +93,7 @@ export class ShareService {
req.expireAt !== undefined ? (req.expireAt ? new Date(req.expireAt) : null) : undefined,
password: req.password,
isDisabled: req.isDisabled,
allowDownload: req.allowDownload,
defaultSortOrder: req.defaultSortOrder,
viewMode: req.viewMode,
fieldVisibility: (req.fieldVisibility as PrismaJson.ShareLinkFieldVisibility) ?? undefined,
@@ -330,6 +332,7 @@ export class ShareService {
name: l.name,
expireAt: l.expireAt?.toISOString(),
isDisabled: l.isDisabled,
allowDownload: l.allowDownload,
hasPassword: !!l.password,
password: l.password,
defaultSortOrder: l.defaultSortOrder ?? undefined,
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "share_links" ADD COLUMN "allow_download" BOOLEAN NOT NULL DEFAULT true;
+1
View File
@@ -367,6 +367,7 @@ model ShareLink {
expireAt DateTime? @map("expire_at")
password String?
isDisabled Boolean @default(false) @map("is_disabled")
allowDownload Boolean @default(true) @map("allow_download")
defaultSortOrder String? @map("default_sort_order")
viewMode String? @map("view_mode")
/// [ShareLinkFieldVisibility]
File diff suppressed because one or more lines are too long
@@ -3450,6 +3450,7 @@ export const ShareLinkScalarFieldEnum = {
expireAt: 'expireAt',
password: 'password',
isDisabled: 'isDisabled',
allowDownload: 'allowDownload',
defaultSortOrder: 'defaultSortOrder',
viewMode: 'viewMode',
fieldVisibility: 'fieldVisibility',
@@ -265,6 +265,7 @@ export const ShareLinkScalarFieldEnum = {
expireAt: 'expireAt',
password: 'password',
isDisabled: 'isDisabled',
allowDownload: 'allowDownload',
defaultSortOrder: 'defaultSortOrder',
viewMode: 'viewMode',
fieldVisibility: 'fieldVisibility',
+52 -1
View File
@@ -32,6 +32,7 @@ export type ShareLinkMinAggregateOutputType = {
expireAt: Date | null
password: string | null
isDisabled: boolean | null
allowDownload: boolean | null
defaultSortOrder: string | null
viewMode: string | null
createdAt: Date | null
@@ -49,6 +50,7 @@ export type ShareLinkMaxAggregateOutputType = {
expireAt: Date | null
password: string | null
isDisabled: boolean | null
allowDownload: boolean | null
defaultSortOrder: string | null
viewMode: string | null
createdAt: Date | null
@@ -66,6 +68,7 @@ export type ShareLinkCountAggregateOutputType = {
expireAt: number
password: number
isDisabled: number
allowDownload: number
defaultSortOrder: number
viewMode: number
fieldVisibility:PrismaJson.ShareLinkFieldVisibility
@@ -86,6 +89,7 @@ export type ShareLinkMinAggregateInputType = {
expireAt?: true
password?: true
isDisabled?: true
allowDownload?: true
defaultSortOrder?: true
viewMode?: true
createdAt?: true
@@ -103,6 +107,7 @@ export type ShareLinkMaxAggregateInputType = {
expireAt?: true
password?: true
isDisabled?: true
allowDownload?: true
defaultSortOrder?: true
viewMode?: true
createdAt?: true
@@ -120,6 +125,7 @@ export type ShareLinkCountAggregateInputType = {
expireAt?: true
password?: true
isDisabled?: true
allowDownload?: true
defaultSortOrder?: true
viewMode?: true
fieldVisibility?: true
@@ -211,6 +217,7 @@ export type ShareLinkGroupByOutputType = {
expireAt: Date | null
password: string | null
isDisabled: boolean
allowDownload: boolean
defaultSortOrder: string | null
viewMode: string | null
fieldVisibility:PrismaJson.ShareLinkFieldVisibility | null
@@ -250,6 +257,7 @@ export type ShareLinkWhereInput = {
expireAt?: Prisma.DateTimeNullableFilter<"ShareLink"> | Date | string | null
password?: Prisma.StringNullableFilter<"ShareLink"> | string | null
isDisabled?: Prisma.BoolFilter<"ShareLink"> | boolean
allowDownload?: Prisma.BoolFilter<"ShareLink"> | boolean
defaultSortOrder?: Prisma.StringNullableFilter<"ShareLink"> | string | null
viewMode?: Prisma.StringNullableFilter<"ShareLink"> | string | null
fieldVisibility?: Prisma.JsonNullableFilter<"ShareLink">
@@ -272,6 +280,7 @@ export type ShareLinkOrderByWithRelationInput = {
expireAt?: Prisma.SortOrderInput | Prisma.SortOrder
password?: Prisma.SortOrderInput | Prisma.SortOrder
isDisabled?: Prisma.SortOrder
allowDownload?: Prisma.SortOrder
defaultSortOrder?: Prisma.SortOrderInput | Prisma.SortOrder
viewMode?: Prisma.SortOrderInput | Prisma.SortOrder
fieldVisibility?: Prisma.SortOrderInput | Prisma.SortOrder
@@ -298,6 +307,7 @@ export type ShareLinkWhereUniqueInput = Prisma.AtLeast<{
expireAt?: Prisma.DateTimeNullableFilter<"ShareLink"> | Date | string | null
password?: Prisma.StringNullableFilter<"ShareLink"> | string | null
isDisabled?: Prisma.BoolFilter<"ShareLink"> | boolean
allowDownload?: Prisma.BoolFilter<"ShareLink"> | boolean
defaultSortOrder?: Prisma.StringNullableFilter<"ShareLink"> | string | null
viewMode?: Prisma.StringNullableFilter<"ShareLink"> | string | null
fieldVisibility?: Prisma.JsonNullableFilter<"ShareLink">
@@ -319,6 +329,7 @@ export type ShareLinkOrderByWithAggregationInput = {
expireAt?: Prisma.SortOrderInput | Prisma.SortOrder
password?: Prisma.SortOrderInput | Prisma.SortOrder
isDisabled?: Prisma.SortOrder
allowDownload?: Prisma.SortOrder
defaultSortOrder?: Prisma.SortOrderInput | Prisma.SortOrder
viewMode?: Prisma.SortOrderInput | Prisma.SortOrder
fieldVisibility?: Prisma.SortOrderInput | Prisma.SortOrder
@@ -343,6 +354,7 @@ export type ShareLinkScalarWhereWithAggregatesInput = {
expireAt?: Prisma.DateTimeNullableWithAggregatesFilter<"ShareLink"> | Date | string | null
password?: Prisma.StringNullableWithAggregatesFilter<"ShareLink"> | string | null
isDisabled?: Prisma.BoolWithAggregatesFilter<"ShareLink"> | boolean
allowDownload?: Prisma.BoolWithAggregatesFilter<"ShareLink"> | boolean
defaultSortOrder?: Prisma.StringNullableWithAggregatesFilter<"ShareLink"> | string | null
viewMode?: Prisma.StringNullableWithAggregatesFilter<"ShareLink"> | string | null
fieldVisibility?: Prisma.JsonNullableWithAggregatesFilter<"ShareLink">
@@ -361,6 +373,7 @@ export type ShareLinkCreateInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -379,6 +392,7 @@ export type ShareLinkUncheckedCreateInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -397,6 +411,7 @@ export type ShareLinkUpdateInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -415,6 +430,7 @@ export type ShareLinkUncheckedUpdateInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -433,6 +449,7 @@ export type ShareLinkCreateManyInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -451,6 +468,7 @@ export type ShareLinkUpdateManyMutationInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -465,6 +483,7 @@ export type ShareLinkUncheckedUpdateManyInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -493,6 +512,7 @@ export type ShareLinkCountOrderByAggregateInput = {
expireAt?: Prisma.SortOrder
password?: Prisma.SortOrder
isDisabled?: Prisma.SortOrder
allowDownload?: Prisma.SortOrder
defaultSortOrder?: Prisma.SortOrder
viewMode?: Prisma.SortOrder
fieldVisibility?: Prisma.SortOrder
@@ -511,6 +531,7 @@ export type ShareLinkMaxOrderByAggregateInput = {
expireAt?: Prisma.SortOrder
password?: Prisma.SortOrder
isDisabled?: Prisma.SortOrder
allowDownload?: Prisma.SortOrder
defaultSortOrder?: Prisma.SortOrder
viewMode?: Prisma.SortOrder
createdAt?: Prisma.SortOrder
@@ -528,6 +549,7 @@ export type ShareLinkMinOrderByAggregateInput = {
expireAt?: Prisma.SortOrder
password?: Prisma.SortOrder
isDisabled?: Prisma.SortOrder
allowDownload?: Prisma.SortOrder
defaultSortOrder?: Prisma.SortOrder
viewMode?: Prisma.SortOrder
createdAt?: Prisma.SortOrder
@@ -712,6 +734,7 @@ export type ShareLinkCreateWithoutCreatorInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -729,6 +752,7 @@ export type ShareLinkUncheckedCreateWithoutCreatorInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -775,6 +799,7 @@ export type ShareLinkScalarWhereInput = {
expireAt?: Prisma.DateTimeNullableFilter<"ShareLink"> | Date | string | null
password?: Prisma.StringNullableFilter<"ShareLink"> | string | null
isDisabled?: Prisma.BoolFilter<"ShareLink"> | boolean
allowDownload?: Prisma.BoolFilter<"ShareLink"> | boolean
defaultSortOrder?: Prisma.StringNullableFilter<"ShareLink"> | string | null
viewMode?: Prisma.StringNullableFilter<"ShareLink"> | string | null
fieldVisibility?: Prisma.JsonNullableFilter<"ShareLink">
@@ -793,6 +818,7 @@ export type ShareLinkCreateWithoutProjectInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -810,6 +836,7 @@ export type ShareLinkUncheckedCreateWithoutProjectInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -853,6 +880,7 @@ export type ShareLinkCreateWithoutWatermarkConfigInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -870,6 +898,7 @@ export type ShareLinkUncheckedCreateWithoutWatermarkConfigInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -913,6 +942,7 @@ export type ShareLinkCreateWithoutRootFolderInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -930,6 +960,7 @@ export type ShareLinkUncheckedCreateWithoutRootFolderInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -963,6 +994,7 @@ export type ShareLinkUpdateWithoutRootFolderInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -980,6 +1012,7 @@ export type ShareLinkUncheckedUpdateWithoutRootFolderInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -997,6 +1030,7 @@ export type ShareLinkCreateManyCreatorInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1014,6 +1048,7 @@ export type ShareLinkUpdateWithoutCreatorInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1031,6 +1066,7 @@ export type ShareLinkUncheckedUpdateWithoutCreatorInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1048,6 +1084,7 @@ export type ShareLinkUncheckedUpdateManyWithoutCreatorInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1065,6 +1102,7 @@ export type ShareLinkCreateManyProjectInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1082,6 +1120,7 @@ export type ShareLinkUpdateWithoutProjectInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1099,6 +1138,7 @@ export type ShareLinkUncheckedUpdateWithoutProjectInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1116,6 +1156,7 @@ export type ShareLinkUncheckedUpdateManyWithoutProjectInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1133,6 +1174,7 @@ export type ShareLinkCreateManyWatermarkConfigInput = {
expireAt?: Date | string | null
password?: string | null
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: string | null
viewMode?: string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1150,6 +1192,7 @@ export type ShareLinkUpdateWithoutWatermarkConfigInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1167,6 +1210,7 @@ export type ShareLinkUncheckedUpdateWithoutWatermarkConfigInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1184,6 +1228,7 @@ export type ShareLinkUncheckedUpdateManyWithoutWatermarkConfigInput = {
expireAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
password?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
isDisabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
allowDownload?: Prisma.BoolFieldUpdateOperationsInput | boolean
defaultSortOrder?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
viewMode?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
fieldVisibility?:PrismaJson.ShareLinkFieldVisibility | Prisma.NullableJsonNullValueInput
@@ -1203,6 +1248,7 @@ export type ShareLinkSelect<ExtArgs extends runtime.Types.Extensions.InternalArg
expireAt?: boolean
password?: boolean
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: boolean
viewMode?: boolean
fieldVisibility?: boolean
@@ -1225,6 +1271,7 @@ export type ShareLinkSelectCreateManyAndReturn<ExtArgs extends runtime.Types.Ext
expireAt?: boolean
password?: boolean
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: boolean
viewMode?: boolean
fieldVisibility?: boolean
@@ -1247,6 +1294,7 @@ export type ShareLinkSelectUpdateManyAndReturn<ExtArgs extends runtime.Types.Ext
expireAt?: boolean
password?: boolean
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: boolean
viewMode?: boolean
fieldVisibility?: boolean
@@ -1269,6 +1317,7 @@ export type ShareLinkSelectScalar = {
expireAt?: boolean
password?: boolean
isDisabled?: boolean
allowDownload?: boolean
defaultSortOrder?: boolean
viewMode?: boolean
fieldVisibility?: boolean
@@ -1281,7 +1330,7 @@ export type ShareLinkSelectScalar = {
watermarkStatus?: boolean
}
export type ShareLinkOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "name" | "expireAt" | "password" | "isDisabled" | "defaultSortOrder" | "viewMode" | "fieldVisibility" | "createdAt" | "updatedAt" | "projectId" | "rootFolderId" | "creatorId" | "watermarkConfigId" | "watermarkStatus", ExtArgs["result"]["shareLink"]>
export type ShareLinkOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "name" | "expireAt" | "password" | "isDisabled" | "allowDownload" | "defaultSortOrder" | "viewMode" | "fieldVisibility" | "createdAt" | "updatedAt" | "projectId" | "rootFolderId" | "creatorId" | "watermarkConfigId" | "watermarkStatus", ExtArgs["result"]["shareLink"]>
export type ShareLinkInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
project?: boolean | Prisma.ProjectDefaultArgs<ExtArgs>
rootFolder?: boolean | Prisma.AssetDefaultArgs<ExtArgs>
@@ -1315,6 +1364,7 @@ export type $ShareLinkPayload<ExtArgs extends runtime.Types.Extensions.InternalA
expireAt: Date | null
password: string | null
isDisabled: boolean
allowDownload: boolean
defaultSortOrder: string | null
viewMode: string | null
/**
@@ -1760,6 +1810,7 @@ export interface ShareLinkFieldRefs {
readonly expireAt: Prisma.FieldRef<"ShareLink", 'DateTime'>
readonly password: Prisma.FieldRef<"ShareLink", 'String'>
readonly isDisabled: Prisma.FieldRef<"ShareLink", 'Boolean'>
readonly allowDownload: Prisma.FieldRef<"ShareLink", 'Boolean'>
readonly defaultSortOrder: Prisma.FieldRef<"ShareLink", 'String'>
readonly viewMode: Prisma.FieldRef<"ShareLink", 'String'>
readonly fieldVisibility: Prisma.FieldRef<"ShareLink", 'Json'>
+3
View File
@@ -7,6 +7,7 @@ export interface ShareLinkInfo {
name: string
expireAt?: string
isDisabled: boolean
allowDownload: boolean
hasPassword: boolean
password?: string | null
defaultSortOrder?: string
@@ -32,6 +33,7 @@ export const createShareLinkRequestSchema = z.object({
expireAt: z.string().datetime().optional(),
password: z.string().optional(),
isDisabled: z.boolean().optional(),
allowDownload: z.boolean().optional(),
defaultSortOrder: z.string().optional(),
viewMode: z.string().optional(),
})
@@ -43,6 +45,7 @@ export const updateShareLinkRequestSchema = z.object({
expireAt: z.string().datetime().optional().nullable(),
password: z.string().optional().nullable(),
isDisabled: z.boolean().optional(),
allowDownload: z.boolean().optional(),
defaultSortOrder: z.string().optional().nullable(),
viewMode: z.string().optional().nullable(),
fieldVisibility: z.record(z.string(), z.boolean()).optional().nullable(),
+58 -55
View File
@@ -63,6 +63,7 @@ interface BreadcrumbNavProps {
onChatbotToggle?: () => void
isPublic?: boolean
shareId?: string
allowDownload?: boolean
onFolderClick?: (folderId: string) => void
fileId?: string
downloadInfo?: {
@@ -104,6 +105,7 @@ export function BreadcrumbNav({
onFolderClick,
fileId,
shareId,
allowDownload = true,
downloadInfo,
versions,
compareMode = false,
@@ -232,61 +234,62 @@ export function BreadcrumbNav({
<ChevronDown className="h-4 w-4" />
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56">
{hasVideoTranscodes ? (
<DropdownMenuSub>
<DropdownMenuSubTrigger className="flex items-center gap-2">
<span>{m.download()}</span>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent className="w-48">
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{downloadInfo?.videoTranscodes?.map((t) => {
const longSide = Math.max(t.width, t.height)
let resolution = `${t.height}p`
if (longSide >= 3840) resolution = '2160p'
else if (longSide >= 1920) resolution = '1080p'
else if (longSide >= 1280) resolution = '720p'
else if (longSide >= 960) resolution = '540p'
else if (longSide >= 640) resolution = '360p'
else if (longSide >= 320) resolution = '180p'
return (
<DropdownMenuItem
key={resolution}
onClick={() => handleDownload(t.key)}
className="flex items-center justify-between"
>
<span>{resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
})}
{downloadInfo?.originalKey && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => handleDownload(downloadInfo.originalKey!)}
className="flex items-center justify-between"
>
<span>Original</span>
<span className="text-xs text-muted-foreground">
{currentAsset.name?.split('.').pop()?.toUpperCase() || 'RAW'}
</span>
</DropdownMenuItem>
</>
)}
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
) : (
<DropdownMenuItem
onClick={() =>
downloadInfo?.originalKey && handleDownload(downloadInfo.originalKey)
}
disabled={!downloadInfo?.originalKey}
>
{m.download()}
</DropdownMenuItem>
)}
{allowDownload &&
(hasVideoTranscodes ? (
<DropdownMenuSub>
<DropdownMenuSubTrigger className="flex items-center gap-2">
<span>{m.download()}</span>
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent className="w-48">
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{downloadInfo?.videoTranscodes?.map((t) => {
const longSide = Math.max(t.width, t.height)
let resolution = `${t.height}p`
if (longSide >= 3840) resolution = '2160p'
else if (longSide >= 1920) resolution = '1080p'
else if (longSide >= 1280) resolution = '720p'
else if (longSide >= 960) resolution = '540p'
else if (longSide >= 640) resolution = '360p'
else if (longSide >= 320) resolution = '180p'
return (
<DropdownMenuItem
key={resolution}
onClick={() => handleDownload(t.key)}
className="flex items-center justify-between"
>
<span>{resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
})}
{downloadInfo?.originalKey && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => handleDownload(downloadInfo.originalKey!)}
className="flex items-center justify-between"
>
<span>Original</span>
<span className="text-xs text-muted-foreground">
{currentAsset.name?.split('.').pop()?.toUpperCase() || 'RAW'}
</span>
</DropdownMenuItem>
</>
)}
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
) : (
<DropdownMenuItem
onClick={() =>
downloadInfo?.originalKey && handleDownload(downloadInfo.originalKey)
}
disabled={!downloadInfo?.originalKey}
>
{m.download()}
</DropdownMenuItem>
))}
{canEdit && (
<DropdownMenuItem onClick={() => console.log('Rename')}>
Rename
@@ -25,6 +25,8 @@ interface CompareControlBarProps {
onFit: () => void
onDownload: (key?: string) => void
onToggleFullScreen: () => void
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
}
export function CompareControlBar({
@@ -44,6 +46,7 @@ export function CompareControlBar({
onFit,
onDownload,
onToggleFullScreen,
allowDownload = true,
}: CompareControlBarProps) {
// Active side is a video: reuse the shared VideoControlBar.
if (activeState?.kind === 'video' && activeState.video && activeAsset) {
@@ -94,6 +97,7 @@ export function CompareControlBar({
totalFrames={v.totalFrames}
currentFrame={v.currentFrame}
seekToFrame={onSeek}
allowDownload={allowDownload}
/>
)
}
@@ -109,6 +113,7 @@ export function CompareControlBar({
onDownload={() => onDownload()}
canDownload={!!activeAsset?.media?.original?.key}
fullscreen={{ isFullScreen, onToggle: onToggleFullScreen }}
allowDownload={allowDownload}
/>
)
}
@@ -33,6 +33,8 @@ interface CompareViewerProps {
onActiveAssetChange: (asset: AssetInfo | null) => void
onPlay?: () => void
onTimeUpdate?: (second: number) => void
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
}
function useCompareAsset(id: string, isPublic: boolean, shareId?: string) {
@@ -73,6 +75,7 @@ export function CompareViewer({
onActiveAssetChange,
onPlay,
onTimeUpdate,
allowDownload = true,
}: CompareViewerProps) {
const rootRef = useRef<HTMLDivElement>(null)
const leftRef = useRef<ComparePaneHandle | null>(null)
@@ -378,6 +381,7 @@ export function CompareViewer({
onFit={handleFit}
onDownload={handleDownload}
onToggleFullScreen={handleToggleFullScreen}
allowDownload={allowDownload}
/>
</div>
)
@@ -92,6 +92,8 @@ interface FileBrowserProps {
onUpdateCollection?: (updates: { name?: string; filter?: any }) => void
rootFolderId?: string
shareId?: string
/** When false, hides download affordances (used by public share views). Defaults to true. */
allowDownload?: boolean
}
type FileWithId = {
@@ -138,6 +140,7 @@ export function FileBrowser({
onUpdateCollection,
rootFolderId,
shareId,
allowDownload = true,
}: FileBrowserProps) {
const [contextMenuItem, setContextMenuItem] = useState<AssetInfo | null>(null)
const [moveCopyMode, setMoveCopyMode] = useState<'move' | 'copy' | null>(null)
@@ -680,6 +683,7 @@ export function FileBrowser({
isRecentlyDeleted,
selectedCount: selectedIds.size,
isShareView,
allowDownload,
fields: displayedFields,
canEdit,
isExternalDragging,
@@ -1136,19 +1140,21 @@ export function FileBrowser({
</span>
)}
</div>
<Button
variant="ghost"
size="sm"
onClick={() =>
handleDownload(
[...folders, ...displayedFiles].filter((i) => selectedIds.has(i.id!)),
)
}
className="gap-2"
>
<Download className="h-4 w-4" />
Download
</Button>
{allowDownload && (
<Button
variant="ghost"
size="sm"
onClick={() =>
handleDownload(
[...folders, ...displayedFiles].filter((i) => selectedIds.has(i.id!)),
)
}
className="gap-2"
>
<Download className="h-4 w-4" />
Download
</Button>
)}
</div>
)}
{isExternalDragging && !externalOverFolderId && (
@@ -55,6 +55,8 @@ interface FileCardProps {
fields: MetadataFieldInfo[]
isShareView?: boolean
canEdit?: boolean
/** When false, hides the download action. Defaults to true. */
allowDownload?: boolean
}
export function FileCard({
@@ -81,6 +83,7 @@ export function FileCard({
fields,
isShareView,
canEdit = true,
allowDownload = true,
}: FileCardProps) {
const [name, setName] = useState(item.name)
const inputRef = useRef<HTMLInputElement>(null)
@@ -314,15 +317,17 @@ export function FileCard({
<DropdownMenuContent align="end">
{isShareView ? (
<>
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
{allowDownload && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
)}
{canEdit && (
<DropdownMenuItem
onClick={(e) => {
@@ -359,15 +364,17 @@ export function FileCard({
<span>{m.rename()}</span>
</DropdownMenuItem>
)}
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
{allowDownload && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
)}
{canEdit && (
<>
<DropdownMenuSeparator />
@@ -45,6 +45,8 @@ interface FolderCardProps {
setExternalOverFolderId?: (id: string | null) => void
resetExternalDragState?: () => void
onExternalDrop?: (files: File[], folderId: string) => void
/** When false, hides the download action. Defaults to true. */
allowDownload?: boolean
}
const FolderPreviewGrid = ({ items }: { items: ChildPreview[] }) => {
@@ -126,6 +128,7 @@ export function FolderCard({
setExternalOverFolderId,
resetExternalDragState,
onExternalDrop,
allowDownload = true,
}: FolderCardProps) {
const [name, setName] = useState(item.name || '')
const inputRef = useRef<HTMLInputElement>(null)
@@ -361,15 +364,17 @@ export function FolderCard({
<DropdownMenuContent align="end">
{isShareView ? (
<>
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
{allowDownload && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
)}
{canEdit && (
<DropdownMenuItem
onClick={(e) => {
@@ -406,15 +411,17 @@ export function FolderCard({
<span>{m.rename()}</span>
</DropdownMenuItem>
)}
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
{allowDownload && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation()
onAction?.('download', item)
}}
>
<Download className="mr-2 h-4 w-4" />
<span>{m.download()}</span>
</DropdownMenuItem>
)}
{canEdit && (
<>
<DropdownMenuSeparator />
@@ -15,6 +15,7 @@ export function FileViewer({
annotations,
startTime,
shareId,
allowDownload,
children,
}: OuterFileViewerProps) {
const viewerDef = getViewerForFile(file)
@@ -31,6 +32,7 @@ export function FileViewer({
annotations={annotations}
startTime={startTime}
shareId={shareId}
allowDownload={allowDownload}
>
{children}
</ViewerComponent>
@@ -42,6 +42,7 @@ interface PublicShareInfo {
isDisabled: boolean
isExpired: boolean
hasPassword: boolean
allowDownload: boolean
rootFolderId: string
projectId: string
viewMode?: string | null
@@ -418,6 +419,7 @@ export function PublicShareManager({
isPublic: true,
shareId,
fileId: viewingFileId || undefined,
allowDownload: shareInfo.allowDownload,
downloadInfo: viewingFileData
? {
originalKey: viewingFileData.media?.original?.key,
@@ -561,6 +563,7 @@ export function PublicShareManager({
activeSide={compareActiveSide}
annotations={annotations}
seekRequest={seekRequest}
allowDownload={shareInfo.allowDownload}
onActiveSideChange={(side) => updateCompareSearch({ cmpActive: side })}
onSwitchVersion={(side, versionId) =>
updateCompareSearch(
@@ -582,6 +585,7 @@ export function PublicShareManager({
annotations={annotations}
startTime={startTime}
shareId={shareId}
allowDownload={shareInfo.allowDownload}
/>
)
)}
@@ -619,6 +623,7 @@ export function PublicShareManager({
isShareView={true}
isPublic={true}
shareId={shareId}
allowDownload={shareInfo.allowDownload}
/>
)
)}
@@ -4,34 +4,34 @@ import { Button } from '@/ui/components/ui/button'
import { Input } from '@/ui/components/ui/input'
import { Label } from '@/ui/components/ui/label'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/ui/components/ui/select'
import { Switch } from '@/ui/components/ui/switch'
import { WatermarkEditorDialog } from '@/ui/components/watermark-editor-dialog'
import { copyToClipboard as copyTextToClipboard } from '@/ui/lib/clipboard'
import { m } from '@/ui/paraglide/messages.js'
import {
ShareLinkInfo,
UpdateShareLinkRequest,
type FieldInfo as MetadataFieldInfo,
ShareLinkInfo,
UpdateShareLinkRequest,
type FieldInfo as MetadataFieldInfo,
} from '@shumai/dtos'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import {
ArrowDownUp,
ChevronRight,
Copy,
ExternalLink,
LayoutGrid,
List,
ListFilter,
Loader2,
Palette,
Shield,
SortAsc,
ArrowDownUp,
ChevronRight,
Copy,
ExternalLink,
LayoutGrid,
List,
ListFilter,
Loader2,
Palette,
Shield,
SortAsc,
} from 'lucide-react'
import React, { useState } from 'react'
import { toast } from 'sonner'
@@ -186,7 +186,7 @@ export function ShareSettingsSidebar({
<div className="space-y-1">
<SidebarAccordionItem title={m.security()} icon={<Shield className="h-4 w-4" />}>
<div className="p-3 space-y-4 pt-0">
<div className="p-3 space-y-4 pt-2">
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs">{m.password()}</Label>
@@ -241,6 +241,17 @@ export function ShareSettingsSidebar({
)}
</div>
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label className="text-xs">{m.allow_download()}</Label>
<Switch
checked={shareLink.allowDownload}
onCheckedChange={(checked) => updateShare({ allowDownload: checked })}
/>
</div>
<p className="text-xs text-muted-foreground">{m.allow_download_description()}</p>
</div>
<div className="space-y-2 pt-2 border-t border-border/50">
<div className="flex items-center justify-between">
<Label className="text-xs">{m.watermark()}</Label>
@@ -278,7 +289,7 @@ export function ShareSettingsSidebar({
</div>
</SidebarAccordionItem>
<SidebarAccordionItem title={m.appearance()} icon={<Palette className="h-4 w-4" />}>
<div className="p-3 space-y-3 pt-0 flex gap-2">
<div className="p-3 space-y-3 pt-2 flex gap-2">
<Button
variant={viewMode === 'card' ? 'secondary' : 'outline'}
size="sm"
@@ -300,7 +311,7 @@ export function ShareSettingsSidebar({
</div>
</SidebarAccordionItem>
<SidebarAccordionItem title={m.fields()} icon={<ListFilter className="h-4 w-4" />}>
<div className="p-3 space-y-3 pt-0">
<div className="p-3 space-y-3 pt-2">
{(fields as MetadataFieldInfo[])?.map((field) => (
<div key={field.id} className="flex items-center justify-between">
<Label className="text-xs">{field.config?.name}</Label>
@@ -313,7 +324,7 @@ export function ShareSettingsSidebar({
</div>
</SidebarAccordionItem>
<SidebarAccordionItem title={m.sort_by()} icon={<SortAsc className="h-4 w-4" />}>
<div className="p-3 space-y-4 pt-0">
<div className="p-3 space-y-4 pt-2">
<div className="space-y-2">
<Label className="text-xs text-muted-foreground">{m.field()}</Label>
<Select
+2
View File
@@ -25,6 +25,7 @@ export function TopNav() {
versions,
isPublic,
shareId,
allowDownload,
onFolderClick,
compareMode,
canCompareVersions,
@@ -112,6 +113,7 @@ export function TopNav() {
onChatbotToggle={onChatbotToggle}
isPublic={isPublic}
shareId={shareId}
allowDownload={allowDownload}
fileId={fileId}
downloadInfo={downloadInfo}
versions={versions}
@@ -4,7 +4,7 @@ import React, { useImperativeHandle } from 'react'
import { FileViewerProps, MediaController } from '../types'
export const DefaultViewer = React.forwardRef<MediaController, FileViewerProps>(
({ file, shareId, children }, ref) => {
({ file, shareId, children, allowDownload = true }, ref) => {
// Implement no-op media controller
useImperativeHandle(ref, () => ({
play: () => {},
@@ -46,15 +46,17 @@ export const DefaultViewer = React.forwardRef<MediaController, FileViewerProps>(
</div>
</div>
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-end gap-2 transition-colors duration-200">
<button
onClick={handleDownload}
disabled={!file.media?.original?.key}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
title="Download original file"
>
<Download size={14} />
Download
</button>
{allowDownload && (
<button
onClick={handleDownload}
disabled={!file.media?.original?.key}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
title="Download original file"
>
<Download size={14} />
Download
</button>
)}
</div>
</div>
)
@@ -11,6 +11,8 @@ export interface ImageControlBarProps {
onCopy?: () => void
copied?: boolean
canCopy?: boolean
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
/** When provided, renders a fullscreen toggle (used by compare mode). */
fullscreen?: { isFullScreen: boolean; onToggle: () => void }
}
@@ -25,6 +27,7 @@ export function ImageControlBar({
onCopy,
copied = false,
canCopy = true,
allowDownload = true,
fullscreen,
}: ImageControlBarProps) {
return (
@@ -65,15 +68,17 @@ export function ImageControlBar({
{copied ? m.copied() : m.copy()}
</button>
)}
<button
onClick={onDownload}
disabled={!canDownload}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
title={m.download_original_image()}
>
<Download size={14} />
{m.download()}
</button>
{allowDownload && (
<button
onClick={onDownload}
disabled={!canDownload}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
title={m.download_original_image()}
>
<Download size={14} />
{m.download()}
</button>
)}
{fullscreen && (
<button
onClick={fullscreen.onToggle}
@@ -8,7 +8,7 @@ import { useAnnotationStore } from '@/ui/stores/annotation-store'
import { FileViewerProps, MediaController } from '../types'
export const ImageViewer = React.forwardRef<MediaController, FileViewerProps>(
({ file, annotations, shareId, children }, ref) => {
({ file, annotations, shareId, children, allowDownload }, ref) => {
// Implement no-op media controller since images are static
useImperativeHandle(ref, () => ({
play: () => {},
@@ -215,6 +215,7 @@ export const ImageViewer = React.forwardRef<MediaController, FileViewerProps>(
onCopy={handleCopy}
copied={copied}
canCopy={!!bestUrl}
allowDownload={allowDownload}
/>
</div>
)
@@ -11,6 +11,8 @@ export interface PdfControlBarProps {
onFit: () => void
onDownload: () => void
canDownload: boolean
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
}
export function PdfControlBar({
@@ -23,6 +25,7 @@ export function PdfControlBar({
onFit,
onDownload,
canDownload,
allowDownload = true,
}: PdfControlBarProps) {
return (
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-between gap-2 transition-colors duration-200">
@@ -76,15 +79,17 @@ export function PdfControlBar({
>
{m.fit()}
</button>
<button
onClick={onDownload}
disabled={!canDownload}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50"
title={m.download_original_file()}
>
<Download size={14} />
{m.download()}
</button>
{allowDownload && (
<button
onClick={onDownload}
disabled={!canDownload}
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50"
title={m.download_original_file()}
>
<Download size={14} />
{m.download()}
</button>
)}
</div>
</div>
)
@@ -19,7 +19,20 @@ if (typeof window !== 'undefined' && pdfjsLib.GlobalWorkerOptions) {
}
export const PdfViewer = React.forwardRef<MediaController, FileViewerProps>(
({ file, annotations, shareId, children, onPlay, onPause, onTimeUpdate, startTime }, ref) => {
(
{
file,
annotations,
shareId,
children,
onPlay,
onPause,
onTimeUpdate,
startTime,
allowDownload,
},
ref,
) => {
const {
isDrawing,
currentTool,
@@ -347,6 +360,7 @@ export const PdfViewer = React.forwardRef<MediaController, FileViewerProps>(
onFit={handleFit}
onDownload={handleDownload}
canDownload={!!file.media?.original?.key}
allowDownload={allowDownload}
/>
</div>
)
@@ -19,6 +19,8 @@ export interface FileViewerProps {
onTimeUpdate?: (time: number) => void
startTime?: number
shareId?: string
/** When false, the viewer hides its download affordances. Defaults to true. */
allowDownload?: boolean
children?: React.ReactNode
}
@@ -78,6 +78,8 @@ export interface ControlBarProps {
/** Fired when the cursor enters/leaves the bar (used to pin it visible). */
onMouseEnter?: () => void
onMouseLeave?: () => void
/** When false, hides the download affordance. Defaults to true. */
allowDownload?: boolean
}
export const VideoControlBar: React.FC<ControlBarProps> = ({
@@ -104,6 +106,7 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
floatOverlayInFullScreen = true,
onMouseEnter,
onMouseLeave,
allowDownload = true,
}) => {
const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
@@ -348,51 +351,52 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
)}
{/* Download */}
{isAudio ? (
<button
onClick={() => handleDownload(data.media?.original?.key || '')}
className="transition-colors hover:text-primary"
title={m.download()}
disabled={!data.media?.original?.key}
>
<Download className="h-5 w-5" />
</button>
) : (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button className="transition-colors hover:text-primary" title={m.download()}>
<Download className="h-5 w-5" />
</button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
key={res.resolution}
onClick={() => handleDownload(res.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
>
<span>{res.resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
))}
{data.media?.original?.key && (
<>
<DropdownMenuSeparator />
{allowDownload &&
(isAudio ? (
<button
onClick={() => handleDownload(data.media?.original?.key || '')}
className="transition-colors hover:text-primary"
title={m.download()}
disabled={!data.media?.original?.key}
>
<Download className="h-5 w-5" />
</button>
) : (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button className="transition-colors hover:text-primary" title={m.download()}>
<Download className="h-5 w-5" />
</button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
onClick={() => handleDownload(data.media?.original?.key ?? '')}
key={res.resolution}
onClick={() => handleDownload(res.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
>
<span>{m.original()}</span>
<span className="text-xs text-muted-foreground">
{data.name?.split('.').pop()?.toUpperCase() || 'RAW'}
</span>
<span>{res.resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
)}
))}
{data.media?.original?.key && (
<>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() => handleDownload(data.media?.original?.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
>
<span>{m.original()}</span>
<span className="text-xs text-muted-foreground">
{data.name?.split('.').pop()?.toUpperCase() || 'RAW'}
</span>
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
))}
{/* Fullscreen */}
<button
@@ -13,7 +13,17 @@ import { FileViewerProps, MediaController } from '../types'
const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
(
{ file: data, onPlay, onPause, onTimeUpdate, annotations, startTime, shareId, children },
{
file: data,
onPlay,
onPause,
onTimeUpdate,
annotations,
startTime,
shareId,
children,
allowDownload,
},
ref,
) => {
const localPlayerRef = useRef<Player | null>(null)
@@ -683,6 +693,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
seekToFrame={seekToFrame}
onMouseEnter={handleControlsMouseEnter}
onMouseLeave={handleControlsMouseLeave}
allowDownload={allowDownload}
/>
</div>
)
+2
View File
@@ -174,6 +174,8 @@
"security": "Security",
"expiration_date": "Expiration Date",
"allow_download": "Allow download",
"allow_download_description": "Visitors can download files from this share link",
"appearance": "Appearance",
"grid": "Grid",
"list": "List",
+2
View File
@@ -174,6 +174,8 @@
"security": "安全",
"expiration_date": "过期日期",
"allow_download": "允许下载",
"allow_download_description": "访客可以从该分享链接下载文件",
"appearance": "外观",
"grid": "网格",
"list": "列表",
+2
View File
@@ -163,6 +163,8 @@ export * from "./copy_link.js";
export * from "./view.js";
export * from "./security.js";
export * from "./expiration_date.js";
export * from "./allow_download.js";
export * from "./allow_download_description.js";
export * from "./appearance.js";
export * from "./grid.js";
export * from "./list.js";
+2
View File
@@ -165,6 +165,8 @@ export * from './copy_link.js'
export * from './view.js'
export * from './security.js'
export * from './expiration_date.js'
export * from './allow_download.js'
export * from './allow_download_description.js'
export * from './appearance.js'
export * from './grid.js'
export * from './list.js'
+16
View File
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Allow download" |
*
* @param {Allow_DownloadInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const allow_download: ((inputs?: Allow_DownloadInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Allow_DownloadInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Allow_DownloadInputs = {};
+29
View File
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Allow_DownloadInputs */
const en_allow_download = /** @type {(inputs: Allow_DownloadInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Allow download`)
};
const zh_allow_download = /** @type {(inputs: Allow_DownloadInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`允许下载`)
};
/**
* | output |
* | --- |
* | "Allow download" |
*
* @param {Allow_DownloadInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const allow_download = /** @type {((inputs?: Allow_DownloadInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Allow_DownloadInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_allow_download(inputs)
return zh_allow_download(inputs)
});
+16
View File
@@ -0,0 +1,16 @@
/**
* | output |
* | --- |
* | "Visitors can download files from this share link" |
*
* @param {Allow_Download_DescriptionInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const allow_download_description: ((inputs?: Allow_Download_DescriptionInputs, options?: {
locale?: "en" | "zh";
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Allow_Download_DescriptionInputs, {
locale?: "en" | "zh";
}, {}>;
export type LocalizedString = import("../runtime.js").LocalizedString;
export type Allow_Download_DescriptionInputs = {};
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Allow_Download_DescriptionInputs */
const en_allow_download_description = /** @type {(inputs: Allow_Download_DescriptionInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`Visitors can download files from this share link`)
};
const zh_allow_download_description = /** @type {(inputs: Allow_Download_DescriptionInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`访客可以从该分享链接下载文件`)
};
/**
* | output |
* | --- |
* | "Visitors can download files from this share link" |
*
* @param {Allow_Download_DescriptionInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const allow_download_description = /** @type {((inputs?: Allow_Download_DescriptionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Allow_Download_DescriptionInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_allow_download_description(inputs)
return zh_allow_download_description(inputs)
});
+2
View File
@@ -31,6 +31,8 @@ export interface TopNavProjectState {
}>
isPublic?: boolean
shareId?: string
/** When false, the public share hides download affordances. Defaults to true. */
allowDownload?: boolean
onFolderClick?: (folderId: string) => void
isRightSidebarCollapsed?: boolean
onRightSidebarToggle?: () => void