Skip to content

Commit

Permalink
add Custom
Browse files Browse the repository at this point in the history
  • Loading branch information
zcpua committed Jul 16, 2023
1 parent b9d81f5 commit f9f1f19
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@nestjs/common';
import { MidjourneyService } from './midjourney.service';
import { FastifyReply } from 'fastify';
import { AvatarBody, PromptMessageBody } from './interfaces';
import { AvatarBody, CustomBody, PromptMessageBody } from './interfaces';
@Controller('midjourney')
export class AppController {
constructor(private readonly MjService: MidjourneyService) {}
Expand Down Expand Up @@ -42,4 +42,24 @@ export class AppController {
res.raw.write(JSON.stringify(msg));
res.raw.end();
}
@Post('custom')
@UseInterceptors()
async Custom(@Body() data: CustomBody, @Res() res: FastifyReply) {
res.raw.setHeader('Content-Type', 'text/html');
res.raw.setHeader('Transfer-Encoding', 'chunked');
res.raw.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
res.raw.setHeader('Pragma', 'no-cache');
res.raw.setHeader('Expires', '0');

const msg = await this.MjService.Custom(
data.msgId,
data.customId,
data.flags,
(uri, progress) => {
res.raw.write(JSON.stringify({ uri, progress }));
},
);
res.raw.write(JSON.stringify(msg));
res.raw.end();
}
}
6 changes: 6 additions & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ export type OptionMessageBody = {
export type AvatarBody = {
img: string;
};

export type CustomBody = {
flags: number;
msgId: string;
customId: string;
};
17 changes: 17 additions & 0 deletions src/midjourney.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ export class MidjourneyService implements OnModuleInit {
return msg;
}

async Custom(
msgId: string,
customId: string,
flags: number,
loading?: (uri: string, progress: string) => void,
) {
const msg = await this.Midjourney.Custom({
msgId,
customId,
flags,
loading: (uri, progress) => {
loading && loading(uri, progress);
},
});
return msg;
}

// async Variation(
// content: string,
// index: number,
Expand Down

0 comments on commit f9f1f19

Please sign in to comment.