From 8b55b32ec851ee65efeeac726f5942fd110e956f Mon Sep 17 00:00:00 2001 From: "xiaoqi.cxq" Date: Tue, 7 Jun 2022 06:35:35 +0800 Subject: [PATCH] main workspaces bugfix --- Dockerfile | 2 +- package.json | 2 +- src/services/providers/helpers/giteeHelper.js | 23 +++++++++++++------ src/store/workspace.js | 7 +++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1a701d00..f82c17d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:11.15.0 +FROM mafgwo/wkhtmltopdf-nodejs:11.15.0 RUN mkdir -p /opt/stackedit WORKDIR /opt/stackedit diff --git a/package.json b/package.json index 0433b537..99e53d89 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/services/providers/helpers/giteeHelper.js b/src/services/providers/helpers/giteeHelper.js index 8807a367..c9de2986 100644 --- a/src/services/providers/helpers/giteeHelper.js +++ b/src/services/providers/helpers/giteeHelper.js @@ -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(); diff --git a/src/store/workspace.js b/src/store/workspace.js index 84f5447d..a72f6d39 100644 --- a/src/store/workspace.js +++ b/src/store/workspace.js @@ -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':