repo_description: 🔥 今日热榜 API，一个聚合热门数据的 API 接口，支持 RSS 模式 及 Vercel 部署 | 前端页面：https://github.com/imsyy/DailyHot
repo_topics: api daily-hot list rss vercel
code: import type { ListContext, Options, RouterData } from "../types.js";
  import { get } from "../utils/getData.js";
  import { getTime } from "../utils/getTime.js";
  
  const typeMap: Record<string, string> = {
    "1": "今日热门",
    "7": "周热门",
    "30": "月热门",
  };
  
  export const handleRoute = async (c: ListContext, noCache: boolean) => {
    const type = c.req.query("type") || "1";
    const listData = await getList({ type }, noCache);
    const routeData: RouterData = {
      name: "smzdm",
      title: "什么值得买",
      type: typeMap[type],
      description:
        "什么值得买是一个中立的、致力于帮助广大网友买到更有性价比网购产品的最热门推荐网站。",
      link: "https://www.smzdm.com/top/",
      params: {
        type: {
          name: "文章分类",
          type: typeMap,
        },
      },
      total: listData.data?.length || 0,
      ...listData,
    };
    return routeData;
  };
  
  interface SmzdmItem {
    article_id: string;
    title: string;
    content: string;
    pic_url: string;
    nickname: string;
    collection_count: string;
    time_sort: string;
    jump_link: string;
  }
  
  interface SmzdmResponse {
    data: SmzdmItem[];
  }
  
  const getList = async (options: Options, noCache: boolean) => {
    const { type } = options;
    const url = `https://post.smzdm.com/rank/json_more/?unit=${type}`;
    const result = await get<SmzdmResponse>({ url, noCache });
    const list = result.data.data;
    return {
      ...result,
      data: list.map((v) => ({
        id: v.article_id,
        title: v.title,
        desc: v.content,
        cover: v.pic_url,
        author: v.nickname,
        hot: Number(v.collection_count),
        timestamp: getTime(v.time_sort),
        url: v.jump_link,
        mobileUrl: v.jump_link,
      })),
    };
  };
  