forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dockerhub): 添加 DockerHub 仓库路由 (DIYgod#17691)
* feat(dockerhub): 添加 DockerHub 仓库路由 - 新增 DockerHub 仓库路由,支持获取指定用户的仓库列表 - 支持分页获取仓库信息,默认每页10条记录 * feat(dockerhub): add description for DockerHub repositories route - 添加 DockerHub 仓库路由的描述信息 * refactor(dockerhub): 优化 DockerHub 仓库路由配置 - 修改路由名称和示例路径以提高可读性 - 将 owner 参数转换为小写以确保一致性 - 从查询参数中解析 limit 并设置默认值为 10
- Loading branch information
1 parent
3db53f5
commit 0ea051c
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |