mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-07-23 12:11:51 +00:00
Move WikiTree and Google Drive code out of app.tsx
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type {ParsedQuery} from 'query-string';
|
||||
import {TopolaData} from '../util/gedcom_util';
|
||||
import {DataSource, DataSourceEnum, SourceSelection} from './data_source';
|
||||
import {
|
||||
@@ -92,3 +93,34 @@ export class GoogleDriveDataSource implements DataSource<GoogleDriveSourceSpec>
|
||||
return loadAndPrepareFile(blob, cacheKey, onProgress);
|
||||
}
|
||||
}
|
||||
|
||||
export const GOOGLE_DRIVE_REDIRECT_KEYS = ['state'];
|
||||
|
||||
export function handleGoogleDriveRedirect(
|
||||
mergedParams: ParsedQuery,
|
||||
): {redirectPath: string; fileId: string} | null {
|
||||
const stateParam = mergedParams.state;
|
||||
if (typeof stateParam === 'string') {
|
||||
try {
|
||||
const parsedState = JSON.parse(stateParam);
|
||||
if (
|
||||
parsedState &&
|
||||
parsedState.action === 'open' &&
|
||||
Array.isArray(parsedState.ids) &&
|
||||
parsedState.ids.length > 0
|
||||
) {
|
||||
return {
|
||||
redirectPath: '/view',
|
||||
fileId: parsedState.ids[0],
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
// Silently catch JSON parsing errors for state parameters not meant for us
|
||||
console.warn(
|
||||
'Google Drive state query parameter JSON parsing failed or action mismatch:',
|
||||
err,
|
||||
);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type {ParsedQuery} from 'query-string';
|
||||
import {IntlShape} from 'react-intl';
|
||||
import {analyticsEvent} from '../util/analytics';
|
||||
import {TopolaError} from '../util/error';
|
||||
@@ -109,3 +110,18 @@ export class WikiTreeDataSource implements DataSource<WikiTreeSourceSpec> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const WIKITREE_REDIRECT_KEYS = ['authcode'];
|
||||
|
||||
export function handleWikiTreeRedirect(
|
||||
windowSearch: ParsedQuery,
|
||||
currentPathname: string,
|
||||
): {redirectPath: string; paramsModified: boolean} | null {
|
||||
if (windowSearch.authcode) {
|
||||
return {
|
||||
redirectPath: currentPathname,
|
||||
paramsModified: true,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user