mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 08:47:10 +08:00
@@ -42,7 +42,7 @@ Generated by [AVA](https://avajs.dev).
|
|||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
blobId: 'fileId1',
|
blobId: 'Ip3vuwzubwJnOlzeKQ0Gc-daDcMc7EOYnIqypOyn4bs',
|
||||||
chunkSize: 0,
|
chunkSize: 0,
|
||||||
name: 'sample.pdf',
|
name: 'sample.pdf',
|
||||||
status: 'processing',
|
status: 'processing',
|
||||||
|
|||||||
Binary file not shown.
@@ -1,3 +1,5 @@
|
|||||||
|
import { createHash } from 'node:crypto';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Args,
|
Args,
|
||||||
Context,
|
Context,
|
||||||
@@ -102,8 +104,9 @@ class AddContextFileInput {
|
|||||||
@Field(() => String)
|
@Field(() => String)
|
||||||
contextId!: string;
|
contextId!: string;
|
||||||
|
|
||||||
@Field(() => String)
|
// @TODO(@darkskygit): remove this after client lower then 0.22 has been disconnected
|
||||||
blobId!: string;
|
@Field(() => String, { nullable: true, deprecationReason: 'Never used' })
|
||||||
|
blobId!: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@InputType()
|
@InputType()
|
||||||
@@ -611,8 +614,9 @@ export class CopilotContextResolver {
|
|||||||
if (!this.context.canEmbedding) {
|
if (!this.context.canEmbedding) {
|
||||||
throw new CopilotEmbeddingUnavailable();
|
throw new CopilotEmbeddingUnavailable();
|
||||||
}
|
}
|
||||||
|
const { contextId } = options;
|
||||||
|
|
||||||
const lockFlag = `${COPILOT_LOCKER}:context:${options.contextId}`;
|
const lockFlag = `${COPILOT_LOCKER}:context:${contextId}`;
|
||||||
await using lock = await this.mutex.acquire(lockFlag);
|
await using lock = await this.mutex.acquire(lockFlag);
|
||||||
if (!lock) {
|
if (!lock) {
|
||||||
throw new TooManyRequest('Server is busy');
|
throw new TooManyRequest('Server is busy');
|
||||||
@@ -623,22 +627,15 @@ export class CopilotContextResolver {
|
|||||||
throw new BlobQuotaExceeded();
|
throw new BlobQuotaExceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = await this.context.get(options.contextId);
|
const session = await this.context.get(contextId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const file = await session.addFile(
|
|
||||||
options.blobId,
|
|
||||||
content.filename,
|
|
||||||
content.mimetype
|
|
||||||
);
|
|
||||||
|
|
||||||
const buffer = await readStream(content.createReadStream());
|
const buffer = await readStream(content.createReadStream());
|
||||||
await this.storage.put(
|
const blobId = createHash('sha256').update(buffer).digest('base64url');
|
||||||
user.id,
|
const { filename, mimetype } = content;
|
||||||
session.workspaceId,
|
|
||||||
options.blobId,
|
await this.storage.put(user.id, session.workspaceId, blobId, buffer);
|
||||||
buffer
|
const file = await session.addFile(blobId, filename, mimetype);
|
||||||
);
|
|
||||||
|
|
||||||
await this.jobs.addFileEmbeddingQueue({
|
await this.jobs.addFileEmbeddingQueue({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
@@ -655,10 +652,7 @@ export class CopilotContextResolver {
|
|||||||
if (e instanceof UserFriendlyError) {
|
if (e instanceof UserFriendlyError) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
throw new CopilotFailedToModifyContext({
|
throw new CopilotFailedToModifyContext({ contextId, message: e.message });
|
||||||
contextId: options.contextId,
|
|
||||||
message: e.message,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ input AddContextDocInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
input AddContextFileInput {
|
input AddContextFileInput {
|
||||||
blobId: String!
|
blobId: String
|
||||||
contextId: String!
|
contextId: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export interface AddContextDocInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AddContextFileInput {
|
export interface AddContextFileInput {
|
||||||
blobId: Scalars['String']['input'];
|
blobId?: InputMaybe<Scalars['String']['input']>;
|
||||||
contextId: Scalars['String']['input'];
|
contextId: Scalars['String']['input'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user