Skip to content

Commit b6fd545

Browse files
committed
fix: set file access to user scope
1 parent 30db6e9 commit b6fd545

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

‎backend/cmd/files/pdf-utils.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (v *virtualFile) Close() error {
6565
return nil // No-op since it's an in-memory buffer
6666
}
6767

68-
func RenderPDFPageAsImage(path string, pageNumber int, user string) (File, error) {
68+
func RenderDocPageAsImage(path string, pageNumber int, user string) (File, error) {
6969
doc, err := fitz.New(path)
7070
if err != nil {
7171
return File{}, err

‎backend/cmd/tools/tools.go‎

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -411,27 +411,35 @@ func viewDocumentPageTool(args, user, convID string) providers.ToolOutput {
411411
return providers.ToolOutput{Content: fmt.Sprintf("error decoding arguments: %v", err)}
412412
}
413413

414-
docs := files.GetAllConversationAttachments(convID)
415-
doc := findAttachment(docs, params.FileID)
416-
if doc == nil {
417-
return providers.ToolOutput{Content: fmt.Sprintf("Unable to find document with id %s in this conversation", params.FileID)}
414+
// docs := files.GetAllConversationAttachments(convID)
415+
// doc := findAttachment(docs, params.FileID)
416+
// if doc == nil {
417+
// return providers.ToolOutput{Content: fmt.Sprintf("Unable to find document with id %s in this conversation", params.FileID)}
418+
// }
419+
420+
docs, err := files.GetByIDs([]string{params.FileID}, user)
421+
if err != nil {
422+
return providers.ToolOutput{Content: fmt.Sprintf("error finding document: %v", err)}
423+
}
424+
if len(docs) == 0 {
425+
return providers.ToolOutput{Content: fmt.Sprintf("Unable to find document with id %s", params.FileID)}
418426
}
419427

420-
imgData, err := fs.RenderPDFPageAsImage(doc.File.Path, params.PageNumber, user)
428+
imgData, err := fs.RenderDocPageAsImage(docs[0].Path, params.PageNumber, user)
421429
if err != nil {
422430
return providers.ToolOutput{Content: fmt.Sprintf("error rendering document page: %v", err)}
423431
}
424432

425-
return providers.ToolOutput{File: imgData.ID, Content: fmt.Sprintf("Rendered page %d of document %s as image", params.PageNumber, doc.File.Name)}
433+
return providers.ToolOutput{File: imgData.ID, Content: fmt.Sprintf("Rendered page %d of document %s as image", params.PageNumber, docs[0].Name)}
426434
}
427435

428-
func findAttachment(m map[int][]fs.Attachment, targetID string) *fs.Attachment {
429-
for _, attachments := range m {
430-
for _, att := range attachments {
431-
if att.File.ID == targetID {
432-
return &att
433-
}
434-
}
435-
}
436-
return nil
437-
}
436+
// func findAttachment(m map[int][]fs.Attachment, targetID string) *fs.Attachment {
437+
// for _, attachments := range m {
438+
// for _, att := range attachments {
439+
// if att.File.ID == targetID {
440+
// return &att
441+
// }
442+
// }
443+
// }
444+
// return nil
445+
// }

0 commit comments

Comments
 (0)