!4 支持workspaces、badgeCreations保存到app-data

Merge pull request !4 from 豆萁/zh
This commit is contained in:
豆萁 2022-06-25 00:41:09 +00:00 committed by Gitee
commit 273b4e3500
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 54 additions and 51 deletions

View File

@ -152,17 +152,18 @@ export default {
}); });
// Data creations/updates // Data creations/updates
const syncDataByItemId = store.getters['data/syncDataByItemId']; const syncDataById = store.getters['data/syncDataById'];
Object.keys(treeDataMap).forEach((path) => { Object.keys(treeDataMap).forEach((path) => {
// Only template data are stored // Only settings、workspaces、template data are stored
const [, id] = path.match(/^\.stackedit-data\/(templates)\.json$/) || []; const [, id] = path.match(/^\.stackedit-data\/(settings|workspaces|badgeCreations|templates)\.json$/) || [];
if (id) { if (id) {
idsByPath[path] = id; idsByPath[path] = id;
const syncData = syncDataByItemId[id]; idsByPath[id] = id;
const syncData = syncDataById[id];
if (!syncData || syncData.sha !== this.shaByPath[path]) { if (!syncData || syncData.sha !== this.shaByPath[path]) {
const type = 'data'; const type = 'data';
changes.push({ changes.push({
syncDataId: path, syncDataId: id,
item: { item: {
id, id,
type, type,
@ -170,7 +171,7 @@ export default {
hash: 1, hash: 1,
}, },
syncData: { syncData: {
id: path, id,
type, type,
// Need a truthy value to force downloading the content // Need a truthy value to force downloading the content
hash: 1, hash: 1,

View File

@ -113,15 +113,20 @@ export default new Provider({
if (!syncData) { if (!syncData) {
return {}; return {};
} }
const path = `.stackedit-data/${syncData.id}.json`;
// const path = store.getters.gitPathsByItemId[syncData.id];
// const path = syncData.id;
const { sha, data } = await giteeHelper.downloadFile({ const { sha, data } = await giteeHelper.downloadFile({
owner: token.name, owner: token.name,
repo: appDataRepo, repo: appDataRepo,
branch: appDataBranch, branch: appDataBranch,
token, token,
path: syncData.id, path,
}); });
gitWorkspaceSvc.shaByPath[syncData.id] = sha; if (!sha) {
return {};
}
gitWorkspaceSvc.shaByPath[path] = sha;
const item = JSON.parse(data); const item = JSON.parse(data);
return { return {
item, item,
@ -129,6 +134,7 @@ export default new Provider({
...syncData, ...syncData,
hash: item.hash, hash: item.hash,
sha, sha,
type: 'data',
}, },
}; };
}, },
@ -162,21 +168,11 @@ export default new Provider({
async uploadWorkspaceData({ async uploadWorkspaceData({
token, token,
item, item,
syncData,
}) { }) {
const path = store.getters.gitPathsByItemId[item.id]; const path = `.stackedit-data/${item.id}.json`;
if (!path) { // const path = store.getters.gitPathsByItemId[item.id];
return { // const path = syncData.id;
syncData: {
type: item.type,
hash: item.hash,
},
};
}
const syncData = {
id: path,
type: item.type,
hash: item.hash,
};
const res = await giteeHelper.uploadFile({ const res = await giteeHelper.uploadFile({
token, token,
owner: token.name, owner: token.name,
@ -190,6 +186,9 @@ export default new Provider({
return { return {
syncData: { syncData: {
...syncData, ...syncData,
type: item.type,
hash: item.hash,
data: item.data,
sha: res.content.sha, sha: res.content.sha,
}, },
}; };
@ -221,7 +220,7 @@ export default new Provider({
user = committer; user = committer;
} }
const sub = `${giteeHelper.subPrefix}:${user.login}`; const sub = `${giteeHelper.subPrefix}:${user.login}`;
if (user.avatar_url && user.avatar_url.endsWith('.png')) { if (user.avatar_url && user.avatar_url.endsWith('.png') && !user.avatar_url.endsWith('no_portrait.png')) {
user.avatar_url = `${user.avatar_url}!avatar60`; user.avatar_url = `${user.avatar_url}!avatar60`;
} }
userSvc.addUserInfo({ id: sub, name: user.login, imageUrl: user.avatar_url }); userSvc.addUserInfo({ id: sub, name: user.login, imageUrl: user.avatar_url });

View File

@ -135,7 +135,7 @@ export default new Provider({
user = committer; user = committer;
} }
const sub = `${giteeHelper.subPrefix}:${user.login}`; const sub = `${giteeHelper.subPrefix}:${user.login}`;
if (user.avatar_url && user.avatar_url.endsWith('.png')) { if (user.avatar_url && user.avatar_url.endsWith('.png') && !user.avatar_url.endsWith('no_portrait.png')) {
user.avatar_url = `${user.avatar_url}!avatar60`; user.avatar_url = `${user.avatar_url}!avatar60`;
} }
userSvc.addUserInfo({ id: sub, name: user.login, imageUrl: user.avatar_url }); userSvc.addUserInfo({ id: sub, name: user.login, imageUrl: user.avatar_url });

View File

@ -249,7 +249,7 @@ export default new Provider({
user = committer; user = committer;
} }
const sub = `${giteeHelper.subPrefix}:${user.login}`; const sub = `${giteeHelper.subPrefix}:${user.login}`;
if (user.avatar_url && user.avatar_url.endsWith('.png')) { if (user.avatar_url && user.avatar_url.endsWith('.png') && !user.avatar_url.endsWith('no_portrait.png')) {
user.avatar_url = `${user.avatar_url}!avatar60`; user.avatar_url = `${user.avatar_url}!avatar60`;
} }
userSvc.addUserInfo({ id: sub, name: user.login, imageUrl: user.avatar_url }); userSvc.addUserInfo({ id: sub, name: user.login, imageUrl: user.avatar_url });

View File

@ -46,7 +46,7 @@ userSvc.setInfoResolver('gitee', subPrefix, async (sub) => {
}, },
})).body; })).body;
if (user.avatar_url && user.avatar_url.endsWith('.png')) { if (user.avatar_url && user.avatar_url.endsWith('.png') && !user.avatar_url.endsWith('no_portrait.png')) {
user.avatar_url = `${user.avatar_url}!avatar60`; user.avatar_url = `${user.avatar_url}!avatar60`;
} }
return { return {
@ -112,7 +112,7 @@ export default {
access_token: accessToken, access_token: accessToken,
}, },
})).body; })).body;
if (user.avatar_url && user.avatar_url.endsWith('.png')) { if (user.avatar_url && user.avatar_url.endsWith('.png') && !user.avatar_url.endsWith('no_portrait.png')) {
user.avatar_url = `${user.avatar_url}!avatar60`; user.avatar_url = `${user.avatar_url}!avatar60`;
} }
userSvc.addUserInfo({ userSvc.addUserInfo({
@ -309,10 +309,13 @@ export default {
url: `contents/${encodeURIComponent(path)}`, url: `contents/${encodeURIComponent(path)}`,
params: { ref: branch }, params: { ref: branch },
}); });
if (sha) {
return { return {
sha, sha,
data: utils.decodeBase64(content), data: utils.decodeBase64(content),
}; };
}
return {};
}, },
/** /**

View File

@ -539,7 +539,7 @@ const syncDataItem = async (dataId) => {
|| store.state.data.lsItemsById[dataId]; || store.state.data.lsItemsById[dataId];
const oldItem = getItem(); const oldItem = getItem();
const oldSyncData = store.getters['data/syncDataByItemId'][dataId]; const oldSyncData = store.getters['data/syncDataById'][dataId];
// Sync if item hash and syncData hash are out of sync // Sync if item hash and syncData hash are out of sync
if (oldSyncData && oldItem && oldItem.hash === oldSyncData.hash) { if (oldSyncData && oldItem && oldItem.hash === oldSyncData.hash) {
return; return;
@ -548,7 +548,7 @@ const syncDataItem = async (dataId) => {
const token = workspaceProvider.getToken(); const token = workspaceProvider.getToken();
const { item } = updateSyncData(await workspaceProvider.downloadWorkspaceData({ const { item } = updateSyncData(await workspaceProvider.downloadWorkspaceData({
token, token,
syncData: oldSyncData, syncData: oldSyncData || { id: dataId },
})); }));
const serverItem = item; const serverItem = item;
@ -603,14 +603,14 @@ const syncDataItem = async (dataId) => {
updateSyncData(await workspaceProvider.uploadWorkspaceData({ updateSyncData(await workspaceProvider.uploadWorkspaceData({
token, token,
item: mergedItem, item: mergedItem,
syncData: store.getters['data/syncDataByItemId'][dataId], syncData: store.getters['data/syncDataById'][dataId],
ifNotTooLate: tooLateChecker(restartContentSyncAfter), ifNotTooLate: tooLateChecker(restartContentSyncAfter),
})); }));
} }
// Copy sync data into data sync data // Copy sync data into data sync data
store.dispatch('data/patchDataSyncDataById', { store.dispatch('data/patchDataSyncDataById', {
[dataId]: utils.deepCopy(store.getters['data/syncDataByItemId'][dataId]), [dataId]: utils.deepCopy(store.getters['data/syncDataById'][dataId]),
}); });
}; };
@ -728,11 +728,11 @@ const syncWorkspace = async (skipContents = false) => {
// Sync settings, workspaces and badges only in the main workspace // Sync settings, workspaces and badges only in the main workspace
if (workspace.id === 'main') { if (workspace.id === 'main') {
await syncDataItem('settings'); // await syncDataItem('settings');
await syncDataItem('workspaces'); await syncDataItem('workspaces');
await syncDataItem('badgeCreations'); await syncDataItem('badgeCreations');
// await syncDataItem('templates');
} }
await syncDataItem('templates');
if (!skipContents) { if (!skipContents) {
const currentFileId = store.getters['file/current'].id; const currentFileId = store.getters['file/current'].id;

View File

@ -303,7 +303,7 @@
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>丰富的 Markdown 编辑器</h3> <h3>丰富的 Markdown 编辑器</h3>
<p>StackEdit 的 Markdown 语法高亮是独一无二的。 编辑器的精致文本格式可帮助您可视化文件的最终呈现。</p> <p>StackEdit中文版 的 Markdown 语法高亮是独一无二的。 编辑器的精致文本格式可帮助您可视化文件的最终呈现。</p>
</div> </div>
</div> </div>
<div class="column"> <div class="column">
@ -316,14 +316,14 @@
<img class="image" width="410" src="static/landing/navigation-bar.png"> <img class="image" width="410" src="static/landing/navigation-bar.png">
<div class="feature"> <div class="feature">
<h3>所见即所得控件</h3> <h3>所见即所得控件</h3>
<p>StackEdit 提供了非常方便的格式化按钮和快捷方式,这要归功于 Stack Overflow 使用的所见即所得式 Markdown 编辑器 PageDown。</p> <p>StackEdit中文版 提供了非常方便的格式化按钮和快捷方式,这要归功于 Stack Overflow 使用的所见即所得式 Markdown 编辑器 PageDown。</p>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>智能布局</h3> <h3>智能布局</h3>
<p>无论你是写作、阅读还是评论……StackEdit的布局都为你提供了所需的灵活性。</p> <p>无论你是写作、阅读还是评论……StackEdit中文版的布局都为你提供了所需的灵活性。</p>
</div> </div>
</div> </div>
<div class="column"> <div class="column">
@ -333,7 +333,7 @@
<div class="row"> <div class="row">
<div class="feature"> <div class="feature">
<h3>滚动同步实时预览</h3> <h3>滚动同步实时预览</h3>
<p>StackEdit的滚动同步功能精确地绑定了编辑器面板和预览面板的滚动条以确保您在编写时始终关注输出。</p> <p>StackEdit中文版的滚动同步功能精确地绑定了编辑器面板和预览面板的滚动条,以确保您在编写时始终关注输出。</p>
</div> </div>
<img class="image" width="485" src="static/landing/scroll-sync.gif"> <img class="image" width="485" src="static/landing/scroll-sync.gif">
</div> </div>
@ -342,7 +342,7 @@
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>保持同步</h3> <h3>保持同步</h3>
<p>StackEdit 可以将您的文件与 Google Drive、Dropbox 和 GitHub 同步。 它还可以将它们作为博客文章发布到 Blogger、WordPress 和 Zendesk。 您可以选择是以 Markdown 格式、HTML 上传,还是使用 Handlebars 模板引擎格式化输出。</p> <p>StackEdit中文版 可以将您的文件与 Gitee、GitHub、Google Drive 和 Dropbox 同步。 它还可以将它们作为博客文章发布到 Blogger、WordPress 和 Zendesk。 您可以选择是以 Markdown 格式、HTML 上传,还是使用 Handlebars 模板引擎格式化输出。</p>
</div> </div>
</div> </div>
<div class="column"> <div class="column">
@ -353,14 +353,14 @@
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>协作</h3> <h3>协作</h3>
<p>借助 StackEdit您可以共享协作文档空间这要归功于同步机制。 如果两个协作者同时处理同一个文件StackEdit 会负责合并更改。</p> <p>借助 StackEdit中文版,您可以共享协作文档空间,这要归功于同步机制。 如果两个协作者同时处理同一个文件StackEdit中文版 会负责合并更改。</p>
</div> </div>
<img class="image" width="300" src="static/landing/workspace.png"> <img class="image" width="300" src="static/landing/workspace.png">
</div> </div>
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>评论</h3> <h3>评论</h3>
<p>StackEdit 允许您在文件中插入内联评论和嵌入协作者讨论,就像 Microsoft Word 和 Google Docs 一样。</p> <p>StackEdit中文版 允许您在文件中插入内联评论和嵌入协作者讨论,就像 Microsoft Word 和 Google Docs 一样。</p>
</div> </div>
<img class="image" width="395" src="static/landing/discussion.png"> <img class="image" width="395" src="static/landing/discussion.png">
</div> </div>
@ -368,7 +368,7 @@
<div class="row"> <div class="row">
<div class="feature"> <div class="feature">
<h3>离线写作!</h3> <h3>离线写作!</h3>
<p>即使在旅行时StackEdit 仍然可以访问,让您可以像任何桌面应用程序一样离线编写。 你没有借口再偷懒!</p> <p>即使在旅行时StackEdit中文版 仍然可以访问,让您可以像任何桌面应用程序一样离线编写。 你没有借口再偷懒!</p>
</div> </div>
</div> </div>
<h1>扩展的 Markdown 支持</h1> <h1>扩展的 Markdown 支持</h1>
@ -382,7 +382,7 @@
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>GitHub 风格的 Markdown</h3> <h3>GitHub 风格的 Markdown</h3>
<p>StackEdit 支持不同的 Markdown 风格,例如 Markdown Extra、GFM 和 CommonMark。 每个 Markdown 功能都可以在您方便的时候启用或禁用。</p> <p>StackEdit中文版 支持不同的 Markdown 风格,例如 Markdown Extra、GFM 和 CommonMark。 每个 Markdown 功能都可以在您方便的时候启用或禁用。</p>
</div> </div>
</div> </div>
</div> </div>
@ -396,7 +396,7 @@
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>LaTeX 数学表达式</h3> <h3>LaTeX 数学表达式</h3>
<p>StackEdit 从您的 Markdown 文件中的 LaTeX 表达式呈现数学公式。</p> <p>StackEdit中文版 从您的 Markdown 文件中的 LaTeX 表达式呈现数学公式。</p>
</div> </div>
</div> </div>
</div> </div>
@ -409,7 +409,7 @@
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>UML 图</h3> <h3>UML 图</h3>
<p>StackEdit 使您能够使用简单的语法编写序列图和流程图。</p> <p>StackEdit中文版 使您能够使用简单的语法编写序列图和流程图。</p>
</div> </div>
</div> </div>
</div> </div>
@ -422,7 +422,7 @@
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>乐谱</h3> <h3>乐谱</h3>
<p>StackEdit 可以使用 ABC 表示法渲染乐谱。</p> <p>StackEdit中文版 可以使用 ABC 表示法渲染乐谱。</p>
</div> </div>
</div> </div>
</div> </div>
@ -435,7 +435,7 @@
<div class="column"> <div class="column">
<div class="feature"> <div class="feature">
<h3>Emojis表情</h3> <h3>Emojis表情</h3>
<p>StackEdit 支持使用 Markdown 表情符号标记在文件中插入表情符号。</p> <p>StackEdit中文版 支持使用 Markdown 表情符号标记在文件中插入表情符号。</p>
</div> </div>
</div> </div>
</div> </div>