mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Add new file activity.
This commit is contained in:
@@ -234,6 +234,7 @@ export const i18nData = {
|
||||
"Comment Details": "Comment Details",
|
||||
"Posted a comment": "Posted a comment",
|
||||
"Resources": "Resources",
|
||||
"Added a new file": "Added a new file",
|
||||
},
|
||||
},
|
||||
"zh-CN": {
|
||||
@@ -461,6 +462,7 @@ export const i18nData = {
|
||||
"Posted a comment": "发布了一个评论",
|
||||
|
||||
"Resources": "资源",
|
||||
"Added a new file": "添加了新文件",
|
||||
},
|
||||
},
|
||||
"zh-TW": {
|
||||
@@ -688,6 +690,7 @@ export const i18nData = {
|
||||
"Posted a comment": "發布了評論",
|
||||
|
||||
"Resources": "資源",
|
||||
"Added a new file": "添加了新檔案",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@@ -177,6 +177,7 @@ export enum ActivityType {
|
||||
ResourcePublished = 1,
|
||||
ResourceUpdated = 2,
|
||||
NewComment = 3,
|
||||
NewFile = 4,
|
||||
}
|
||||
|
||||
export interface Activity {
|
||||
@@ -187,4 +188,5 @@ export interface Activity {
|
||||
resource?: Resource;
|
||||
user?: User;
|
||||
comment?: Comment;
|
||||
file?: RFile;
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@ import { useTranslation } from "react-i18next";
|
||||
import { useNavigate } from "react-router";
|
||||
import Loading from "../components/loading.tsx";
|
||||
import { CommentContent } from "../components/comment_tile.tsx";
|
||||
import {MdOutlineArchive, MdOutlinePhotoAlbum} from "react-icons/md";
|
||||
import Badge from "../components/badge.tsx";
|
||||
|
||||
export default function ActivitiesPage() {
|
||||
const [activities, setActivities] = useState<Activity[]>([]);
|
||||
@@ -59,6 +61,18 @@ export default function ActivitiesPage() {
|
||||
);
|
||||
}
|
||||
|
||||
function fileSizeToString(size: number) {
|
||||
if (size < 1024) {
|
||||
return size + "B";
|
||||
} else if (size < 1024 * 1024) {
|
||||
return (size / 1024).toFixed(2) + "KB";
|
||||
} else if (size < 1024 * 1024 * 1024) {
|
||||
return (size / 1024 / 1024).toFixed(2) + "MB";
|
||||
} else {
|
||||
return (size / 1024 / 1024 / 1024).toFixed(2) + "GB";
|
||||
}
|
||||
}
|
||||
|
||||
function ActivityCard({ activity }: { activity: Activity }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -67,6 +81,7 @@ function ActivityCard({ activity }: { activity: Activity }) {
|
||||
t("Published a resource"),
|
||||
t("Updated a resource"),
|
||||
t("Posted a comment"),
|
||||
t("Added a new file"),
|
||||
];
|
||||
|
||||
const navigate = useNavigate();
|
||||
@@ -97,6 +112,33 @@ function ActivityCard({ activity }: { activity: Activity }) {
|
||||
<CommentContent content={activity.comment!.content} />
|
||||
</div>
|
||||
);
|
||||
} else if (activity.type === ActivityType.NewFile) {
|
||||
content = (
|
||||
<div>
|
||||
<h4 className={"font-bold py-2"}>{activity.file!.filename}</h4>
|
||||
<p className={"text-sm whitespace-pre-wrap"}>
|
||||
{activity.file!.description}
|
||||
</p>
|
||||
<p className={"pt-1"}>
|
||||
<Badge className={"badge-soft badge-secondary text-xs mr-2"}>
|
||||
<MdOutlineArchive size={16} className={"inline-block"} />
|
||||
{activity.file!.is_redirect
|
||||
? t("Redirect")
|
||||
: fileSizeToString(activity.file!.size)}
|
||||
</Badge>
|
||||
<Badge className={"badge-soft badge-accent text-xs mr-2"}>
|
||||
<MdOutlinePhotoAlbum size={16} className={"inline-block"} />
|
||||
{(() => {
|
||||
let title = activity.resource!.title;
|
||||
if (title.length > 20) {
|
||||
title = title.slice(0, 20) + "...";
|
||||
}
|
||||
return title;
|
||||
})()}
|
||||
</Badge>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -112,6 +154,8 @@ function ActivityCard({ activity }: { activity: Activity }) {
|
||||
navigate(`/resources/${activity.resource?.id}`);
|
||||
} else if (activity.type === ActivityType.NewComment) {
|
||||
navigate(`/comments/${activity.comment?.id}`);
|
||||
} else if (activity.type === ActivityType.NewFile) {
|
||||
navigate(`/resources/${activity.resource?.id}#files`);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
@@ -171,7 +171,10 @@ export default function ManageServerConfigPage() {
|
||||
checked={config.allow_normal_user_upload}
|
||||
className="toggle-primary toggle"
|
||||
onChange={(e) => {
|
||||
setConfig({ ...config, allow_normal_user_upload: e.target.checked });
|
||||
setConfig({
|
||||
...config,
|
||||
allow_normal_user_upload: e.target.checked,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</fieldset>
|
||||
|
@@ -145,7 +145,9 @@ export default function StorageView() {
|
||||
<tr key={s.id} className={"hover"}>
|
||||
<td>
|
||||
{s.name}
|
||||
{s.isDefault && <Badge className={"ml-1"}>{t("Default")}</Badge>}
|
||||
{s.isDefault && (
|
||||
<Badge className={"ml-1"}>{t("Default")}</Badge>
|
||||
)}
|
||||
</td>
|
||||
<td>{new Date(s.createdAt).toLocaleString()}</td>
|
||||
<td>
|
||||
@@ -173,15 +175,15 @@ export default function StorageView() {
|
||||
>
|
||||
<a>{t("Delete")}</a>
|
||||
</PopupMenuItem>
|
||||
{!s.isDefault && <PopupMenuItem
|
||||
onClick={() => {
|
||||
handleSetDefault(s.id);
|
||||
}}
|
||||
>
|
||||
<a>
|
||||
t("Set as Default")
|
||||
</a>
|
||||
</PopupMenuItem>}
|
||||
{!s.isDefault && (
|
||||
<PopupMenuItem
|
||||
onClick={() => {
|
||||
handleSetDefault(s.id);
|
||||
}}
|
||||
>
|
||||
<a>t("Set as Default")</a>
|
||||
</PopupMenuItem>
|
||||
)}
|
||||
</ul>,
|
||||
document.getElementById(
|
||||
`set_default_button_${s.id}`,
|
||||
|
@@ -395,7 +395,7 @@ function DeleteResourceDialog({
|
||||
);
|
||||
}
|
||||
|
||||
const context = createContext<() => void>(() => { });
|
||||
const context = createContext<() => void>(() => {});
|
||||
|
||||
function Article({ resource }: { resource: ResourceDetails }) {
|
||||
return (
|
||||
@@ -503,10 +503,7 @@ function Article({ resource }: { resource: ResourceDetails }) {
|
||||
const href = props.href as string;
|
||||
const origin = window.location.origin;
|
||||
|
||||
if (
|
||||
href.startsWith(origin) ||
|
||||
href.startsWith("/")
|
||||
) {
|
||||
if (href.startsWith(origin) || href.startsWith("/")) {
|
||||
let path = href;
|
||||
if (path.startsWith(origin)) {
|
||||
path = path.substring(origin.length);
|
||||
@@ -532,7 +529,13 @@ function Article({ resource }: { resource: ResourceDetails }) {
|
||||
);
|
||||
}
|
||||
|
||||
function RelatedResourceCard({ r, content }: { r: Resource, content?: string }) {
|
||||
function RelatedResourceCard({
|
||||
r,
|
||||
content,
|
||||
}: {
|
||||
r: Resource;
|
||||
content?: string;
|
||||
}) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [articleWidth, setArticleWidth] = useState<number | null>(null);
|
||||
@@ -549,10 +552,9 @@ function RelatedResourceCard({ r, content }: { r: Resource, content?: string })
|
||||
if (articleElement) {
|
||||
observer.observe(articleElement);
|
||||
}
|
||||
}, [])
|
||||
}, []);
|
||||
|
||||
const imgHeight =
|
||||
r.image && r.image.width > r.image.height ? 320 : 420;
|
||||
const imgHeight = r.image && r.image.width > r.image.height ? 320 : 420;
|
||||
let imgWidth = r.image
|
||||
? (r.image.width / r.image.height) * imgHeight
|
||||
: undefined;
|
||||
@@ -561,7 +563,7 @@ function RelatedResourceCard({ r, content }: { r: Resource, content?: string })
|
||||
}
|
||||
|
||||
if (!articleWidth) {
|
||||
return <></>
|
||||
return <></>;
|
||||
}
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user