Compare commits

...

3 Commits

Author SHA1 Message Date
f84bcbdadc Fix created time of files. 2025-10-04 21:16:52 +08:00
af52e7b764 Display created time of files. 2025-10-04 21:10:47 +08:00
ff30125518 Improve file tile 2025-10-04 18:42:45 +08:00
5 changed files with 57 additions and 10 deletions

View File

@@ -105,6 +105,8 @@ export interface RFile {
user: User;
resource?: Resource;
hash?: string;
storage_name?: string;
created_at: number; // unix timestamp
}
export interface UploadingFile {

View File

@@ -85,7 +85,7 @@ function HomeHeader() {
if (pinned && stats) {
return;
}
const prefetchData = app.getPreFetchData();
if (prefetchData && prefetchData.background) {
navigator.setBackground(

View File

@@ -25,11 +25,13 @@ import Markdown from "react-markdown";
import "../markdown.css";
import Loading from "../components/loading.tsx";
import {
MdAdd,
MdAdd, MdOutlineAccessTime,
MdOutlineAdd,
MdOutlineArchive,
MdOutlineArticle,
MdOutlineCloud,
MdOutlineComment,
MdOutlineContentCopy,
MdOutlineDataset,
MdOutlineDelete,
MdOutlineDownload,
@@ -730,16 +732,54 @@ function FileTile({ file }: { file: RFile }) {
{file.is_redirect ? t("Redirect") : fileSizeToString(file.size)}
</Badge>
{file.hash && (
<Badge
className={
"badge-soft badge-accent text-xs mr-2 break-all hidden sm:inline-flex"
}
selectable={true}
>
<MdOutlineVerifiedUser size={16} className={"inline-block"} />
Md5: {file.hash}
<>
<Badge
className={
"badge-soft badge-accent text-xs mr-2 break-all hover:shadow-xs cursor-pointer transition-shadow"
}
onClick={() => {
const dialog = document.getElementById(
`file_md5_${file.id}`,
) as HTMLDialogElement;
dialog.showModal();
}}
>
<MdOutlineVerifiedUser size={16} className={"inline-block"} />
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 className={"badge-soft badge-info text-xs mr-2"}>
<MdOutlineAccessTime size={16} className={"inline-block"} />
{new Date(file.created_at * 1000).toISOString().substring(0, 10)}
</Badge>
<DeleteFileDialog fileId={file.id} uploaderId={file.user.id} />
<UpdateFileInfoDialog file={file} />
</p>

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,8 @@ type FileView struct {
User UserView `json:"user"`
Resource *ResourceView `json:"resource,omitempty"`
Hash string `json:"hash,omitempty"`
StorageName string `json:"storage_name,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"`
}
func (f *File) ToView() *FileView {
@@ -41,6 +43,8 @@ func (f *File) ToView() *FileView {
IsRedirect: f.RedirectUrl != "",
User: f.User.ToView(),
Hash: f.Hash,
StorageName: f.Storage.Name,
CreatedAt: f.CreatedAt.Unix(),
}
}