switched from s3 to disk for saving icons
This commit is contained in:
parent
113a261dae
commit
5b3f6a6870
9 changed files with 84 additions and 112 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
|
@ -24,7 +23,7 @@ type Bundle struct {
|
|||
}
|
||||
|
||||
// buildEntry creates a BundleEntry for a host, converting its icon if available.
|
||||
func buildEntry(ctx context.Context, host HostRow, iconsBucket string, logWriter *LogWriter, stats *Stats) BundleEntry {
|
||||
func buildEntry(host HostRow, iconsDir string, logWriter *LogWriter, stats *Stats) BundleEntry {
|
||||
entry := BundleEntry{
|
||||
Host: host.Hostname,
|
||||
Title: host.HtmlTitle,
|
||||
|
|
@ -36,7 +35,7 @@ func buildEntry(ctx context.Context, host HostRow, iconsBucket string, logWriter
|
|||
return entry
|
||||
}
|
||||
|
||||
encoded, w, h, convertErr := safeConvert(ctx, host.BestIconS3Key, iconsBucket)
|
||||
encoded, w, h, convertErr := safeConvert(host.BestIconS3Key, iconsDir)
|
||||
if convertErr != "" {
|
||||
stats.ConvertErrors.Add(1)
|
||||
logLine := fmt.Sprintf("CONVERT_ERROR: %s %s", host.Hostname, convertErr)
|
||||
|
|
@ -54,7 +53,7 @@ func buildEntry(ctx context.Context, host HostRow, iconsBucket string, logWriter
|
|||
}
|
||||
|
||||
// safeConvert wraps convertIconToBase64PNG with panic recovery.
|
||||
func safeConvert(ctx context.Context, s3Key, iconsBucket string) (encoded string, w, h int, errMsg string) {
|
||||
func safeConvert(hash, iconsDir string) (encoded string, w, h int, errMsg string) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
errMsg = fmt.Sprintf("panic: %v", r)
|
||||
|
|
@ -62,7 +61,7 @@ func safeConvert(ctx context.Context, s3Key, iconsBucket string) (encoded string
|
|||
}()
|
||||
|
||||
var err error
|
||||
encoded, w, h, err = convertIconToBase64PNG(ctx, s3Key, iconsBucket)
|
||||
encoded, w, h, err = convertIconToBase64PNG(hash, iconsDir)
|
||||
if err != nil {
|
||||
return "", 0, 0, err.Error()
|
||||
}
|
||||
|
|
@ -79,7 +78,7 @@ func writeBundleLocal(outputDir string, index int, data []byte) error {
|
|||
return os.WriteFile(path, data, 0644)
|
||||
}
|
||||
|
||||
func writeBundleS3(ctx context.Context, bucket string, index int, data []byte) error {
|
||||
func writeBundleS3(bucket string, index int, data []byte) error {
|
||||
key := fmt.Sprintf("tabs/%04d.json", index)
|
||||
return s3UploadBundle(ctx, bucket, key, data)
|
||||
return s3UploadBundle(bucket, key, data)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue