Skip to content

Commit

Permalink
feat(dockerhub): 添加 DockerHub 仓库路由 (#17691)
Browse files Browse the repository at this point in the history
* feat(dockerhub): 添加 DockerHub 仓库路由
- 新增 DockerHub 仓库路由,支持获取指定用户的仓库列表
- 支持分页获取仓库信息,默认每页10条记录

* feat(dockerhub): add description for DockerHub repositories route
- 添加 DockerHub 仓库路由的描述信息

* refactor(dockerhub): 优化 DockerHub 仓库路由配置
- 修改路由名称和示例路径以提高可读性
- 将 owner 参数转换为小写以确保一致性
- 从查询参数中解析 limit 并设置默认值为 10
  • Loading branch information
CaoMeiYouRen authored Nov 24, 2024
1 parent 3db53f5 commit 0ea051c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/routes/dockerhub/repositories.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}

0 comments on commit 0ea051c

Please sign in to comment.