Skip to content

Commit

Permalink
fix: 前台构建器减少初始化边缘情况引起的错误日志
Browse files Browse the repository at this point in the history
  • Loading branch information
Mereithhh committed Aug 26, 2022
1 parent 31fca3b commit f28525b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 35 deletions.
5 changes: 4 additions & 1 deletion packages/website/api/addViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export async function addViewer(pathname: string): Promise<any> {
const res = await fetch(url, {
method: "POST",
});
const { data } = await res.json();
const { statusCode, data } = await res.json();
if (statusCode == 233) {
return { viewer: 0, visited: 0 };
}
return data;
} catch (err) {
console.log(err);
Expand Down
77 changes: 44 additions & 33 deletions packages/website/api/getAllData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,53 @@ export interface PublicAllProp {
}
export const version = process.env["VAN_BLOG_VERSION"] || "dev";

const defaultMeta: MetaProps = {
categories: [],
menus: [],
links: [],
socials: [],
rewards: [],
about: {
updatedAt: new Date().toISOString(),
content: "",
},
siteInfo: {
author: "作者名字",
authorDesc: "作者描述",
authorLogo: "/logo.svg",
siteLogo: "/logo.svg",
favicon: "/logo.svg",
siteName: "VanBlog",
siteDesc: "Vanblog",
beianNumber: "",
beianUrl: "",
payAliPay: "",
payWechat: "",
payAliPayDark: "",
payWechatDark: "",
since: "",
enableComment: "true",
baseUrl: "",
showDonateInfo: "true",
showFriends: "true",
showAdminButton: "true",
},
};

export async function getPublicMeta(): Promise<PublicMetaProp> {
try {
const url = `${config.baseUrl}api/public/meta`;
const res = await fetch(url);
const { data } = await res.json();
const { statusCode, data } = await res.json();
if (statusCode == 233) {
return {
version: version,
totalWordCount: 0,
tags: [],
totalArticles: 0,
meta: defaultMeta,
};
}
return data;
} catch (err) {
if (process.env.isBuild == "t") {
Expand All @@ -96,38 +138,7 @@ export async function getPublicMeta(): Promise<PublicMetaProp> {
totalWordCount: 0,
tags: [],
totalArticles: 0,
meta: {
categories: [],
menus: [],
links: [],
socials: [],
rewards: [],
about: {
updatedAt: new Date().toISOString(),
content: "",
},
siteInfo: {
author: "作者名字",
authorDesc: "作者描述",
authorLogo: "",
siteLogo: "/logo.svg",
favicon: "/logo.svg",
siteName: "VanBlog",
siteDesc: "Vanblog",
beianNumber: "",
beianUrl: "",
payAliPay: "",
payWechat: "",
payAliPayDark: "",
payWechatDark: "",
since: "",
enableComment: "true",
baseUrl: "",
showDonateInfo: "true",
showFriends: "true",
showAdminButton: "true",
},
},
meta: defaultMeta,
};
} else {
throw err;
Expand Down
5 changes: 4 additions & 1 deletion packages/website/api/getArticles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export const getArticlesByOption = async (
try {
const url = `${config.baseUrl}api/public/article?${queryString}`;
const res = await fetch(url);
const { data } = await res.json();
const { statusCode, data } = await res.json();
if (statusCode == 233) {
return { articles: [], total: 0, totalWordCount: 0 };
}
return data;
} catch (err) {
if (process.env.isBuild == "t") {
Expand Down

0 comments on commit f28525b

Please sign in to comment.