From 51b15f5878cee8771a2c73b168110f9e8ed411c9 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Sun, 15 Feb 2026 21:28:14 -0700 Subject: [PATCH] moved the BuggyAttachments reference up to the application layer, instead of at the database layer --- conference_ops.go | 3 ++- conferenceadmin.go | 3 ++- database/post.go | 5 +++-- exports/vcif_xml.go | 15 +++++++++------ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/conference_ops.go b/conference_ops.go index 405862b..d603170 100644 --- a/conference_ops.go +++ b/conference_ops.go @@ -20,6 +20,7 @@ import ( "strconv" "strings" + "git.erbosoft.com/amy/amsterdam/config" "git.erbosoft.com/amy/amsterdam/database" "git.erbosoft.com/amy/amsterdam/email" "git.erbosoft.com/amy/amsterdam/ui" @@ -106,7 +107,7 @@ func AttachmentSend(ctxt ui.AmContext) (string, any) { } else if info == nil { return "error", echo.NewHTTPError(http.StatusNotFound, "attachment not found") } - data, err := hdr.AttachmentData(ctxt.Ctx()) + data, err := hdr.AttachmentData(ctxt.Ctx(), config.CommandLine.BuggyAttachments) if err != nil { return "error", err } diff --git a/conferenceadmin.go b/conferenceadmin.go index a01a09f..132f54e 100644 --- a/conferenceadmin.go +++ b/conferenceadmin.go @@ -19,6 +19,7 @@ import ( "strings" "time" + "git.erbosoft.com/amy/amsterdam/config" "git.erbosoft.com/amy/amsterdam/database" "git.erbosoft.com/amy/amsterdam/email" "git.erbosoft.com/amy/amsterdam/exports" @@ -730,7 +731,7 @@ func ConferenceExport(ctxt ui.AmContext) (string, any) { r, w := io.Pipe() go func() { start := time.Now() - err := exports.VCIFStreamTopicFile(context.Background(), w, topics) + err := exports.VCIFStreamTopicFile(context.Background(), w, topics, config.CommandLine.BuggyAttachments) if err != nil { log.Errorf("ConferenceExport task failed with %v", err) s := fmt.Sprintf("\r\n", err) diff --git a/database/post.go b/database/post.go index 48a3734..c94e309 100644 --- a/database/post.go +++ b/database/post.go @@ -103,11 +103,12 @@ func (p *PostHeader) AttachmentInfo(ctx context.Context) (*PostAttachInfo, error /* AttachmentData returns attachment data for a post. * Parameters: * ctx - Standard Go context value. + * bugWorkaround - Work around certain bugs in extracting compressed data, if true. * Returns: * Attachment data as a byte array. * Standard Go error status. */ -func (p *PostHeader) AttachmentData(ctx context.Context) ([]byte, error) { +func (p *PostHeader) AttachmentData(ctx context.Context, bugWorkaround bool) ([]byte, error) { if p.ScribbleDate != nil && p.ScribbleUid != nil { return nil, errors.New("no attachment data for scribbled post") } @@ -136,7 +137,7 @@ func (p *PostHeader) AttachmentData(ctx context.Context) ([]byte, error) { } if err != nil || n < int(datalen) { if err == nil { - if config.CommandLine.BuggyAttachments { + if bugWorkaround { log.Warnf("PostHeader.AttachmentData: bugged attachment on post #%d (expected %d bytes, got %d), truncating for retrieval", p.PostId, datalen, n) outdata = outdata[:n] } else { diff --git a/exports/vcif_xml.go b/exports/vcif_xml.go index 9a40b3d..ba7e4d9 100644 --- a/exports/vcif_xml.go +++ b/exports/vcif_xml.go @@ -80,10 +80,11 @@ type VCIFPostAttachment struct { * ctx - Standard Go context value. * target - Pointer to the target VCIF post structure. * post - The post to fill the target from. + * bugWorkaround - Work around bug in extracting compressed attachment data. * Returns: * Standard Go error status. */ -func VCIFFromPost(ctx context.Context, target *VCIFPost, post *database.PostHeader) error { +func VCIFFromPost(ctx context.Context, target *VCIFPost, post *database.PostHeader, bugWorkaround bool) error { // Fill in the posting user. user, err := post.Creator(ctx) if err != nil { @@ -127,7 +128,7 @@ func VCIFFromPost(ctx context.Context, target *VCIFPost, post *database.PostHead MIMEType: ainfo.MIMEType, Filename: ainfo.Filename, } - data, err := post.AttachmentData(ctx) + data, err := post.AttachmentData(ctx, bugWorkaround) if err != nil { return err } @@ -160,10 +161,11 @@ func VCIFFromPost(ctx context.Context, target *VCIFPost, post *database.PostHead * ctx - Standard Go context value. * target - Pointer to the target VCIF topic value. * topic - The topic to fill the target from. + * bugWorkaround - Work around bug in extracting compressed attachment data. * Returns: * Standard Go error status. */ -func VCIFFromTopic(ctx context.Context, target *VCIFTopic, topic *database.Topic) error { +func VCIFFromTopic(ctx context.Context, target *VCIFTopic, topic *database.Topic, bugWorkaround bool) error { // Get all posts in the topic. posts, err := database.AmGetPostRange(ctx, topic, 0, topic.TopMessage) if err != nil { @@ -173,7 +175,7 @@ func VCIFFromTopic(ctx context.Context, target *VCIFTopic, topic *database.Topic // Build the posts array. myPostArray := make([]VCIFPost, len(posts)) for i, p := range posts { - err = VCIFFromPost(ctx, &(myPostArray[i]), p) + err = VCIFFromPost(ctx, &(myPostArray[i]), p, bugWorkaround) if err != nil { return fmt.Errorf("error converting post %d: %v", p.Num, err) } @@ -193,10 +195,11 @@ func VCIFFromTopic(ctx context.Context, target *VCIFTopic, topic *database.Topic * ctx - Standard Go context value. * w - Writer to receive the XML data. * topics - Array of topics to be written. + * bugWorkaround - Work around bug in extracting compressed attachment data. * Returns: * Standard Go error status. */ -func VCIFStreamTopicFile(ctx context.Context, w io.Writer, topics []*database.Topic) error { +func VCIFStreamTopicFile(ctx context.Context, w io.Writer, topics []*database.Topic, bugWorkaround bool) error { // Write the header of the file. var b strings.Builder b.WriteString(xml.Header) @@ -213,7 +216,7 @@ func VCIFStreamTopicFile(ctx context.Context, w io.Writer, topics []*database.To // Encode each topic in turn and write it to the writer. for _, t := range topics { var encodedTopic VCIFTopic - err = VCIFFromTopic(ctx, &encodedTopic, t) + err = VCIFFromTopic(ctx, &encodedTopic, t, bugWorkaround) if err != nil { return fmt.Errorf("error converting topic %d: %v", t.Number, err) }