Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tencent cloud column #15673

Merged
merged 8 commits into from
May 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions lib/routes/tencent/cloud/developer/column.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch'; // 统一使用的请求库
import { parseDate } from '@/utils/parse-date';
import cache from '@/utils/cache';

const PAGE = 1;
const PAGE_SIZE = 20;
Expand Down Expand Up @@ -50,8 +51,8 @@ export const route: Route = {

const classify = await findClassifyById(categoryId);

const title = '腾讯云开发者社区';
const description = classify.length > 0 ? classify[0].name : '';
const title = classify ? classify.name : '';
const description = `${title} - 腾讯云开发者社区`;

return {
title,
Expand All @@ -62,17 +63,19 @@ export const route: Route = {
};

async function findClassifyById(id) {
const classifylink = `https://cloud.tencent.com/developer/api/column/get-classify-list-by-scene`;
const response = await ofetch(classifylink, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: {
scene: 0,
},
const classifylink = 'https://cloud.tencent.com/developer/api/column/get-classify-list-by-scene';
const result = await cache.tryGet(classifylink, async () => {
const response = await ofetch(classifylink, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: {
scene: 0,
},
});
return response.list.find((classify) => classify.id === Number(id));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please cache the response.

Cache the HTML response only. Otherwise, findClassifyById will return the same thing for different id.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});

const result = response.list.filter((classify) => classify.id === Number(id));
return result;
}