A tool for archiving & converting scans of postcards, and information about them.

fix(postoffice): :bug: Ensure USD only gets texture, not HTML/CSS

Because the web codec now returns the HTML and CSS, the USD codec was unsure which of the files provided was the image it should be using as a texture. This is now fixed!

+16 -5
+12 -3
formats/usd/codec.go
··· 124 124 func (c codec) Encode(pc types.Postcard, opts *formats.EncodeOptions) ([]formats.FileWriter, error) { 125 125 usdFilename := pc.Name + extension 126 126 127 - // Grab the filename of the texture image, as it might be JPG or PNG 128 - webImg, _ := web.Codec("jpeg", "png") 127 + if opts == nil { 128 + opts = &formats.EncodeOptions{} 129 + } 129 130 // We can scrub the transparency data (it's represented in mesh points) 130 131 // And make a significantly smaller (JPEG powered) texture. 131 132 // We must not do this for archival requests, as it loses the transparency data forever. 132 133 opts.NoTransparency = !opts.WantsLossless() 134 + opts.IncludeSupportFiles = false 135 + 136 + webImg, _ := web.Codec("jpeg", "png") 133 137 fws, err := webImg.Encode(pc, opts) 134 138 if err != nil { 135 139 return nil, err 136 140 } 137 141 138 - if len(fws) != 1 { 142 + switch len(fws) { 143 + case 1: 144 + // All good 145 + case 0: 139 146 return nil, fmt.Errorf("couldn't encode postcard textures") 147 + default: 148 + return nil, fmt.Errorf("unable to determine web image file writer") 140 149 } 141 150 fw := fws[0] 142 151
+1 -1
internal/www/postoffice/postoffice-serviceworker.js
··· 11 11 event.waitUntil(clients.claim()) 12 12 }) 13 13 14 - registerWasmHTTPListener(wasm, { base: '/api' }) 14 + registerWasmHTTPListener(wasm, { base: '/api/' })
+3 -1
pkg/postoffice/http.go
··· 45 45 if len(files) == 1 { 46 46 w.Header().Add("Content-Type", files[0].Mimetype) 47 47 w.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, files[0].Filename)) 48 - files[0].WriteTo(w) 48 + if err := files[0].WriteTo(w); err != nil { 49 + http.Error(w, "Unable to write file", http.StatusInternalServerError) 50 + } 49 51 return 50 52 } 51 53