1
0

fix: mishandling of target reach time of milestone in frontend

This commit is contained in:
alikia2x (寒寒) 2025-11-12 21:29:00 +08:00
parent 6341d9bf7c
commit f7a1bc312a
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 56209E0CCD8420C6
2 changed files with 5 additions and 17 deletions

View File

@ -11,6 +11,7 @@ import { formatDateTime } from "@/components/SearchResults";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Card } from "@/components/ui/card";
import { Progress } from "@/components/ui/progress";
import { addHoursToNow, formatHours } from "./song/[id]/info";
// @ts-ignore idk
const app = treaty<App>(import.meta.env.VITE_API_URL!);
@ -30,19 +31,6 @@ const milestoneConfig = {
shinwa: { name: "神话", range: [5000000, 9999999], target: 10000000 },
};
function formatHours(hours: number): string {
if (hours >= 24 * 14) return `${Math.floor(hours / 24)}`;
if (hours >= 24) return `${Math.floor(hours / 24)}${Math.floor(hours % 24)} 小时`;
if (hours >= 1) return `${Math.floor(hours)}${Math.round((hours % 1) * 60)}`;
return `${Math.round(hours * 60)} 分钟`;
}
function addHoursToNow(hours: number): string {
const d = new Date();
d.setHours(d.getHours() + hours);
return `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")} ${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}`;
}
export default function Home() {
const [input, setInput] = useState("");
const [milestoneType, setMilestoneType] = useState<MilestoneType>("shinwa");
@ -78,7 +66,7 @@ export default function Home() {
<img
src={video.bilibili_metadata.coverUrl}
alt="视频封面"
className="h-25 w-40 rounded-sm object-cover flex-shrink-0"
className="h-25 w-40 rounded-sm object-cover shrink-0"
referrerPolicy="no-referrer"
loading="lazy"
/>

View File

@ -47,16 +47,16 @@ export async function clientLoader({ params }: Route.LoaderArgs) {
return { id: params.id };
}
function formatHours(hours: number): string {
export function formatHours(hours: number): string {
if (hours >= 24 * 14) return `${Math.floor(hours / 24)}`;
if (hours >= 24) return `${Math.floor(hours / 24)}${Math.round(hours) % 24} 小时`;
if (hours >= 1) return `${Math.floor(hours)}${Math.round((hours % 1) * 60)}`;
return `${Math.round(hours * 60)} 分钟`;
}
function addHoursToNow(hours: number): string {
export function addHoursToNow(hours: number): string {
const d = new Date();
d.setHours(d.getHours() + hours);
d.setSeconds(d.getSeconds() + hours * 3600);
return `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, "0")}-${d.getDate().toString().padStart(2, "0")} ${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}`;
}