Files
RSSHub/lib/routes/dockerhub/build.js
2019-06-03 18:03:05 +08:00

30 lines
933 B
JavaScript

const got = require('@/utils/got');
module.exports = async (ctx) => {
const { owner, image, tag = 'latest' } = ctx.params;
const namespace = `${owner}/${image}`;
const link = `https://hub.docker.com/r/${namespace}`;
const data = await got.get(`https://hub.docker.com/v2/repositories/${namespace}/tags/?page_size=5`);
const metadata = await got.get(`https://hub.docker.com/v2/repositories/${namespace}`);
const list = data.data.results.filter((a) => a.name === tag);
const out = list.map((item) => ({
title: `${namespace}:${tag} was built. ${(item.images[0].size / 1000000).toFixed(2)} MB`,
link,
author: owner,
pubDate: new Date(item.last_updated).toUTCString(),
guid: item.last_updated,
}));
ctx.state.data = {
title: `${namespace}:${tag} build history`,
description: metadata.description,
link,
item: out,
};
};