|
|
@ -1,12 +1,12 @@ |
|
|
|
import { Controller, HttpCode, Post, Request, UseGuards } from '@nestjs/common'; |
|
|
|
import { Controller, HttpCode, Post, Request, UseGuards } from '@nestjs/common'; |
|
|
|
import { forwardRef, Inject } from '@nestjs/common'; |
|
|
|
import { forwardRef, Inject } from '@nestjs/common'; |
|
|
|
import { ModuleRef } from '@nestjs/core'; |
|
|
|
import { ModuleRef } from '@nestjs/core'; |
|
|
|
|
|
|
|
import { SocketGateway } from 'src/services/socket.gateway'; |
|
|
|
import { GlobalGuard } from '../../guards/global/global.guard'; |
|
|
|
import { GlobalGuard } from '../../guards/global/global.guard'; |
|
|
|
import { NcError } from '../../helpers/catchError'; |
|
|
|
import { NcError } from '../../helpers/catchError'; |
|
|
|
import { ExtractProjectIdMiddleware } from '../../middlewares/extract-project-id/extract-project-id.middleware'; |
|
|
|
import { ExtractProjectIdMiddleware } from '../../middlewares/extract-project-id/extract-project-id.middleware'; |
|
|
|
import { SyncSource } from '../../models'; |
|
|
|
import { SyncSource } from '../../models'; |
|
|
|
import NocoJobs from '../../jobs/NocoJobs'; |
|
|
|
import NocoJobs from '../../jobs/NocoJobs'; |
|
|
|
import { SocketService } from '../../services/socket.service'; |
|
|
|
|
|
|
|
import airtableSyncJob from './helpers/job'; |
|
|
|
import airtableSyncJob from './helpers/job'; |
|
|
|
import type { AirtableSyncConfig } from './helpers/job'; |
|
|
|
import type { AirtableSyncConfig } from './helpers/job'; |
|
|
|
|
|
|
|
|
|
|
@ -78,7 +78,7 @@ const initJob = (sv: Server, jobs: { [p: string]: { last_message: any } }) => { |
|
|
|
@UseGuards(ExtractProjectIdMiddleware, GlobalGuard) |
|
|
|
@UseGuards(ExtractProjectIdMiddleware, GlobalGuard) |
|
|
|
export class ImportController { |
|
|
|
export class ImportController { |
|
|
|
constructor( |
|
|
|
constructor( |
|
|
|
private readonly socketService: SocketService, |
|
|
|
private readonly socketGateway: SocketGateway, |
|
|
|
@Inject(forwardRef(() => ModuleRef)) private readonly moduleRef: ModuleRef, |
|
|
|
@Inject(forwardRef(() => ModuleRef)) private readonly moduleRef: ModuleRef, |
|
|
|
) {} |
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
|
@ -95,7 +95,7 @@ export class ImportController { |
|
|
|
@Post('/api/v1/db/meta/syncs/:syncId/trigger') |
|
|
|
@Post('/api/v1/db/meta/syncs/:syncId/trigger') |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
async triggerSync(@Request() req) { |
|
|
|
async triggerSync(@Request() req) { |
|
|
|
if (req.params.syncId in this.socketService.jobs) { |
|
|
|
if (req.params.syncId in this.socketGateway.jobs) { |
|
|
|
NcError.badRequest('Sync already in progress'); |
|
|
|
NcError.badRequest('Sync already in progress'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -125,7 +125,7 @@ export class ImportController { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, 1000); |
|
|
|
}, 1000); |
|
|
|
|
|
|
|
|
|
|
|
this.socketService.jobs[req.params.syncId] = { |
|
|
|
this.socketGateway.jobs[req.params.syncId] = { |
|
|
|
last_message: { |
|
|
|
last_message: { |
|
|
|
msg: 'Sync started', |
|
|
|
msg: 'Sync started', |
|
|
|
}, |
|
|
|
}, |
|
|
@ -136,13 +136,13 @@ export class ImportController { |
|
|
|
@Post('/api/v1/db/meta/syncs/:syncId/abort') |
|
|
|
@Post('/api/v1/db/meta/syncs/:syncId/abort') |
|
|
|
@HttpCode(200) |
|
|
|
@HttpCode(200) |
|
|
|
async abortImport(@Request() req) { |
|
|
|
async abortImport(@Request() req) { |
|
|
|
if (req.params.syncId in this.socketService.jobs) { |
|
|
|
if (req.params.syncId in this.socketGateway.jobs) { |
|
|
|
delete this.socketService.jobs[req.params.syncId]; |
|
|
|
delete this.socketGateway.jobs[req.params.syncId]; |
|
|
|
} |
|
|
|
} |
|
|
|
return {}; |
|
|
|
return {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async onModuleInit() { |
|
|
|
async onModuleInit() { |
|
|
|
initJob(this.socketService.io, this.socketService.jobs); |
|
|
|
initJob(this.socketGateway.io, this.socketGateway.jobs); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|