mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-03-15 03:02:00 -07:00
refactor: make adminToken usage clearer
This commit is contained in:
parent
d24a7519f2
commit
fdaa9cc48e
4 changed files with 20 additions and 14 deletions
|
|
@ -1,6 +1,7 @@
|
|||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable unicorn/no-null */
|
||||
import { IGitUserInfos } from '@services/git/interface';
|
||||
import { logger } from '@services/libs/log';
|
||||
import { IAuthingUserInfo, SupportedStorageServices } from '@services/types';
|
||||
import { IWorkspace } from '@services/workspaces/interface';
|
||||
import settings from 'electron-settings';
|
||||
|
|
@ -110,9 +111,10 @@ export class Authentication implements IAuthenticationService {
|
|||
}
|
||||
|
||||
public generateOneTimeAdminAuthTokenForWorkspace(workspaceID: string): string {
|
||||
const newToken = nanoid().toLowerCase();
|
||||
this.oneTimeAdminAuthToken.set(workspaceID, newToken);
|
||||
return newToken;
|
||||
const adminToken = nanoid().toLowerCase();
|
||||
logger.error(`generateOneTimeAdminAuthTokenForWorkspace() adminToken for ${workspaceID} is ${adminToken}`);
|
||||
this.oneTimeAdminAuthToken.set(workspaceID, adminToken);
|
||||
return adminToken;
|
||||
}
|
||||
|
||||
public async getOneTimeAdminAuthTokenForWorkspace(workspaceID: string): Promise<string | undefined> {
|
||||
|
|
@ -120,7 +122,11 @@ export class Authentication implements IAuthenticationService {
|
|||
}
|
||||
|
||||
public getOneTimeAdminAuthTokenForWorkspaceSync(workspaceID: string): string | undefined {
|
||||
return this.oneTimeAdminAuthToken.get(workspaceID);
|
||||
const adminToken = this.oneTimeAdminAuthToken.get(workspaceID);
|
||||
if (adminToken === undefined) {
|
||||
logger.error(`getOneTimeAdminAuthTokenForWorkspaceSync() No adminToken for ${workspaceID}`);
|
||||
}
|
||||
return adminToken;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -581,8 +581,8 @@ export class Wiki implements IWikiService {
|
|||
});
|
||||
}
|
||||
|
||||
public async wikiStartup(workspace: IWorkspace, configs?: { adminToken?: string }): Promise<void> {
|
||||
const { wikiFolderLocation, isSubWiki, mainWikiToLink, id, name, mainWikiID } = workspace;
|
||||
public async wikiStartup(workspace: IWorkspace): Promise<void> {
|
||||
const { wikiFolderLocation, isSubWiki, mainWikiToLink, id, name, mainWikiID, tokenAuth } = workspace;
|
||||
|
||||
// remove $:/StoryList, otherwise it sometimes cause $__StoryList_1.tid to be generated
|
||||
// and it will leak private sub-wiki's opened tiddler title
|
||||
|
|
@ -593,6 +593,11 @@ export class Wiki implements IWikiService {
|
|||
}
|
||||
|
||||
const userName = await this.authService.getUserName(workspace);
|
||||
let adminToken = '';
|
||||
if (tokenAuth) {
|
||||
logger.debug(`initializeWorkspaceView() generateOneTimeAdminAuthTokenForWorkspace`);
|
||||
adminToken = this.authService.generateOneTimeAdminAuthTokenForWorkspace(id);
|
||||
}
|
||||
|
||||
// if is main wiki
|
||||
if (isSubWiki) {
|
||||
|
|
@ -608,7 +613,7 @@ export class Wiki implements IWikiService {
|
|||
} else {
|
||||
try {
|
||||
logger.debug('startWiki() calling startWiki');
|
||||
await this.startWiki(id, userName, { adminToken: configs?.adminToken });
|
||||
await this.startWiki(id, userName, { adminToken });
|
||||
logger.debug('startWiki() done');
|
||||
} catch (error) {
|
||||
logger.warn(`Get startWiki() error: ${(error as Error)?.message}`);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ export interface IWikiService {
|
|||
...arguments_: Parameters<IWikiOperations[OP]>
|
||||
): undefined | ReturnType<IWikiOperations[OP]>;
|
||||
/** handle start/restart of wiki/subwiki, will handle wiki sync too */
|
||||
wikiStartup(workspace: IWorkspace, configs?: { adminToken?: string }): Promise<void>;
|
||||
wikiStartup(workspace: IWorkspace): Promise<void>;
|
||||
}
|
||||
export const WikiServiceIPCDescriptor = {
|
||||
channel: WikiChannel.name,
|
||||
|
|
|
|||
|
|
@ -123,13 +123,8 @@ export class WorkspaceView implements IWorkspaceViewService {
|
|||
});
|
||||
}
|
||||
}
|
||||
let adminToken = '';
|
||||
if (workspace.tokenAuth) {
|
||||
logger.debug(`initializeWorkspaceView() generateOneTimeAdminAuthTokenForWorkspace`);
|
||||
adminToken = this.authService.generateOneTimeAdminAuthTokenForWorkspace(workspace.id);
|
||||
}
|
||||
logger.debug(`initializeWorkspaceView() calling wikiStartup()`);
|
||||
await this.wikiService.wikiStartup(workspace, { adminToken });
|
||||
await this.wikiService.wikiStartup(workspace);
|
||||
|
||||
const userInfo = await this.authService.getStorageServiceUserInfo(workspace.storageService);
|
||||
const { wikiFolderLocation, gitUrl: githubRepoUrl, storageService, homeUrl } = workspace;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue