feat: add Visual Studio Code Marketplace (#3430)

This commit is contained in:
SeanChao
2019-11-19 17:20:53 +08:00
committed by DIYgod
parent 9bb50dbc05
commit e031a54dfb
3 changed files with 54 additions and 1 deletions

View File

@@ -240,6 +240,18 @@ GitHub 官方也提供了一些 RSS:
<Route author="xyqfer" example="/testerhome/newest" path="/testerhome/newest"/>
## Visual Studio Code Marketplace
### Visual Studio Code 插件
<Route author="SeanChao" example="/vscode/marketplace" path="/vscode/marketplace/:category?" :paramsDesc="['分类']">
| Featured | Trending Weekly | Trending Monthly | Trending Daily | Most Popular | Recently Added |
| -------- | --------------- | ---------------- | -------------- | ------------ | -------------- |
| featured | trending | trending_m | trending_d | popular | new |
</Route>
## 阿里云
### 数据库内核月报

View File

@@ -260,7 +260,6 @@ router.get('/github/search/:query/:sort?/:order?', require('./routes/github/sear
router.get('/github/branches/:user/:repo', require('./routes/github/branches'));
router.get('/github/file/:user/:repo/:branch/:filepath+', require('./routes/github/file'));
router.get('/github/starred_repos/:user', require('./routes/github/starred_repos'));
// f-droid
router.get('/fdroid/apprelease/:app', require('./routes/fdroid/apprelease'));
@@ -1936,4 +1935,7 @@ router.get('/gov/cnca/hydt', require('./routes/gov/cnca/hydt'));
router.get('/gov/cnca/zxtz', require('./routes/gov/cnca/zxtz'));
// Visual Studio Code Marketplace
router.get('/vscode/marketplace/:type?', require('./routes/vscode/marketplace'));
module.exports = router;

View File

@@ -0,0 +1,39 @@
const got = require('got');
const url = require('url');
module.exports = async (ctx) => {
const type = ctx.params.type || 'featured';
const category = {
featured: { id: 0, section: 'Featured' },
trending: { id: 1, section: 'Trending Weekly' },
trending_w: { id: 1, section: 'Trending Weekly' },
trending_d: { id: 2, section: 'Trending Daily' },
trending_m: { id: 3, section: 'Trending Monthly' },
popular: { id: 4, section: 'Most Popular' },
new: { id: 5, section: 'Recently Added' },
};
const rootLink = 'https://marketplace.visualstudio.com/';
const response = await got('https://marketplace.visualstudio.com/getextensionspercategory?Product=vscode&RemoveFirstSetCategories=true');
const jsonData = JSON.parse(response.body);
const extensionsList = jsonData.epc[category[type].id].e;
const out =
extensionsList &&
extensionsList.map((item) => {
const title = item.t;
const description = item.s;
const link = url.resolve(rootLink, item.l);
const author = item.a;
return {
title,
description,
link,
author,
};
});
ctx.state.data = {
title: 'VS Code Extensions: ' + category[type].section,
link: 'https://marketplace.visualstudio.com/',
item: out,
};
};