mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-13 08:06:24 +08:00
refactor(server): use feature model (#9932)
This commit is contained in:
@@ -12,8 +12,8 @@ import {
|
||||
CopilotSessionNotFound,
|
||||
PrismaTransaction,
|
||||
} from '../../base';
|
||||
import { FeatureManagementService } from '../../core/features';
|
||||
import { QuotaService } from '../../core/quota';
|
||||
import { Models } from '../../models';
|
||||
import { ChatMessageCache } from './message';
|
||||
import { PromptService } from './prompt';
|
||||
import {
|
||||
@@ -195,10 +195,10 @@ export class ChatSessionService {
|
||||
|
||||
constructor(
|
||||
private readonly db: PrismaClient,
|
||||
private readonly feature: FeatureManagementService,
|
||||
private readonly quota: QuotaService,
|
||||
private readonly messageCache: ChatMessageCache,
|
||||
private readonly prompt: PromptService
|
||||
private readonly prompt: PromptService,
|
||||
private readonly models: Models
|
||||
) {}
|
||||
|
||||
private async haveSession(
|
||||
@@ -545,12 +545,15 @@ export class ChatSessionService {
|
||||
}
|
||||
|
||||
async getQuota(userId: string) {
|
||||
const isCopilotUser = await this.feature.isCopilotUser(userId);
|
||||
const isCopilotUser = await this.models.userFeature.has(
|
||||
userId,
|
||||
'unlimited_copilot'
|
||||
);
|
||||
|
||||
let limit: number | undefined;
|
||||
if (!isCopilotUser) {
|
||||
const quota = await this.quota.getUserQuota(userId);
|
||||
limit = quota.feature.copilotActionLimit;
|
||||
limit = quota.copilotActionLimit;
|
||||
}
|
||||
|
||||
const used = await this.countUserMessages(userId);
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
StorageProviderFactory,
|
||||
URLHelper,
|
||||
} from '../../base';
|
||||
import { QuotaManagementService } from '../../core/quota';
|
||||
import { QuotaService } from '../../core/quota';
|
||||
|
||||
@Injectable()
|
||||
export class CopilotStorage {
|
||||
@@ -22,7 +22,7 @@ export class CopilotStorage {
|
||||
private readonly config: Config,
|
||||
private readonly url: URLHelper,
|
||||
private readonly storageFactory: StorageProviderFactory,
|
||||
private readonly quota: QuotaManagementService
|
||||
private readonly quota: QuotaService
|
||||
) {
|
||||
this.provider = this.storageFactory.create(
|
||||
this.config.plugins.copilot.storage
|
||||
@@ -57,7 +57,7 @@ export class CopilotStorage {
|
||||
|
||||
@CallMetric('ai', 'blob_upload')
|
||||
async handleUpload(userId: string, blob: FileUpload) {
|
||||
const checkExceeded = await this.quota.getQuotaCalculator(userId);
|
||||
const checkExceeded = await this.quota.getUserQuotaCalculator(userId);
|
||||
|
||||
if (checkExceeded(0)) {
|
||||
throw new BlobQuotaExceeded();
|
||||
|
||||
Reference in New Issue
Block a user