Skip to content

Commit a31dc73

Browse files
fix(copilot): fix image auth (#1841)
* Fix copilot image auth * Lint * Remove extra loggign * Update apps/sim/app/api/copilot/chat/route.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent c3436e9 commit a31dc73

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

apps/sim/app/api/copilot/chat/route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ export async function POST(req: NextRequest) {
325325
...(processedFileContents.length > 0 && { fileAttachments: processedFileContents }),
326326
}
327327

328+
328329
try {
329330
logger.info(`[${tracker.requestId}] About to call Sim Agent`, {
330331
hasContext: agentContexts.length > 0,

apps/sim/app/api/files/authorization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export async function verifyFileAccess(
122122
}
123123

124124
// 2. Execution files: workspace_id/workflow_id/execution_id/filename
125-
if (inferredContext === 'execution' || isExecutionFile(cloudKey, bucketType)) {
125+
if (inferredContext === 'execution' || (!context && isExecutionFile(cloudKey, bucketType))) {
126126
return await verifyExecutionFileAccess(cloudKey, userId, customConfig)
127127
}
128128

apps/sim/app/api/files/upload/route.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ export async function POST(request: NextRequest) {
245245

246246
logger.info(`Uploading ${context} file: ${originalName}`)
247247

248+
// Generate storage key with context prefix and timestamp to ensure uniqueness
249+
const timestamp = Date.now()
250+
const safeFileName = originalName.replace(/\s+/g, '-')
251+
const storageKey = `${context}/${timestamp}-${safeFileName}`
252+
248253
const metadata: Record<string, string> = {
249254
originalName: originalName,
250255
uploadedAt: new Date().toISOString(),
@@ -258,9 +263,11 @@ export async function POST(request: NextRequest) {
258263

259264
const fileInfo = await storageService.uploadFile({
260265
file: buffer,
261-
fileName: originalName,
266+
fileName: storageKey,
262267
contentType: file.type,
263268
context,
269+
preserveKey: true,
270+
customKey: storageKey,
264271
metadata,
265272
})
266273

0 commit comments

Comments
 (0)