@zola_do/document-manipulator 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,9 +47,9 @@ npm install libreoffice-convert
|
|
|
47
47
|
### 1. Register Modules
|
|
48
48
|
|
|
49
49
|
```typescript
|
|
50
|
-
import { Module } from
|
|
51
|
-
import { DocumentManipulatorModule } from
|
|
52
|
-
import { MinIoModule } from
|
|
50
|
+
import { Module } from '@nestjs/common';
|
|
51
|
+
import { DocumentManipulatorModule } from '@zola_do/document-manipulator';
|
|
52
|
+
import { MinIoModule } from '@zola_do/minio';
|
|
53
53
|
|
|
54
54
|
@Module({
|
|
55
55
|
imports: [MinIoModule, DocumentManipulatorModule],
|
|
@@ -60,8 +60,8 @@ export class AppModule {}
|
|
|
60
60
|
### 2. Use Service
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
|
-
import { Injectable } from
|
|
64
|
-
import { DocumentManipulatorService } from
|
|
63
|
+
import { Injectable } from '@nestjs/common';
|
|
64
|
+
import { DocumentManipulatorService } from '@zola_do/document-manipulator';
|
|
65
65
|
|
|
66
66
|
@Injectable()
|
|
67
67
|
export class ReportService {
|
|
@@ -80,8 +80,8 @@ export class ReportService {
|
|
|
80
80
|
return await this.minioService.uploadBuffer(
|
|
81
81
|
mergedBuffer,
|
|
82
82
|
`merged-invoice-${Date.now()}.pdf`,
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
'application/pdf',
|
|
84
|
+
'invoices',
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -256,8 +256,8 @@ async convertViaRemote(docxBuffer: Buffer): Promise<Buffer> {
|
|
|
256
256
|
Utility service for file operations:
|
|
257
257
|
|
|
258
258
|
```typescript
|
|
259
|
-
import { Injectable } from
|
|
260
|
-
import { FileHelperService } from
|
|
259
|
+
import { Injectable } from '@nestjs/common';
|
|
260
|
+
import { FileHelperService } from '@zola_do/document-manipulator';
|
|
261
261
|
|
|
262
262
|
@Injectable()
|
|
263
263
|
export class DocumentService {
|
|
@@ -275,7 +275,7 @@ export class DocumentService {
|
|
|
275
275
|
|
|
276
276
|
// Validate file type
|
|
277
277
|
if (!this.fileHelper.isValidDocumentType(ext)) {
|
|
278
|
-
throw new BadRequestException(
|
|
278
|
+
throw new BadRequestException('Invalid document type');
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
// Get file size
|
|
@@ -374,7 +374,7 @@ class DocumentManipulatorService {
|
|
|
374
374
|
// Conversion
|
|
375
375
|
async convertDocument(
|
|
376
376
|
buffer: Buffer,
|
|
377
|
-
outputExtension:
|
|
377
|
+
outputExtension: '.pdf' | '.html' | '.odt',
|
|
378
378
|
): Promise<Buffer>;
|
|
379
379
|
}
|
|
380
380
|
```
|
|
@@ -464,7 +464,7 @@ Check that the input buffer is a valid document:
|
|
|
464
464
|
|
|
465
465
|
```typescript
|
|
466
466
|
if (buffer.length === 0) {
|
|
467
|
-
throw new Error(
|
|
467
|
+
throw new Error('Empty buffer');
|
|
468
468
|
}
|
|
469
469
|
```
|
|
470
470
|
|
|
@@ -474,8 +474,8 @@ Ensure PDF buffers are valid:
|
|
|
474
474
|
|
|
475
475
|
```typescript
|
|
476
476
|
// Verify PDF header
|
|
477
|
-
if (!buffer.slice(0, 4).equals(Buffer.from(
|
|
478
|
-
throw new Error(
|
|
477
|
+
if (!buffer.slice(0, 4).equals(Buffer.from('%PDF'))) {
|
|
478
|
+
throw new Error('Invalid PDF buffer');
|
|
479
479
|
}
|
|
480
480
|
```
|
|
481
481
|
|