Files
gitea-MIRROR/modules/structs/attachment.go
Lunny Xiao 9ed44be714 feat: record and expose SHA-256 for attachments (#39954)
Release assets and other attachments had no content digest, so tools
that download release binaries could not verify them. This records one
and shows it on the releases page in a GitHub-like asset list.

- Record the SHA-256 of each attachment while it streams to storage,
migrated release assets included
- Return it as `digest: "sha256:<hex>"` in the attachment API, the field
GitHub uses for release assets
- Lay out release assets in columns for digest with copy button,
download count, size and date, stacked under the name on narrow screens
- Rename the "Downloads" section to "Assets" and show the asset count
- Attachments uploaded before this have no digest, backfilling them is
left for a follow-up

| Before | After |
| --- | --- |
| <img width="600" alt="before-desktop"
src="https://github.com/user-attachments/assets/d6f290b4-5fba-4ee2-86c0-82c0bd77f702"
/> | <img width="600" alt="after-desktop"
src="https://github.com/user-attachments/assets/11bafe88-331d-4e96-9455-87774db539d8"
/> |
| <img width="360" alt="before-mobile"
src="https://github.com/user-attachments/assets/22a83b07-ca43-4cc6-8d2a-c1fc92a32dfe"
/> | <img width="370" alt="after-mobile"
src="https://github.com/user-attachments/assets/d013b7d1-0683-4983-9864-5dbc7844f27d"
/> |

---------

Co-authored-by: silverwind <me@silverwind.io>
2026-11-20 08:47:30 +00:00

38 lines
1.1 KiB
Go

// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package structs
import (
"time"
)
// Attachment a generic attachment
// swagger:model
type Attachment struct {
// ID is the unique identifier for the attachment
ID int64 `json:"id"`
// Name is the filename of the attachment
Name string `json:"name"`
// Size is the file size in bytes
Size int64 `json:"size"`
// Digest is the SHA-256 of the content as "sha256:{hex}", omitted when not recorded at upload
Digest string `json:"digest,omitempty"`
// DownloadCount is the number of times the attachment has been downloaded
DownloadCount int64 `json:"download_count"`
// swagger:strfmt date-time
// Created is the time when the attachment was uploaded
Created time.Time `json:"created_at"`
// UUID is the unique identifier for the attachment file
UUID string `json:"uuid"`
// DownloadURL is the URL to download the attachment
DownloadURL string `json:"browser_download_url"`
}
// EditAttachmentOptions options for editing attachments
// swagger:model
type EditAttachmentOptions struct {
// Name is the new filename for the attachment
Name string `json:"name"`
}