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

@@ -105,6 +105,7 @@ export interface RFile {
user: User; user: User;
resource?: Resource; resource?: Resource;
hash?: string; hash?: string;
storage_name?: string;
} }
export interface UploadingFile { export interface UploadingFile {

View File

@@ -29,7 +29,9 @@ import {
MdOutlineAdd, MdOutlineAdd,
MdOutlineArchive, MdOutlineArchive,
MdOutlineArticle, MdOutlineArticle,
MdOutlineCloud,
MdOutlineComment, MdOutlineComment,
MdOutlineContentCopy,
MdOutlineDataset, MdOutlineDataset,
MdOutlineDelete, MdOutlineDelete,
MdOutlineDownload, MdOutlineDownload,
@@ -730,14 +732,48 @@ function FileTile({ file }: { file: RFile }) {
{file.is_redirect ? t("Redirect") : fileSizeToString(file.size)} {file.is_redirect ? t("Redirect") : fileSizeToString(file.size)}
</Badge> </Badge>
{file.hash && ( {file.hash && (
<>
<Badge <Badge
className={ className={
"badge-soft badge-accent text-xs mr-2 break-all hidden sm:inline-flex" "badge-soft badge-accent text-xs mr-2 break-all hover:shadow-xs cursor-pointer transition-shadow"
} }
selectable={true} onClick={() => {
const dialog = document.getElementById(
`file_md5_${file.id}`,
) as HTMLDialogElement;
dialog.showModal();
}}
> >
<MdOutlineVerifiedUser size={16} className={"inline-block"} /> <MdOutlineVerifiedUser size={16} className={"inline-block"} />
Md5: {file.hash} Md5
</Badge>
<dialog id={`file_md5_${file.id}`} className="modal">
<div className="modal-box">
<h3 className="font-bold text-lg mb-4">Md5</h3>
<label className="input input-primary w-full">
<input type="text" readOnly value={file.hash} />
<button
className="btn btn-square btn-ghost btn-sm"
onClick={() => {
navigator.clipboard.writeText(file.hash!);
}}
>
<MdOutlineContentCopy size={18} />
</button>
</label>
<div className="modal-action">
<form method="dialog">
<button className="btn">Close</button>
</form>
</div>
</div>
</dialog>
</>
)}
{file.storage_name && (
<Badge className={"badge-soft badge-info text-xs mr-2"}>
<MdOutlineCloud size={16} className={"inline-block"} />
{file.storage_name}
</Badge> </Badge>
)} )}
<DeleteFileDialog fileId={file.id} uploaderId={file.user.id} /> <DeleteFileDialog fileId={file.id} uploaderId={file.user.id} />

View File

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

View File

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