-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathplugin.controller.ts
More file actions
68 lines (59 loc) · 2.01 KB
/
Copy pathplugin.controller.ts
File metadata and controls
68 lines (59 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Controller, Post, Get, Param, Dependencies } from '@nestjs/common';
import { PluginService } from './pdf-plugin.service';
import { PluginOutput } from './pdf-plugin.interfaces';
import { PdfOutputPlugin } from './pdf-output-plugin';
import { PdfInputPlugin } from './pdf-input-plugin';
@Controller('plugin')
@Dependencies(PluginService)
export class PluginController {
private pdfOutputPlugin!: PdfOutputPlugin;
private pdfInputPlugin!: PdfInputPlugin;
constructor(private readonly pluginService: PluginService) {}
onModuleInit() {
this.pdfOutputPlugin = new PdfOutputPlugin();
this.pdfInputPlugin = new PdfInputPlugin();
}
@Post('generate-doc/:outputType')
async generateDocument(
@Param('outputType') outputType: string,
): Promise<PluginOutput> {
try {
return this.pdfOutputPlugin.generateDoc(outputType);
} catch (error: any) {
console.error('Error generating document:', error.message);
throw new Error('Failed to generate document');
}
}
@Get()
getPluginStatus(): string {
return 'Plugin is running!';
}
@Get('/pdf-to-image')
async convertPdfToImage(): Promise<{ images?: { url: string }[] }> {
const pdfFilePath = './generatedDocument.pdf';
try {
const pluginOutput = await this.pdfInputPlugin.transformPdfToImage(
pdfFilePath,
);
if (pluginOutput.images) {
const images = pluginOutput.images;
images.forEach((image: { url: string }) => {
console.log('Image URL:', image.url);
});
}
return { images: pluginOutput.images };
} catch (error) {
console.error('Error converting PDF to image:', error);
throw new Error('PDF to image conversion failed');
}
}
@Post('create-default-pdf')
async createDefaultPdf(): Promise<PluginOutput> {
try {
return this.pdfOutputPlugin.createDefaultPdf();
} catch (error: any) {
console.error('Error creating default PDF:', error.message);
throw new Error('Failed to create default PDF');
}
}
}