@@ -426,53 +426,32 @@ func inlineImages(body string, ctx *mailCommentContext) (string, error) {
426426// Helper function to convert attachment source to data URI
427427
428428func attachmentSrcToDataURI (attachmentPath string , ctx * mailCommentContext ) (string , error ) {
429- // Extract the UUID from the attachment path
430429 parts := strings .Split (attachmentPath , "/attachments/" )
431- attachmentUUID := ""
432- if len (parts ) > 1 {
433- attachmentUUID = parts [1 ]
434- } else {
430+ if len (parts ) <= 1 {
435431 return "" , fmt .Errorf ("Invalid attachment path: %s" , attachmentPath )
436432 }
437- // Retrieve the attachment using the UUID
433+
434+ attachmentUUID := parts [len (parts )- 1 ]
438435 attachment , err := repo_model .GetAttachmentByUUID (ctx , attachmentUUID )
439- log .Trace ("attachmentUUID: %s" , attachmentUUID )
440436 if err != nil {
441437 return "" , err
442438 }
443439
444- // log attachment.DownloadPath
445- log .Trace ("attachment.DownloadURL(): %s" , attachment .DownloadURL ())
446-
447440 fr , err := storage .Attachments .Open (attachment .RelativePath ())
448441 if err != nil {
449442 return "" , err
450443 }
451- defer func (fr storage.Object ) {
452- err := fr .Close ()
453- if err != nil {
454- }
455- }(fr )
444+ defer fr .Close ()
456445
457- // fr is io.ReadSeeker
458- // get this as bytes:
459446 content := make ([]byte , attachment .Size )
460- _ , err = fr .Read (content )
461- if err != nil {
447+ if _ , err := fr .Read (content ); err != nil {
462448 return "" , err
463449 }
464450
465- // Detect the MIME type
466451 mimeType := http .DetectContentType (content )
467-
468- log .Trace ("MIME type: %s" , mimeType )
469-
470- // Encode the content to base64
471452 encoded := base64 .StdEncoding .EncodeToString (content )
472- log .Trace ("First 100 characters of encoded content: %s" , encoded [:100 ])
473-
474- // Construct the data URI
475453 dataURI := fmt .Sprintf ("data:%s;base64,%s" , mimeType , encoded )
454+
476455 return dataURI , nil
477456}
478457
0 commit comments