moved the BuggyAttachments reference up to the application layer, instead of at the database layer

This commit is contained in:
2026-02-15 21:28:14 -07:00
parent 777b5ca846
commit 51b15f5878
4 changed files with 16 additions and 10 deletions
+2 -1
View File
@@ -20,6 +20,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"git.erbosoft.com/amy/amsterdam/config"
"git.erbosoft.com/amy/amsterdam/database" "git.erbosoft.com/amy/amsterdam/database"
"git.erbosoft.com/amy/amsterdam/email" "git.erbosoft.com/amy/amsterdam/email"
"git.erbosoft.com/amy/amsterdam/ui" "git.erbosoft.com/amy/amsterdam/ui"
@@ -106,7 +107,7 @@ func AttachmentSend(ctxt ui.AmContext) (string, any) {
} else if info == nil { } else if info == nil {
return "error", echo.NewHTTPError(http.StatusNotFound, "attachment not found") 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 { if err != nil {
return "error", err return "error", err
} }
+2 -1
View File
@@ -19,6 +19,7 @@ import (
"strings" "strings"
"time" "time"
"git.erbosoft.com/amy/amsterdam/config"
"git.erbosoft.com/amy/amsterdam/database" "git.erbosoft.com/amy/amsterdam/database"
"git.erbosoft.com/amy/amsterdam/email" "git.erbosoft.com/amy/amsterdam/email"
"git.erbosoft.com/amy/amsterdam/exports" "git.erbosoft.com/amy/amsterdam/exports"
@@ -730,7 +731,7 @@ func ConferenceExport(ctxt ui.AmContext) (string, any) {
r, w := io.Pipe() r, w := io.Pipe()
go func() { go func() {
start := time.Now() start := time.Now()
err := exports.VCIFStreamTopicFile(context.Background(), w, topics) err := exports.VCIFStreamTopicFile(context.Background(), w, topics, config.CommandLine.BuggyAttachments)
if err != nil { if err != nil {
log.Errorf("ConferenceExport task failed with %v", err) log.Errorf("ConferenceExport task failed with %v", err)
s := fmt.Sprintf("<!-- ***PROCESSING ERROR*** %v -->\r\n", err) s := fmt.Sprintf("<!-- ***PROCESSING ERROR*** %v -->\r\n", err)
+3 -2
View File
@@ -103,11 +103,12 @@ func (p *PostHeader) AttachmentInfo(ctx context.Context) (*PostAttachInfo, error
/* AttachmentData returns attachment data for a post. /* AttachmentData returns attachment data for a post.
* Parameters: * Parameters:
* ctx - Standard Go context value. * ctx - Standard Go context value.
* bugWorkaround - Work around certain bugs in extracting compressed data, if true.
* Returns: * Returns:
* Attachment data as a byte array. * Attachment data as a byte array.
* Standard Go error status. * 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 { if p.ScribbleDate != nil && p.ScribbleUid != nil {
return nil, errors.New("no attachment data for scribbled post") 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 || n < int(datalen) {
if err == nil { 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) log.Warnf("PostHeader.AttachmentData: bugged attachment on post #%d (expected %d bytes, got %d), truncating for retrieval", p.PostId, datalen, n)
outdata = outdata[:n] outdata = outdata[:n]
} else { } else {
+9 -6
View File
@@ -80,10 +80,11 @@ type VCIFPostAttachment struct {
* ctx - Standard Go context value. * ctx - Standard Go context value.
* target - Pointer to the target VCIF post structure. * target - Pointer to the target VCIF post structure.
* post - The post to fill the target from. * post - The post to fill the target from.
* bugWorkaround - Work around bug in extracting compressed attachment data.
* Returns: * Returns:
* Standard Go error status. * 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. // Fill in the posting user.
user, err := post.Creator(ctx) user, err := post.Creator(ctx)
if err != nil { if err != nil {
@@ -127,7 +128,7 @@ func VCIFFromPost(ctx context.Context, target *VCIFPost, post *database.PostHead
MIMEType: ainfo.MIMEType, MIMEType: ainfo.MIMEType,
Filename: ainfo.Filename, Filename: ainfo.Filename,
} }
data, err := post.AttachmentData(ctx) data, err := post.AttachmentData(ctx, bugWorkaround)
if err != nil { if err != nil {
return err return err
} }
@@ -160,10 +161,11 @@ func VCIFFromPost(ctx context.Context, target *VCIFPost, post *database.PostHead
* ctx - Standard Go context value. * ctx - Standard Go context value.
* target - Pointer to the target VCIF topic value. * target - Pointer to the target VCIF topic value.
* topic - The topic to fill the target from. * topic - The topic to fill the target from.
* bugWorkaround - Work around bug in extracting compressed attachment data.
* Returns: * Returns:
* Standard Go error status. * 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. // Get all posts in the topic.
posts, err := database.AmGetPostRange(ctx, topic, 0, topic.TopMessage) posts, err := database.AmGetPostRange(ctx, topic, 0, topic.TopMessage)
if err != nil { if err != nil {
@@ -173,7 +175,7 @@ func VCIFFromTopic(ctx context.Context, target *VCIFTopic, topic *database.Topic
// Build the posts array. // Build the posts array.
myPostArray := make([]VCIFPost, len(posts)) myPostArray := make([]VCIFPost, len(posts))
for i, p := range posts { for i, p := range posts {
err = VCIFFromPost(ctx, &(myPostArray[i]), p) err = VCIFFromPost(ctx, &(myPostArray[i]), p, bugWorkaround)
if err != nil { if err != nil {
return fmt.Errorf("error converting post %d: %v", p.Num, err) 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. * ctx - Standard Go context value.
* w - Writer to receive the XML data. * w - Writer to receive the XML data.
* topics - Array of topics to be written. * topics - Array of topics to be written.
* bugWorkaround - Work around bug in extracting compressed attachment data.
* Returns: * Returns:
* Standard Go error status. * 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. // Write the header of the file.
var b strings.Builder var b strings.Builder
b.WriteString(xml.Header) 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. // Encode each topic in turn and write it to the writer.
for _, t := range topics { for _, t := range topics {
var encodedTopic VCIFTopic var encodedTopic VCIFTopic
err = VCIFFromTopic(ctx, &encodedTopic, t) err = VCIFFromTopic(ctx, &encodedTopic, t, bugWorkaround)
if err != nil { if err != nil {
return fmt.Errorf("error converting topic %d: %v", t.Number, err) return fmt.Errorf("error converting topic %d: %v", t.Number, err)
} }