mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 18:26:05 +08:00
feat(server): team quota (#8955)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { GetEnableUrlPreviewQuery } from '@affine/graphql';
|
||||
import type { GetWorkspaceConfigQuery } from '@affine/graphql';
|
||||
import type { WorkspaceService } from '@toeverything/infra';
|
||||
import {
|
||||
backoffRetry,
|
||||
@@ -8,21 +8,22 @@ import {
|
||||
Entity,
|
||||
fromPromise,
|
||||
LiveData,
|
||||
mapInto,
|
||||
onComplete,
|
||||
onStart,
|
||||
} from '@toeverything/infra';
|
||||
import { exhaustMap } from 'rxjs';
|
||||
import { EMPTY, exhaustMap, mergeMap } from 'rxjs';
|
||||
|
||||
import { isBackendError, isNetworkError } from '../../cloud';
|
||||
import type { WorkspaceShareSettingStore } from '../stores/share-setting';
|
||||
|
||||
type EnableAi = GetWorkspaceConfigQuery['workspace']['enableAi'];
|
||||
type EnableUrlPreview =
|
||||
GetEnableUrlPreviewQuery['workspace']['enableUrlPreview'];
|
||||
GetWorkspaceConfigQuery['workspace']['enableUrlPreview'];
|
||||
|
||||
const logger = new DebugLogger('affine:workspace-permission');
|
||||
|
||||
export class WorkspaceShareSetting extends Entity {
|
||||
enableAi$ = new LiveData<EnableAi | null>(null);
|
||||
enableUrlPreview$ = new LiveData<EnableUrlPreview | null>(null);
|
||||
isLoading$ = new LiveData(false);
|
||||
error$ = new LiveData<any>(null);
|
||||
@@ -38,7 +39,7 @@ export class WorkspaceShareSetting extends Entity {
|
||||
revalidate = effect(
|
||||
exhaustMap(() => {
|
||||
return fromPromise(signal =>
|
||||
this.store.fetchWorkspaceEnableUrlPreview(
|
||||
this.store.fetchWorkspaceConfig(
|
||||
this.workspaceService.workspace.id,
|
||||
signal
|
||||
)
|
||||
@@ -51,7 +52,13 @@ export class WorkspaceShareSetting extends Entity {
|
||||
when: isBackendError,
|
||||
count: 3,
|
||||
}),
|
||||
mapInto(this.enableUrlPreview$),
|
||||
mergeMap(value => {
|
||||
if (value) {
|
||||
this.enableAi$.next(value.enableAi);
|
||||
this.enableUrlPreview$.next(value.enableUrlPreview);
|
||||
}
|
||||
return EMPTY;
|
||||
}),
|
||||
catchErrorInto(this.error$, error => {
|
||||
logger.error('Failed to fetch enableUrlPreview', error);
|
||||
}),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { WorkspaceServerService } from '@affine/core/modules/cloud';
|
||||
import {
|
||||
getEnableUrlPreviewQuery,
|
||||
getWorkspaceConfigQuery,
|
||||
setEnableAiMutation,
|
||||
setEnableUrlPreviewMutation,
|
||||
} from '@affine/graphql';
|
||||
import { Store } from '@toeverything/infra';
|
||||
@@ -10,15 +11,12 @@ export class WorkspaceShareSettingStore extends Store {
|
||||
super();
|
||||
}
|
||||
|
||||
async fetchWorkspaceEnableUrlPreview(
|
||||
workspaceId: string,
|
||||
signal?: AbortSignal
|
||||
) {
|
||||
async fetchWorkspaceConfig(workspaceId: string, signal?: AbortSignal) {
|
||||
if (!this.workspaceServerService.server) {
|
||||
throw new Error('No Server');
|
||||
}
|
||||
const data = await this.workspaceServerService.server.gql({
|
||||
query: getEnableUrlPreviewQuery,
|
||||
query: getWorkspaceConfigQuery,
|
||||
variables: {
|
||||
id: workspaceId,
|
||||
},
|
||||
@@ -26,7 +24,27 @@ export class WorkspaceShareSettingStore extends Store {
|
||||
signal,
|
||||
},
|
||||
});
|
||||
return data.workspace.enableUrlPreview;
|
||||
return data.workspace;
|
||||
}
|
||||
|
||||
async updateWorkspaceEnableAi(
|
||||
workspaceId: string,
|
||||
enableAi: boolean,
|
||||
signal?: AbortSignal
|
||||
) {
|
||||
if (!this.workspaceServerService.server) {
|
||||
throw new Error('No Server');
|
||||
}
|
||||
await this.workspaceServerService.server.gql({
|
||||
query: setEnableAiMutation,
|
||||
variables: {
|
||||
id: workspaceId,
|
||||
enableAi,
|
||||
},
|
||||
context: {
|
||||
signal,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async updateWorkspaceEnableUrlPreview(
|
||||
|
||||
Reference in New Issue
Block a user