updated s3_key name to icon_hash
This commit is contained in:
parent
e308718eb2
commit
33bd0a221e
8 changed files with 31 additions and 31 deletions
|
|
@ -43,7 +43,7 @@ func claimBatch(ctx context.Context, pool *pgxpool.Pool, limit int) ([]IconRow,
|
|||
|
||||
// DownloadResult holds the outcome of downloading one icon.
|
||||
type DownloadResult struct {
|
||||
S3Key string
|
||||
IconHash string
|
||||
ContentType string
|
||||
Width int
|
||||
Height int
|
||||
|
|
@ -65,14 +65,14 @@ func updateIcon(ctx context.Context, pool *pgxpool.Pool, iconID int64, result Do
|
|||
_, err := pool.Exec(ctx, `
|
||||
UPDATE icons SET
|
||||
scan_state = 'completed',
|
||||
s3_key = $1,
|
||||
icon_hash = $1,
|
||||
content_type = $2,
|
||||
width = $3,
|
||||
height = $4,
|
||||
file_size = $5,
|
||||
downloaded_at = now()
|
||||
WHERE id = $6`,
|
||||
result.S3Key, result.ContentType,
|
||||
result.IconHash, result.ContentType,
|
||||
nilIntIf(result.Width, 0), nilIntIf(result.Height, 0),
|
||||
result.FileSize, iconID)
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -37,22 +37,22 @@ func processIcon(icon IconRow, cfg Config) DownloadResult {
|
|||
|
||||
// Compute SHA-256 for content-addressed storage
|
||||
hash := sha256.Sum256(data)
|
||||
s3Key := hex.EncodeToString(hash[:])
|
||||
iconHash := hex.EncodeToString(hash[:])
|
||||
|
||||
// Write to disk (skip if already exists — dedup)
|
||||
dedup := false
|
||||
if !cfg.DryRun {
|
||||
if iconExists(s3Key) {
|
||||
if iconExists(iconHash) {
|
||||
dedup = true
|
||||
} else {
|
||||
if err := iconWrite(s3Key, data); err != nil {
|
||||
if err := iconWrite(iconHash, data); err != nil {
|
||||
return DownloadResult{Err: fmt.Sprintf("disk write: %v", err), ErrType: "other"}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DownloadResult{
|
||||
S3Key: s3Key,
|
||||
IconHash: iconHash,
|
||||
ContentType: contentType,
|
||||
Width: width,
|
||||
Height: height,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue