Skip to content

Commit

Permalink
feat: cleanup codes
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Nov 27, 2024
1 parent 7f1e30d commit 88fe51e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { extractLinkSearchParams } from '@affine/core/utils/link';
import { useService } from '@toeverything/infra';
import { useEffect, useRef } from 'react';
import {
Expand Down Expand Up @@ -27,9 +28,7 @@ type LoaderData = z.infer<typeof LoaderData>;
type ParsedState = z.infer<typeof ParsedState>;

async function parseState(url: string): Promise<ParsedState> {
const { code, state: stateStr } = Array.from(
new URL(url).searchParams.entries()
).reduce((acc, [k, v]) => ((acc[k] = v), acc), {} as Record<string, string>);
const { code, state: stateStr } = extractLinkSearchParams(url);
if (!code || !stateStr) throw new Error('Invalid oauth callback parameters');
try {
/** @deprecated old client compatibility*/
Expand Down
9 changes: 2 additions & 7 deletions packages/frontend/core/src/desktop/pages/open-app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GraphQLService } from '@affine/core/modules/cloud';
import { OpenInAppPage } from '@affine/core/modules/open-in-app/views/open-in-app-page';
import { appSchemaUrl, appSchemes, channelToScheme } from '@affine/core/utils';
import { extractLinkSearchParams } from '@affine/core/utils/link';
import type { GetCurrentUserQuery } from '@affine/graphql';
import { getCurrentUserQuery } from '@affine/graphql';
import { useService } from '@toeverything/infra';
Expand All @@ -27,13 +28,7 @@ export const loader: LoaderFunction = async args => {
const action = args.params.action || '';

try {
const { url, ...params } = Array.from(
new URL(args.request.url).searchParams.entries()
).reduce(
(acc, [k, v]) => ((acc[k] = v), acc),
{} as Record<string, string>
);

const { url, ...params } = extractLinkSearchParams(args.request.url);
return LoaderData.parse({ action, url, params });
} catch (e) {
console.error(e);
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/core/src/utils/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function extractLinkSearchParams(link: string): Record<string, string> {
return Array.from(new URL(link).searchParams.entries()).reduce(
(acc, [k, v]) => ((acc[k] = v), acc),
{} as Record<string, string>
);
}

0 comments on commit 88fe51e

Please sign in to comment.