Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/wizard/dto/create-tempfile-req.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Expose } from 'class-transformer';
import { IsOptional, IsString } from 'class-validator';

export class CreateTempfileReqDto {
@Expose()
@IsOptional()
@IsString()
filename?: string;
}
9 changes: 9 additions & 0 deletions src/wizard/dto/tempfile.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Expose } from 'class-transformer';

export class TempfileDto {
@Expose({ name: 'upload_url' })
uploadUrl: string;

@Expose({ name: 'download_url' })
downloadUrl: string;
}
7 changes: 7 additions & 0 deletions src/wizard/internal.wizard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ChunkCallbackDto } from 'omniboxd/wizard/dto/chunk-callback.dto';
import { ChunkManagerService } from 'omniboxd/wizard/chunk-manager.service';
import { Body, Controller, Get, Param, Post, Query, Res } from '@nestjs/common';
import { FetchTaskRequest } from 'omniboxd/wizard/dto/fetch-task-request.dto';
import { CreateTempfileReqDto } from './dto/create-tempfile-req.dto';

@Controller('internal/api/v1/wizard')
export class InternalWizardController {
Expand Down Expand Up @@ -87,4 +88,10 @@ export class InternalWizardController {

return { message: 'Chunk received', chunk_index, total_chunks };
}

@Public()
@Post('tempfiles')
async createTempfile(@Body() createReq: CreateTempfileReqDto) {
return await this.wizardService.createTempfile(createReq.filename);
}
}
14 changes: 14 additions & 0 deletions src/wizard/wizard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { createGunzip } from 'zlib';
import { buffer } from 'node:stream/consumers';
import { SharedResourcesService } from 'omniboxd/shared-resources/shared-resources.service';
import { ResourcesService } from 'omniboxd/resources/resources.service';
import { TempfileDto } from './dto/tempfile.dto';

@Injectable()
export class WizardService {
Expand Down Expand Up @@ -235,6 +236,19 @@ export class WizardService {
);
}

async createTempfile(filename?: string): Promise<TempfileDto> {
const { objectKey } = await this.s3Service.generateObjectKey(
'wizard-tempfiles',
filename,
);
const uploadUrl = await this.s3Service.generateUploadUrl(objectKey, false);
const downloadUrl = await this.s3Service.generateDownloadUrl(
objectKey,
true,
);
return { uploadUrl, downloadUrl };
}

async uploadedTaskDoneCallback(taskId: string) {
const key = `wizard-tasks/${taskId}`;
const { stream } = await this.s3Service.getObject(key);
Expand Down
Loading