mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(server): update trascript endpoint (#11196)
This commit is contained in:
@@ -32,9 +32,10 @@ export class CopilotJobModel extends BaseModel {
|
||||
return row;
|
||||
}
|
||||
|
||||
async has(workspaceId: string, blobId: string) {
|
||||
async has(userId: string, workspaceId: string, blobId: string) {
|
||||
const row = await this.db.aiJobs.findFirst({
|
||||
where: {
|
||||
createdBy: userId,
|
||||
workspaceId,
|
||||
blobId,
|
||||
},
|
||||
@@ -42,6 +43,45 @@ export class CopilotJobModel extends BaseModel {
|
||||
return !!row;
|
||||
}
|
||||
|
||||
async getWithUser(
|
||||
userId: string,
|
||||
workspaceId: string,
|
||||
jobId?: string,
|
||||
blobId?: string,
|
||||
type?: AiJobType
|
||||
) {
|
||||
if (!jobId && !blobId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const row = await this.db.aiJobs.findFirst({
|
||||
where: {
|
||||
id: jobId,
|
||||
blobId,
|
||||
workspaceId,
|
||||
type,
|
||||
OR: [
|
||||
{ createdBy: userId },
|
||||
{ createdBy: { not: userId }, status: AiJobStatus.claimed },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
if (!row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
id: row.id,
|
||||
workspaceId: row.workspaceId,
|
||||
blobId: row.blobId,
|
||||
createdBy: row.createdBy || undefined,
|
||||
type: row.type,
|
||||
status: row.status,
|
||||
payload: row.payload,
|
||||
};
|
||||
}
|
||||
|
||||
async update(jobId: string, data: UpdateCopilotJobInput) {
|
||||
const ret = await this.db.aiJobs.updateMany({
|
||||
where: {
|
||||
@@ -74,42 +114,6 @@ export class CopilotJobModel extends BaseModel {
|
||||
return ret?.status;
|
||||
}
|
||||
|
||||
async getWithUser(
|
||||
userId: string,
|
||||
workspaceId: string,
|
||||
jobId?: string,
|
||||
type?: AiJobType
|
||||
) {
|
||||
const row = await this.db.aiJobs.findFirst({
|
||||
where: {
|
||||
id: jobId,
|
||||
workspaceId,
|
||||
type,
|
||||
OR: [
|
||||
{
|
||||
createdBy: userId,
|
||||
status: { in: [AiJobStatus.finished, AiJobStatus.claimed] },
|
||||
},
|
||||
{ createdBy: { not: userId }, status: AiJobStatus.claimed },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
if (!row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
id: row.id,
|
||||
workspaceId: row.workspaceId,
|
||||
blobId: row.blobId,
|
||||
createdBy: row.createdBy || undefined,
|
||||
type: row.type,
|
||||
status: row.status,
|
||||
payload: row.payload,
|
||||
};
|
||||
}
|
||||
|
||||
async get(jobId: string): Promise<CopilotJob | null> {
|
||||
const row = await this.db.aiJobs.findFirst({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user