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 RUN mkdir -p /opt/stackedit
WORKDIR /opt/stackedit WORKDIR /opt/stackedit

View File

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

View File

@ -57,7 +57,12 @@ export default {
lastSyncActivityKey: (state, { currentWorkspace }) => `${currentWorkspace.id}/lastSyncActivity`, lastSyncActivityKey: (state, { currentWorkspace }) => `${currentWorkspace.id}/lastSyncActivity`,
lastFocusKey: (state, { currentWorkspace }) => `${currentWorkspace.id}/lastWindowFocus`, lastFocusKey: (state, { currentWorkspace }) => `${currentWorkspace.id}/lastWindowFocus`,
mainWorkspaceToken: (state, getters, rootState, rootGetters) => 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) => { syncToken: (state, { currentWorkspace, mainWorkspaceToken }, rootState, rootGetters) => {
switch (currentWorkspace.providerId) { switch (currentWorkspace.providerId) {
case 'googleDriveWorkspace': case 'googleDriveWorkspace':