From 38efae7c491f4386d5f17ec1077b3dfc9dfefce9 Mon Sep 17 00:00:00 2001 From: mei Date: Mon, 10 Feb 2025 09:47:51 +0800 Subject: [PATCH] fix: weekly_rank --- components/database-stats.tsx | 4 +- components/server-stats.tsx | 2 +- components/uploader-search.tsx | 2 +- components/video-search.tsx | 246 +++++++++++++-------------------- 4 files changed, 100 insertions(+), 154 deletions(-) diff --git a/components/database-stats.tsx b/components/database-stats.tsx index 5c49ecb..85d30bd 100644 --- a/components/database-stats.tsx +++ b/components/database-stats.tsx @@ -18,8 +18,8 @@ export default function DatabaseStats() { const fetchCounts = async () => { try { setLoading(true) - const videoResponse = await fetch("https://api.ninevocalrank.top/basic/v1/database/video_count") - const uploaderResponse = await fetch("https://api.ninevocalrank.top/basic/v1/database/uploader_count") + const videoResponse = await fetch("https://ecs-113-44-166-103.compute.hwclouds-dns.com/basic/v1/database/video_count") + const uploaderResponse = await fetch("https://ecs-113-44-166-103.compute.hwclouds-dns.com/basic/v1/database/uploader_count") if (!videoResponse.ok || !uploaderResponse.ok) { throw new Error("服务器响应错误") diff --git a/components/server-stats.tsx b/components/server-stats.tsx index 07eeed7..72fd838 100644 --- a/components/server-stats.tsx +++ b/components/server-stats.tsx @@ -13,7 +13,7 @@ export default function ServerStats() { const fetchServerStat = async () => { try { setLoading(true) - const response = await fetch("https://api.ninevocalrank.top/basic/v1/ServerStat/info") + const response = await fetch("https://ecs-113-44-166-103.compute.hwclouds-dns.com/basic/v1/ServerStat/info") if (!response.ok) { throw new Error("服务器响应错误") } diff --git a/components/uploader-search.tsx b/components/uploader-search.tsx index 057a6e9..2901d2a 100644 --- a/components/uploader-search.tsx +++ b/components/uploader-search.tsx @@ -29,7 +29,7 @@ export default function UploaderSearch() { setLoading(true) setError(null) try { - const response = await fetch(`https://api.ninevocalrank.top/basic/v1/uploader/${uid}`) + const response = await fetch(`https://ecs-113-44-166-103.compute.hwclouds-dns.com/basic/v1/uploader/${uid}`) if (!response.ok) { throw new Error("服务器响应错误") } diff --git a/components/video-search.tsx b/components/video-search.tsx index 7fb14af..6dfb850 100644 --- a/components/video-search.tsx +++ b/components/video-search.tsx @@ -1,119 +1,117 @@ -"use client"; +"use client" -import { useState } from "react"; -import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; -import { Input } from "@/components/ui/input"; -import { Button } from "@/components/ui/button"; -import { Loader2 } from "lucide-react"; +import { useState } from "react" +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" +import { Input } from "@/components/ui/input" +import { Button } from "@/components/ui/button" +import { Loader2 } from "lucide-react" interface Video { video_stat: { - view: number; - like: number; - coin: number; - favorite: number; - reply: number; - share: number; - danmaku: number; - }; + view: number + like: number + coin: number + favorite: number + reply: number + share: number + danmaku: number + } video_info: { - uploader_mid: string; - uploader_name: string; - title: string; - pic: string; - pages: number; - timestamp: number; - }; + uploader_mid: string + uploader_name: string + title: string + pic: string + pages: number + timestamp: number + } video_id: { - avid: string; - bvid: string; - }; + avid: string + bvid: string + } vrank_info: { - vrank_score: number; - rank: string; - rank_code: number; - progress_percentage: number; - }; + vrank_score: number + rank: string + rank_code: number + progress_percentage: number + } video_increase: { - view: number; - like: number; - coin: number; - favorite: number; - reply: number; - share: number; - danmaku: number; - }; - score_rank: number; + view: number + like: number + coin: number + favorite: number + reply: number + share: number + danmaku: number + } + score_rank: number } function getAchievement(views: number) { - if (views >= 10000000) return { name: "神话曲", next: null, progress: 100 }; + if (views >= 10000000) return { name: "神话曲", next: null, progress: 100 } if (views >= 1000000) return { name: "传说曲", next: "神话曲", progress: (views / 10000000) * 100, - }; + } if (views >= 100000) return { name: "殿堂曲", next: "传说曲", progress: (views / 1000000) * 100, - }; - return { name: "未达成", next: "殿堂曲", progress: (views / 100000) * 100 }; + } + return { name: "未达成", next: "殿堂曲", progress: (views / 100000) * 100 } } export default function VideoSearch() { - const [searchTerm, setSearchTerm] = useState(""); - const [videos, setVideos] = useState([]); - const [loading, setLoading] = useState(false); - const [error, setError] = useState(null); + const [searchTerm, setSearchTerm] = useState("") + const [videos, setVideos] = useState([]) + const [loading, setLoading] = useState(false) + const [error, setError] = useState(null) const handleSearch = async () => { if (!searchTerm) { - setError("请输入搜索内容"); - return; + setError("请输入搜索内容") + return } - setLoading(true); - setError(null); + setLoading(true) + setError(null) try { const response = await fetch( - `https://api.ninevocalrank.top/vocaloid_rank/v1/video/${searchTerm}` - ); + `https://ecs-113-44-166-103.compute.hwclouds-dns.com/vocaloid_rank/v1/video/${searchTerm}`, + ) const weekly_response = await fetch( - `https://api.ninevocalrank.top/vocaloid_rank/v1/video/${searchTerm}` - ); + `https://ecs-113-44-166-103.compute.hwclouds-dns.com/vocaloid_rank/v1/sorted/${searchTerm}`, + ) if (!response.ok || !weekly_response.ok) { - throw new Error("服务器响应错误"); + throw new Error("服务器响应错误") } - const data = await response.json(); - const weekly_data = await weekly_response.json(); + const data = await response.json() + const weekly_data = await weekly_response.json() // 合并 data 和 weekly_data const combinedData = { ...data, - weekly_data: weekly_data, - }; + score_rank: weekly_data.score_rank, + } - setVideos([combinedData]); + setVideos([combinedData]) if (videos.length === 0) { - setError("未找到匹配的视频"); + setError("未找到匹配的视频") } } catch (error) { - console.error("搜索视频时出错:", error); - setError("搜索过程中出现错误"); + console.error("搜索视频时出错:", error) + setError("搜索过程中出现错误") } finally { - setLoading(false); + setLoading(false) } - }; + } return ( - - 搜索视频 - + 搜索视频
@@ -131,69 +129,40 @@ export default function VideoSearch() { {videos.length > 0 ? (
    {videos.map((video) => { - const achievement = getAchievement(video.video_stat.view); + const achievement = getAchievement(video.video_stat.view) return ( -
  • +
  • {/* eslint-disable-next-line @next/next/no-img-element */} 视频封面
    -

    - {video.video_info.title} -

    +

    {video.video_info.title}

    - UP主: {video.video_info.uploader_name} (UID:{" "} - {video.video_info.uploader_mid}) -

    -

    - BV号: {video.video_id.bvid} -

    -

    - AV号: {video.video_id.avid} + UP主: {video.video_info.uploader_name} (UID: {video.video_info.uploader_mid})

    +

    BV号: {video.video_id.bvid}

    +

    AV号: {video.video_id.avid}

    -

    - 播放量: {video.video_stat.view.toLocaleString()} -

    -

    - 点赞数: {video.video_stat.like.toLocaleString()} -

    -

    - 投币: {video.video_stat.coin.toLocaleString()} -

    -

    - 收藏: {video.video_stat.favorite.toLocaleString()} -

    -

    - 评论: {video.video_stat.reply.toLocaleString()} -

    -

    - 分享: {video.video_stat.share.toLocaleString()} -

    -

    - 弹幕数: {video.video_stat.danmaku.toLocaleString()} -

    +

    播放量: {video.video_stat.view.toLocaleString()}

    +

    点赞数: {video.video_stat.like.toLocaleString()}

    +

    投币: {video.video_stat.coin.toLocaleString()}

    +

    收藏: {video.video_stat.favorite.toLocaleString()}

    +

    评论: {video.video_stat.reply.toLocaleString()}

    +

    分享: {video.video_stat.share.toLocaleString()}

    +

    弹幕数: {video.video_stat.danmaku.toLocaleString()}

    周刊数据

    {video.vrank_info ? ( <> -

    - 周刊得分:{" "} - {video.vrank_info.vrank_score.toFixed(2)} -

    -

    - 周刊排名: {video.score_rank} -

    +

    周刊得分: {video.vrank_info.vrank_score.toFixed(2)}

    +

    周刊排名: {video.score_rank}

    ) : (

    暂无周刊数据

    @@ -202,48 +171,24 @@ export default function VideoSearch() { <>
    数据增长:
    +

    播放增长: {video.video_increase.view.toLocaleString()}

    +

    点赞增长: {video.video_increase.like.toLocaleString()}

    +

    投币增长: {video.video_increase.coin.toLocaleString()}

    - 播放增长:{" "} - {video.video_increase.view.toLocaleString()} -

    -

    - 点赞增长:{" "} - {video.video_increase.like.toLocaleString()} -

    -

    - 投币增长:{" "} - {video.video_increase.coin.toLocaleString()} -

    -

    - 收藏增长:{" "} - {video.video_increase.favorite.toLocaleString()} -

    -

    - 评论增长:{" "} - {video.video_increase.reply.toLocaleString()} -

    -

    - 分享增长:{" "} - {video.video_increase.share.toLocaleString()} -

    -

    - 弹幕增长:{" "} - {video.video_increase.danmaku.toLocaleString()} + 收藏增长: {video.video_increase.favorite.toLocaleString()}

    +

    评论增长: {video.video_increase.reply.toLocaleString()}

    +

    分享增长: {video.video_increase.share.toLocaleString()}

    +

    弹幕增长: {video.video_increase.danmaku.toLocaleString()}

    )}

    - 数据更新时间:{" "} - {new Date( - video.video_info.timestamp * 1000 - ).toLocaleString("zh-CN")} + 数据更新时间: {new Date(video.video_info.timestamp * 1000).toLocaleString("zh-CN")}

    -

    - 成就: {achievement.name} -

    +

    成就: {achievement.name}

    {achievement.next && (

    @@ -251,8 +196,8 @@ export default function VideoSearch() { {(achievement.next === "殿堂曲" ? 100000 : achievement.next === "传说曲" - ? 1000000 - : 10000000) - video.video_stat.view}{" "} + ? 1000000 + : 10000000) - video.video_stat.view}{" "} 播放

    @@ -267,7 +212,7 @@ export default function VideoSearch() {
  • - ); + ) })}
) : ( @@ -275,5 +220,6 @@ export default function VideoSearch() { )} - ); + ) } +