Improve file tile

This commit is contained in:
2025-10-04 18:42:45 +08:00
parent 02a33e00b3
commit ff30125518
5 changed files with 49 additions and 9 deletions

View File

@@ -41,6 +41,7 @@ func GetResourceByID(id uint) (model.Resource, error) {
}).
Preload("Files").
Preload("Files.User").
Preload("Files.Storage").
First(&r, id).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return model.Resource{}, model.NewNotFoundError("Resource not found")

View File

@@ -30,6 +30,7 @@ type FileView struct {
User UserView `json:"user"`
Resource *ResourceView `json:"resource,omitempty"`
Hash string `json:"hash,omitempty"`
StorageName string `json:"storage_name,omitempty"`
}
func (f *File) ToView() *FileView {
@@ -41,6 +42,7 @@ func (f *File) ToView() *FileView {
IsRedirect: f.RedirectUrl != "",
User: f.User.ToView(),
Hash: f.Hash,
StorageName: f.Storage.Name,
}
}