|
@@ -1,10 +1,11 @@
|
|
|
import { Injectable } from '@nestjs/common';
|
|
import { Injectable } from '@nestjs/common';
|
|
|
-import { mkdtemp, mkdir, readFile, rm, writeFile, copyFile } from 'fs/promises';
|
|
|
|
|
|
|
+import { mkdtemp, mkdir, readFile, rm, writeFile } from 'fs/promises';
|
|
|
import { createWriteStream } from 'fs';
|
|
import { createWriteStream } from 'fs';
|
|
|
import { tmpdir } from 'os';
|
|
import { tmpdir } from 'os';
|
|
|
-import { basename, join, resolve } from 'path';
|
|
|
|
|
|
|
+import { basename, join } from 'path';
|
|
|
import { ZipFile } from 'yazl';
|
|
import { ZipFile } from 'yazl';
|
|
|
import { StorageService } from '../storage/storage.service';
|
|
import { StorageService } from '../storage/storage.service';
|
|
|
|
|
+import { STEP2_CONFIG, STEP2_CONTENT } from './step2-assets';
|
|
|
|
|
|
|
|
type PrepareStep2BundleInput = {
|
|
type PrepareStep2BundleInput = {
|
|
|
totalTaskId: string;
|
|
totalTaskId: string;
|
|
@@ -69,8 +70,6 @@ export class TemplateTaskFiles {
|
|
|
localFiles: Record<string, string>;
|
|
localFiles: Record<string, string>;
|
|
|
}> {
|
|
}> {
|
|
|
const workDir = await this.createWorkDir(input.totalTaskId);
|
|
const workDir = await this.createWorkDir(input.totalTaskId);
|
|
|
- const configPath = resolve(process.cwd(), 'src/step2/config.json');
|
|
|
|
|
- const contentPath = resolve(process.cwd(), 'src/step2/content.json');
|
|
|
|
|
const copiedConfigPath = join(workDir, 'config.json');
|
|
const copiedConfigPath = join(workDir, 'config.json');
|
|
|
const copiedContentPath = join(workDir, 'content.json');
|
|
const copiedContentPath = join(workDir, 'content.json');
|
|
|
const hairstylePath = join(workDir, 'hairstyle.jpg');
|
|
const hairstylePath = join(workDir, 'hairstyle.jpg');
|
|
@@ -78,8 +77,14 @@ export class TemplateTaskFiles {
|
|
|
const backgroundPath = join(workDir, 'input-background.jpg');
|
|
const backgroundPath = join(workDir, 'input-background.jpg');
|
|
|
const zipPath = join(workDir, 'template.zip');
|
|
const zipPath = join(workDir, 'template.zip');
|
|
|
|
|
|
|
|
- await copyFile(configPath, copiedConfigPath);
|
|
|
|
|
- await copyFile(contentPath, copiedContentPath);
|
|
|
|
|
|
|
+ await writeFile(
|
|
|
|
|
+ copiedConfigPath,
|
|
|
|
|
+ `${JSON.stringify(STEP2_CONFIG, null, 2)}\n`,
|
|
|
|
|
+ );
|
|
|
|
|
+ await writeFile(
|
|
|
|
|
+ copiedContentPath,
|
|
|
|
|
+ `${JSON.stringify(STEP2_CONTENT, null, 2)}\n`,
|
|
|
|
|
+ );
|
|
|
await writeFile(hairstylePath, await this.fetchBuffer(input.step1ResultImg));
|
|
await writeFile(hairstylePath, await this.fetchBuffer(input.step1ResultImg));
|
|
|
await writeFile(outfitPath, await this.fetchBuffer(input.clothesUrl));
|
|
await writeFile(outfitPath, await this.fetchBuffer(input.clothesUrl));
|
|
|
await writeFile(backgroundPath, await this.fetchBuffer(input.backgroundUrl));
|
|
await writeFile(backgroundPath, await this.fetchBuffer(input.backgroundUrl));
|