feat: Refactor cloud sync handling and add user info fetching in relevant components

This commit is contained in:
troyeguo
2025-12-19 08:34:40 +08:00
parent dc2c147f28
commit 060cabd5f9
7 changed files with 23 additions and 6 deletions

View File

@@ -461,6 +461,7 @@ class Header extends React.Component<HeaderProps, HeaderState> {
default_sync_option: this.props.defaultSyncOption,
default_sync_token: encryptedToken || "",
});
await this.props.handleFetchUserInfo();
toast.success(this.props.t("Setup successful"));
this.handleCloudSync();
}

View File

@@ -8,7 +8,7 @@ import {
formatTimestamp,
getServerRegion,
getWebsiteUrl,
handleCloudSync,
handleAutoCloudSync,
handleContextMenu,
openInBrowser,
reloadManager,
@@ -190,7 +190,7 @@ class AccountSetting extends React.Component<
});
this.props.handleFetchAuthed();
this.props.handleFetchLoginOptionList();
let result = await handleCloudSync();
let result = await handleAutoCloudSync();
if (result) {
this.props.cloudSyncFunc();
} else {

View File

@@ -242,12 +242,13 @@ class SyncSetting extends React.Component<SettingInfoProps, SettingInfoState> {
let encryptToken = await TokenService.getToken(
this.props.defaultSyncOption + "_token"
);
updateUserConfig({
await updateUserConfig({
is_enable_koodo_sync:
ConfigService.getReaderConfig("isEnableKoodoSync"),
default_sync_option: this.props.defaultSyncOption,
default_sync_token: encryptToken || "",
});
await this.props.handleFetchUserInfo();
if (
ConfigService.getReaderConfig("isEnableKoodoSync") ===
"yes"

View File

@@ -14,6 +14,7 @@ import {
handleLoadingDialog,
handleFetchAuthed,
handleLoginOptionList,
handleFetchUserInfo,
} from "../../../store/actions";
import { stateType } from "../../../store";
import { withRouter } from "react-router-dom";
@@ -48,6 +49,7 @@ const actionCreator = {
handleLoadingDialog,
handleFetchAuthed,
handleLoginOptionList,
handleFetchUserInfo,
};
export default connect(
mapStateToProps,

View File

@@ -20,6 +20,7 @@ export interface SettingInfoProps extends RouteComponentProps<any> {
handleFetchBooks: () => void;
handleFetchPlugins: () => void;
cloudSyncFunc: () => Promise<void>;
handleFetchUserInfo: () => Promise<void>;
bookmarks: BookmarkModel[];
notes: NoteModel[];
isOpenTokenDialog: boolean;

View File

@@ -8,7 +8,7 @@ import { loginList } from "../../constants/loginList";
import {
generateSyncRecord,
getServerRegion,
handleCloudSync,
handleAutoCloudSync,
handleContextMenu,
openInBrowser,
removeSearchParams,
@@ -89,7 +89,7 @@ class Login extends React.Component<LoginProps, LoginState> {
let res = await loginRegister(service, code);
if (res.code === 200) {
this.props.handleLoadingDialog(false);
let result = await handleCloudSync();
let result = await handleAutoCloudSync();
if (result) {
this.props.cloudSyncFunc();
} else {

View File

@@ -1006,13 +1006,25 @@ export const resetKoodoSync = async () => {
});
}, 1000);
};
export const handleCloudSync = async () => {
export const handleAutoCloudSync = async () => {
let syncRes = await getCloudSyncToken();
if (
syncRes.code === 200 &&
syncRes.data.default_sync_option &&
syncRes.data.default_sync_token
) {
let supportedSources = driveList
.filter((item) => {
if (isElectron) {
return item.support.includes("desktop");
} else {
return item.support.includes("browser");
}
})
.map((item) => item.value);
if (!supportedSources.includes(syncRes.data.default_sync_option)) {
return false;
}
ConfigService.setItem(
"defaultSyncOption",
syncRes.data.default_sync_option