1- import syncService from "./sync.js" ;
1+ import becca from "../becca/becca.js" ;
2+ import type { SetupStatusResponse , SetupSyncSeedResponse } from "./api-interface.js" ;
3+ import appInfo from "./app_info.js" ;
24import log from "./log.js" ;
3- import sqlInit from "./sql_init.js" ;
45import optionService from "./options.js" ;
5- import syncOptions from "./sync_options.js" ;
66import request from "./request.js" ;
7- import appInfo from "./app_info.js" ;
7+ import sqlInit from "./sql_init.js" ;
8+ import syncService from "./sync.js" ;
9+ import syncOptions from "./sync_options.js" ;
810import { timeLimit } from "./utils.js" ;
9- import becca from "../becca/becca.js" ;
10- import type { SetupStatusResponse , SetupSyncSeedResponse } from "./api-interface.js" ;
1111
1212async function hasSyncServerSchemaAndSeed ( ) {
1313 const response = await requestToSyncServer < SetupStatusResponse > ( "GET" , "/api/setup/status" ) ;
@@ -55,13 +55,13 @@ async function requestToSyncServer<T>(method: string, path: string, body?: strin
5555 url : syncOptions . getSyncServerHost ( ) + path ,
5656 body,
5757 proxy : syncOptions . getSyncProxy ( ) ,
58- timeout : timeout
58+ timeout
5959 } ) ,
6060 timeout
6161 ) ) as T ;
6262}
6363
64- async function setupSyncFromSyncServer ( syncServerHost : string , syncProxy : string , password : string ) {
64+ async function setupSyncFromSyncServer ( syncServerHost : string , syncProxy : string , password : string , totpToken ?: string ) {
6565 if ( sqlInit . isDbInitialized ( ) ) {
6666 return {
6767 result : "failure" ,
@@ -76,7 +76,7 @@ async function setupSyncFromSyncServer(syncServerHost: string, syncProxy: string
7676 const resp = await request . exec < SetupSyncSeedResponse > ( {
7777 method : "get" ,
7878 url : `${ syncServerHost } /api/setup/sync-seed` ,
79- auth : { password } ,
79+ auth : { password, totpToken } ,
8080 proxy : syncProxy ,
8181 timeout : 30000 // seed request should not take long
8282 } ) ;
@@ -111,10 +111,25 @@ function getSyncSeedOptions() {
111111 return [ becca . getOption ( "documentId" ) , becca . getOption ( "documentSecret" ) ] ;
112112}
113113
114+ async function checkRemoteTotpStatus ( syncServerHost : string ) : Promise < { totpEnabled : boolean } > {
115+ try {
116+ const resp = await request . exec < { totpEnabled ?: boolean } > ( {
117+ method : "get" ,
118+ url : `${ syncServerHost } /api/setup/status` ,
119+ proxy : null ,
120+ timeout : 10000
121+ } ) ;
122+ return { totpEnabled : ! ! resp ?. totpEnabled } ;
123+ } catch {
124+ return { totpEnabled : false } ;
125+ }
126+ }
127+
114128export default {
115129 hasSyncServerSchemaAndSeed,
116130 triggerSync,
117131 sendSeedToSyncServer,
118132 setupSyncFromSyncServer,
119- getSyncSeedOptions
133+ getSyncSeedOptions,
134+ checkRemoteTotpStatus
120135} ;
0 commit comments