main workspaces bugfix

This commit is contained in:
xiaoqi.cxq 2022-06-07 06:35:35 +08:00
parent f0612d1120
commit 8b55b32ec8
4 changed files with 24 additions and 10 deletions

View File

@ -1,4 +1,4 @@
FROM node:11.15.0
FROM mafgwo/wkhtmltopdf-nodejs:11.15.0
RUN mkdir -p /opt/stackedit
WORKDIR /opt/stackedit

View File

@ -1,6 +1,6 @@
{
"name": "stackedit",
"version": "5.15.5",
"version": "5.15.6",
"description": "Free, open-source, full-featured Markdown editor",
"author": "Benoit Schweblin",
"license": "Apache-2.0",

View File

@ -68,7 +68,7 @@ export default {
/**
* https://developer.gitee.com/apps/building-oauth-apps/authorization-options-for-oauth-apps/
*/
async startOauth2(lastRefreshToken, silent = false) {
async startOauth2(lastToken, silent = false, isMain) {
const clientId = store.getters['data/serverConf'].giteeClientId;
let tokenBody;
if (!silent) {
@ -99,7 +99,7 @@ export default {
url: 'https://gitee.com/oauth/token',
params: {
grant_type: 'refresh_token',
refresh_token: lastRefreshToken,
refresh_token: lastToken.refreshToken,
},
})).body;
}
@ -112,23 +112,32 @@ export default {
access_token: accessToken,
},
})).body;
if (user.avatar_url && user.avatar_url.endsWith('.png')) {
user.avatar_url = `${user.avatar_url}!avatar60`;
}
userSvc.addUserInfo({
id: `${subPrefix}:${user.login}`,
name: user.login,
imageUrl: user.avatar_url || '',
});
// 获取同一个用户的登录token
const existingToken = store.getters['data/giteeTokensBySub'][user.login];
// Build token object including sub 在token失效后刷新token 如果刷新失败则触发重新授权
const token = {
accessToken,
// 主文档空间的登录 标识登录
isLogin: !!isMain || (existingToken && !!existingToken.isLogin),
refreshToken: tokenBody.refresh_token,
expiresOn: Date.now() + (tokenBody.expires_in * 1000),
name: user.login,
sub: `${user.login}`,
};
// 检查 stackedit-app-data 仓库是否已经存在 如果不存在则创建该仓库
await this.checkAndCreateRepo(token);
if (isMain) {
// 检查 stackedit-app-data 仓库是否已经存在 如果不存在则创建该仓库
await this.checkAndCreateRepo(token);
}
// Add token to gitee tokens
store.dispatch('data/addGiteeToken', token);
return token;
@ -153,7 +162,7 @@ export default {
// existing token is about to expire.
// Try to get a new token in background
try {
return await this.startOauth2(lastToken.refreshToken, true);
return await this.startOauth2(lastToken, true);
} catch (err) {
// If it fails try to popup a window
if (store.state.offline) {
@ -167,7 +176,7 @@ export default {
}
},
signin() {
return this.startOauth2();
return this.startOauth2(null, false, true);
},
async addAccount() {
const token = await this.startOauth2();

View File

@ -57,7 +57,12 @@ export default {
lastSyncActivityKey: (state, { currentWorkspace }) => `${currentWorkspace.id}/lastSyncActivity`,
lastFocusKey: (state, { currentWorkspace }) => `${currentWorkspace.id}/lastWindowFocus`,
mainWorkspaceToken: (state, getters, rootState, rootGetters) =>
utils.someResult(Object.values(rootGetters['data/giteeTokensBySub']), token => token),
utils.someResult(Object.values(rootGetters['data/giteeTokensBySub']), (token) => {
if (token.isLogin) {
return token;
}
return null;
}),
syncToken: (state, { currentWorkspace, mainWorkspaceToken }, rootState, rootGetters) => {
switch (currentWorkspace.providerId) {
case 'googleDriveWorkspace':