dailyhot-api
Version:
An Api on Today's Hot list
45 lines (44 loc) • 1.46 kB
JavaScript
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
export const handleRoute = async (c, noCache) => {
const sort = c.req.query("sort") || "featured";
const listData = await getList({ sort }, noCache);
const routeData = {
name: "hellogithub",
title: "HelloGitHub",
type: "热门仓库",
description: "分享 GitHub 上有趣、入门级的开源项目",
params: {
sort: {
name: "排行榜分区",
type: {
featured: "精选",
all: "全部",
},
},
},
link: "https://hellogithub.com/",
total: listData.data?.length || 0,
...listData,
};
return routeData;
};
const getList = async (options, noCache) => {
const { sort } = options;
const url = `https://abroad.hellogithub.com/v1/?sort_by=${sort}&tid=&page=1`;
const result = await get({ url, noCache });
const list = result.data.data;
return {
...result,
data: list.map((v) => ({
id: v.item_id,
title: v.title,
desc: v.summary,
author: v.author,
timestamp: getTime(v.updated_at),
hot: v.clicks_total,
url: `https://hellogithub.com/repository/${v.item_id}`,
mobileUrl: `https://hellogithub.com/repository/${v.item_id}`,
})),
};
};