Skip to content

Commit 2d3707c

Browse files
refactor(file): read share status uses visibility vocabulary, no row internals
Read's per-file "share" is now { visibility, url, allowedEmails } using the same visibility vocabulary as Manage Sharing: 'private' when not shared (url null, no config) instead of null, otherwise public/password/email/sso with the link. Drops row internals (id, token, resourceType, resourceId, isActive, hasPassword).
1 parent 5e3ed27 commit 2d3707c

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

apps/sim/app/api/tools/file/manage/route.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,16 +418,29 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
418418
)
419419
}
420420

421-
// Attach each workspace file's public share status (batched to avoid N+1).
422-
// Picker/upload input files have no canonical id, so they carry no share.
421+
// Attach each workspace file's share status (batched to avoid N+1), using
422+
// the same visibility vocabulary as the Manage Sharing operation. A file
423+
// with no active public link reads as 'private' and exposes no link/config.
424+
// Picker/upload input files have no canonical id, so they read as private.
423425
const shares = await getSharesForResources('file', selectedFileIds)
426+
const toReadShare = (fileId: string) => {
427+
const share = shares.get(fileId)
428+
if (!share || !share.isActive) {
429+
return { visibility: 'private' as const, url: null, allowedEmails: [] as string[] }
430+
}
431+
return {
432+
visibility: share.authType,
433+
url: share.url,
434+
allowedEmails: share.allowedEmails,
435+
}
436+
}
424437
const userFiles = files
425438
.map((file) => workspaceFileToUserFile(file))
426439
.filter((file): file is NonNullable<ReturnType<typeof workspaceFileToUserFile>> =>
427440
Boolean(file)
428441
)
429-
.map((file) => ({ ...file, share: shares.get(file.id) ?? null }))
430-
.concat(selectedInputFiles.map((file) => ({ ...file, share: null })))
442+
.map((file) => ({ ...file, share: toReadShare(file.id) }))
443+
.concat(selectedInputFiles.map((file) => ({ ...file, share: toReadShare(file.id) })))
431444

432445
logger.info('Files retrieved', {
433446
count: userFiles.length,

apps/sim/blocks/blocks/file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ export const FileV5Block: BlockConfig<FileParserV3Output> = {
13611361
files: {
13621362
type: 'file[]',
13631363
description:
1364-
'Workspace file objects (read; each includes a "share" field with its public share status, null when not shared), fetched file objects (fetch), the compressed archive (compress), or extracted files (decompress)',
1364+
'Workspace file objects (read; each includes a "share" field — { visibility, url, allowedEmails }, where visibility is "private" when not shared or "public"/"password"/"email"/"sso" with the link in url), fetched file objects (fetch), the compressed archive (compress), or extracted files (decompress)',
13651365
},
13661366
contents: {
13671367
type: 'array',

apps/sim/tools/file/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const createFileReadTool = (config: {
6363
files: {
6464
type: 'file[]',
6565
description:
66-
'Workspace file objects, each with its public share status in a "share" field (null when the file is not shared)',
66+
'Workspace file objects, each with a "share" field: { visibility, url, allowedEmails }. visibility is "private" when not publicly shared (url null), otherwise "public"/"password"/"email"/"sso" with the public link in url',
6767
},
6868
},
6969
})

0 commit comments

Comments
 (0)