github作为主空间时的bug修复

This commit is contained in:
xiaoqi.cxq 2023-12-20 11:21:01 +08:00
parent b4f4c71f85
commit 3467a6ee09

View File

@ -169,7 +169,7 @@ export default {
if (err.status === 404) { if (err.status === 404) {
await request(token, { await request(token, {
method: 'POST', method: 'POST',
url: 'https://api.github.com/repos/mafgwo/stackeditplus-appdata-template/generate', url: 'https://api.github.com/repos/mafgwo/stackedit-appdata-template/generate',
body: { body: {
owner: token.name, owner: token.name,
name: appDataRepo, name: appDataRepo,
@ -193,11 +193,29 @@ export default {
repo, repo,
sha, sha,
path, path,
tryTimes,
}) { }) {
let tryCount = tryTimes || 1;
try {
return repoRequest(token, owner, repo, { return repoRequest(token, owner, repo, {
url: 'commits', url: 'commits',
params: { sha, path }, params: { sha, path },
}); });
} catch (err) {
// 主文档 并且 409 则重试3次
if (tryCount <= 3 && err.status === 409 && repo === appDataRepo) {
tryCount += 1;
return this.getCommits({
token,
owner,
repo,
sha,
path,
tryTimes: tryCount,
});
}
throw err;
}
}, },
/** /**
@ -270,6 +288,7 @@ export default {
path, path,
isImg, isImg,
}) { }) {
try {
const { sha, content, encoding } = await repoRequest(token, owner, repo, { const { sha, content, encoding } = await repoRequest(token, owner, repo, {
url: `contents/${encodeURIComponent(path)}`, url: `contents/${encodeURIComponent(path)}`,
params: { ref: branch }, params: { ref: branch },
@ -286,6 +305,13 @@ export default {
sha, sha,
data: !isImg ? utils.decodeBase64(tempContent) : tempContent, data: !isImg ? utils.decodeBase64(tempContent) : tempContent,
}; };
} catch (err) {
// not .stackedit-data throw err
if (err.status === 404 && path.indexOf('.stackedit-data') >= 0) {
return {};
}
throw err;
}
}, },
/** /**
* 获取仓库信息 * 获取仓库信息