mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-28 15:55:19 +08:00
feat: use baseurl from server config (#5369)
This commit is contained in:
+27
-2
@@ -9,7 +9,7 @@ const errorHandler: Middleware = useSWRNext => (key, fetcher, config) => {
|
||||
return useSWRNext(key, wrappedFetcher.bind(null, fetcher), config);
|
||||
};
|
||||
|
||||
export const useServerFlavor = () => {
|
||||
const useServerConfig = () => {
|
||||
const { data: config, error } = useQueryImmutable(
|
||||
{ query: serverConfigQuery },
|
||||
{
|
||||
@@ -18,10 +18,20 @@ export const useServerFlavor = () => {
|
||||
);
|
||||
|
||||
if (error || !config) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return config.serverConfig;
|
||||
};
|
||||
|
||||
export const useServerFlavor = () => {
|
||||
const config = useServerConfig();
|
||||
|
||||
if (!config) {
|
||||
return 'local';
|
||||
}
|
||||
|
||||
return config.serverConfig.flavor;
|
||||
return config.flavor;
|
||||
};
|
||||
|
||||
export const useSelfHosted = () => {
|
||||
@@ -29,3 +39,18 @@ export const useSelfHosted = () => {
|
||||
|
||||
return ['local', 'selfhosted'].includes(serverFlavor);
|
||||
};
|
||||
|
||||
export const useServerBaseUrl = () => {
|
||||
const config = useServerConfig();
|
||||
|
||||
if (!config) {
|
||||
if (environment.isDesktop) {
|
||||
// don't use window.location in electron
|
||||
return null;
|
||||
}
|
||||
const { protocol, hostname, port } = window.location;
|
||||
return `${protocol}//${hostname}${port ? `:${port}` : ''}`;
|
||||
}
|
||||
|
||||
return config.baseUrl;
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
'use client';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export function useShareLink(workspaceId: string): string {
|
||||
return useMemo(() => {
|
||||
if (environment.isServer) {
|
||||
throw new Error('useShareLink is not available on server side');
|
||||
}
|
||||
if (environment.isDesktop) {
|
||||
return '???';
|
||||
} else {
|
||||
return origin + '/share/' + workspaceId;
|
||||
}
|
||||
}, [workspaceId]);
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { type SubscriptionQuery, subscriptionQuery } from '@affine/graphql';
|
||||
import { useQuery } from '@affine/workspace/affine/gql';
|
||||
import { useAsyncCallback } from '@toeverything/hooks/affine-async-hooks';
|
||||
|
||||
import { useSelfHosted } from './affine/use-server-flavor';
|
||||
import { useSelfHosted } from './affine/use-server-config';
|
||||
|
||||
export type Subscription = NonNullable<
|
||||
NonNullable<SubscriptionQuery['currentUser']>['subscription']
|
||||
|
||||
Reference in New Issue
Block a user