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
+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,