♻️ refactor: update changelog cache and upgrade anthropic sdk (#5829)

* update

* fix tests
This commit is contained in:
Arvin Xu
2025-02-07 14:55:18 +08:00
committed by GitHub
parent 985869c32a
commit 620df2f20d
4 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -104,7 +104,7 @@
"dependencies": {
"@ant-design/icons": "^5.5.2",
"@ant-design/pro-components": "^2.8.3",
"@anthropic-ai/sdk": "^0.33.1",
"@anthropic-ai/sdk": "^0.36.3",
"@auth/core": "^0.37.4",
"@aws-sdk/client-bedrock-runtime": "^3.723.0",
"@aws-sdk/client-s3": "^3.723.0",
+3
View File
@@ -0,0 +1,3 @@
export enum FetchCacheTag {
Changelog = 'changelog',
}
@@ -11,7 +11,8 @@ export const buildAnthropicBlock = async (
): Promise<Anthropic.ContentBlock | Anthropic.ImageBlockParam> => {
switch (content.type) {
case 'text': {
return content;
// just pass-through the content
return content as any;
}
case 'image_url': {
+12 -4
View File
@@ -4,6 +4,7 @@ import { markdownToTxt } from 'markdown-to-txt';
import semver from 'semver';
import urlJoin from 'url-join';
import { FetchCacheTag } from '@/const/cacheControl';
import { Locales } from '@/locales/resources';
import { ChangelogIndexItem } from '@/types/changelog';
@@ -47,7 +48,9 @@ export class ChangelogService {
try {
const url = this.genUrl(urlJoin(this.config.docsPath, 'index.json'));
const res = await fetch(url);
const res = await fetch(url, {
next: { revalidate: 3600, tags: [FetchCacheTag.Changelog] },
});
const data = await res.json();
@@ -79,7 +82,10 @@ export class ChangelogService {
const filename = options?.locale?.startsWith('zh') ? `${id}.zh-CN.mdx` : `${id}.mdx`;
const url = this.genUrl(urlJoin(this.config.docsPath, filename));
const response = await fetch(url);
const response = await fetch(url, {
next: { revalidate: 3600, tags: [FetchCacheTag.Changelog] },
});
const text = await response.text();
const { data, content } = matter(text);
@@ -122,8 +128,10 @@ export class ChangelogService {
content: description,
rawTitle: match ? match[1] : '',
};
} catch {
console.error('Error getting changlog post by id', id);
} catch (e) {
console.error('[ChangelogFetchError]failed to fetch changlog post', id);
console.error(e);
return false as any;
}
}