feat(dockerhub): 添加 DockerHub 仓库路由 (#17691)
* feat(dockerhub): 添加 DockerHub 仓库路由 - 新增 DockerHub 仓库路由,支持获取指定用户的仓库列表 - 支持分页获取仓库信息,默认每页10条记录 * feat(dockerhub): add description for DockerHub repositories route - 添加 DockerHub 仓库路由的描述信息 * refactor(dockerhub): 优化 DockerHub 仓库路由配置 - 修改路由名称和示例路径以提高可读性 - 将 owner 参数转换为小写以确保一致性 - 从查询参数中解析 limit 并设置默认值为 10
This commit is contained in:
parent
3db53f5d5f
commit
0ea051c2fe
|
|
@ -0,0 +1,42 @@
|
|||
import { Route, ViewType } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import { Context } from 'hono';
|
||||
|
||||
export const route: Route = {
|
||||
name: 'Owner Repositories',
|
||||
description: 'List of repositories for an image owner',
|
||||
maintainers: ['CaoMeiYouRen'],
|
||||
path: '/repositories/:owner',
|
||||
categories: ['program-update'],
|
||||
view: ViewType.Notifications,
|
||||
example: '/dockerhub/repositories/diygod',
|
||||
parameters: { owner: 'Image owner' },
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx: Context) {
|
||||
const owner = ctx.req.param('owner').toLowerCase();
|
||||
const limit = Number.parseInt(ctx.req.query('limit') || '10');
|
||||
const link = `https://hub.docker.com/r/${owner}`;
|
||||
const url = `https://hub.docker.com/v2/repositories/${owner}`;
|
||||
const response = await got(url, {
|
||||
searchParams: {
|
||||
page_size: limit,
|
||||
},
|
||||
});
|
||||
const item = response.data.results.map((repo) => ({
|
||||
title: repo.name,
|
||||
description: `${repo.description}<br>status: ${repo.status_description}<br>stars: ${repo.star_count}<br>pulls: ${repo.pull_count}`,
|
||||
link: `https://hub.docker.com/r/${owner}/${repo.name}`,
|
||||
author: owner,
|
||||
pubDate: parseDate(repo.last_updated),
|
||||
guid: `${owner}/${repo.name}`,
|
||||
}));
|
||||
return {
|
||||
title: `${owner} repositories`,
|
||||
description: `List of repositories for ${owner}`,
|
||||
link,
|
||||
item,
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue