feat(route): add Microsoft Artifact Registry route (#15973)

* Add Microsoft Artifact Registry route

* Update category

* Add braces around arrow function bodies

* Remove semicolons

* Change string interpolation

* Add required semicolons

* Set product parameter as wildcard

* Refactor the code

And fix the issues with the return of got

* Correct the item link

* Change descriptions separator to new line

* Move mcr.microsoft to microsoft route

* Correct the path
This commit is contained in:
Hossein Margani 2024-06-24 17:06:53 +01:00 committed by GitHub
parent 960d526a8b
commit 01147c7623
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 65 additions and 2 deletions

View File

@ -0,0 +1,63 @@
import { Route } from '@/types';
import got from '@/utils/got';
export const route: Route = {
path: '/mcr/product/*',
categories: ['program-update'],
example: '/microsoft/mcr/product/dotnet/framework/runtime',
parameters: { product: 'repository path in mcr.microsoft.com' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['https://mcr.microsoft.com/en-us/product/:product/tags'],
},
],
name: 'Product tags in mcr.microsoft.com',
maintainers: ['margani'],
handler,
};
async function handler(ctx) {
const product = ctx.req.path.replace('/microsoft/mcr/product/', '');
const { data: details } = await got({
method: 'get',
url: `https://mcr.microsoft.com/api/v1/catalog/${product}/details`,
});
const { data: tags } = await got({
method: 'get',
url: `https://mcr.microsoft.com/api/v1/catalog/${product}/tags`,
});
return {
title: `${details.name} - Microsoft Artifact Registry`,
description: String(details.shortDescription),
image: `https://mcr.microsoft.com${details.imagePath}`,
link: `https://mcr.microsoft.com/en-us/product/${product}`,
item: tags.map((tag: any) => {
const descriptionItems = [`Digest: \`${tag.digest}\``, `Last modified date: ${new Date(tag.lastModifiedDate).toDateString()}`];
if (tag.architecture) {
descriptionItems.push(`Architecture: ${tag.architecture}`);
}
if (tag.operatingSystem) {
descriptionItems.push(`Operating system: ${tag.operatingSystem}`);
}
return {
title: `${details.name} - ${tag.name}`,
author: details.publisher,
description: descriptionItems.join('<br />'),
pubDate: new Date(tag.lastModifiedDate),
guid: `mcr::${product}::${tag.name}::${tag.digest}`,
link: `https://mcr.microsoft.com/en-us/product/${product}/tags`,
};
}),
};
}

View File

@ -1,6 +1,6 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Microsoft Edge',
url: 'microsoftedge.microsoft.com',
name: 'Microsoft',
url: 'microsoft.com',
};