@hazeljs/pdf-to-audio 0.2.0-alpha.1
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/LICENSE +192 -0
- package/README.md +96 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +49 -0
- package/dist/index.test.js.map +1 -0
- package/dist/pdf-extractor.d.ts +5 -0
- package/dist/pdf-extractor.d.ts.map +1 -0
- package/dist/pdf-extractor.js +15 -0
- package/dist/pdf-extractor.js.map +1 -0
- package/dist/pdf-extractor.test.d.ts +2 -0
- package/dist/pdf-extractor.test.d.ts.map +1 -0
- package/dist/pdf-extractor.test.js +40 -0
- package/dist/pdf-extractor.test.js.map +1 -0
- package/dist/pdf-to-audio-queue.worker.d.ts +16 -0
- package/dist/pdf-to-audio-queue.worker.d.ts.map +1 -0
- package/dist/pdf-to-audio-queue.worker.js +103 -0
- package/dist/pdf-to-audio-queue.worker.js.map +1 -0
- package/dist/pdf-to-audio-queue.worker.test.d.ts +2 -0
- package/dist/pdf-to-audio-queue.worker.test.d.ts.map +1 -0
- package/dist/pdf-to-audio-queue.worker.test.js +24 -0
- package/dist/pdf-to-audio-queue.worker.test.js.map +1 -0
- package/dist/pdf-to-audio.controller.d.ts +10 -0
- package/dist/pdf-to-audio.controller.d.ts.map +1 -0
- package/dist/pdf-to-audio.controller.js +210 -0
- package/dist/pdf-to-audio.controller.js.map +1 -0
- package/dist/pdf-to-audio.controller.test.d.ts +2 -0
- package/dist/pdf-to-audio.controller.test.d.ts.map +1 -0
- package/dist/pdf-to-audio.controller.test.js +252 -0
- package/dist/pdf-to-audio.controller.test.js.map +1 -0
- package/dist/pdf-to-audio.module.d.ts +30 -0
- package/dist/pdf-to-audio.module.d.ts.map +1 -0
- package/dist/pdf-to-audio.module.js +66 -0
- package/dist/pdf-to-audio.module.js.map +1 -0
- package/dist/pdf-to-audio.module.test.d.ts +2 -0
- package/dist/pdf-to-audio.module.test.d.ts.map +1 -0
- package/dist/pdf-to-audio.module.test.js +50 -0
- package/dist/pdf-to-audio.module.test.js.map +1 -0
- package/dist/pdf-to-audio.service.d.ts +10 -0
- package/dist/pdf-to-audio.service.d.ts.map +1 -0
- package/dist/pdf-to-audio.service.js +132 -0
- package/dist/pdf-to-audio.service.js.map +1 -0
- package/dist/pdf-to-audio.service.test.d.ts +2 -0
- package/dist/pdf-to-audio.service.test.d.ts.map +1 -0
- package/dist/pdf-to-audio.service.test.js +146 -0
- package/dist/pdf-to-audio.service.test.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2024 HazelJS Team
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
22
|
+
|
|
23
|
+
1. Definitions.
|
|
24
|
+
|
|
25
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
26
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
27
|
+
|
|
28
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
29
|
+
the copyright owner that is granting the License.
|
|
30
|
+
|
|
31
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
32
|
+
other entities that control, are controlled by, or are under common
|
|
33
|
+
control with that entity. For the purposes of this definition,
|
|
34
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
35
|
+
direction or management of such entity, whether by contract or
|
|
36
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
37
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
38
|
+
|
|
39
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
40
|
+
exercising permissions granted by this License.
|
|
41
|
+
|
|
42
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
43
|
+
including but not limited to software source code, documentation
|
|
44
|
+
source, and configuration files.
|
|
45
|
+
|
|
46
|
+
"Object" form shall mean any form resulting from mechanical
|
|
47
|
+
transformation or translation of a Source form, including but
|
|
48
|
+
not limited to compiled object code, generated documentation,
|
|
49
|
+
and conversions to other media types.
|
|
50
|
+
|
|
51
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
52
|
+
Object form, made available under the License, as indicated by a
|
|
53
|
+
copyright notice that is included in or attached to the work
|
|
54
|
+
(an example is provided in the Appendix below).
|
|
55
|
+
|
|
56
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
57
|
+
form, that is based on (or derived from) the Work and for which the
|
|
58
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
59
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
60
|
+
of this License, Derivative Works shall not include works that remain
|
|
61
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
62
|
+
the Work and Derivative Works thereof.
|
|
63
|
+
|
|
64
|
+
"Contribution" shall mean any work of authorship, including
|
|
65
|
+
the original version of the Work and any modifications or additions
|
|
66
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
67
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
68
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
69
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
70
|
+
means any form of electronic, verbal, or written communication sent
|
|
71
|
+
to the Licensor or its representatives, including but not limited to
|
|
72
|
+
communication on electronic mailing lists, source code control systems,
|
|
73
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
74
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
75
|
+
excluding communication that is conspicuously marked or otherwise
|
|
76
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
77
|
+
|
|
78
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
79
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
80
|
+
subsequently incorporated within the Work.
|
|
81
|
+
|
|
82
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
83
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
84
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
85
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
86
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
87
|
+
Work and such Derivative Works in Source or Object form.
|
|
88
|
+
|
|
89
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
90
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
91
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
92
|
+
(except as stated in this section) patent license to make, have made,
|
|
93
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
94
|
+
where such license applies only to those patent claims licensable
|
|
95
|
+
by such Contributor that are necessarily infringed by their
|
|
96
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
97
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
98
|
+
institute patent litigation against any entity (including a
|
|
99
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
100
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
101
|
+
or contributory patent infringement, then any patent licenses
|
|
102
|
+
granted to You under this License for that Work shall terminate
|
|
103
|
+
as of the date such litigation is filed.
|
|
104
|
+
|
|
105
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
106
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
107
|
+
modifications, and in Source or Object form, provided that You
|
|
108
|
+
meet the following conditions:
|
|
109
|
+
|
|
110
|
+
(a) You must give any other recipients of the Work or
|
|
111
|
+
Derivative Works a copy of this License; and
|
|
112
|
+
|
|
113
|
+
(b) You must cause any modified files to carry prominent notices
|
|
114
|
+
stating that You changed the files; and
|
|
115
|
+
|
|
116
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
117
|
+
that You distribute, all copyright, patent, trademark, and
|
|
118
|
+
attribution notices from the Source form of the Work,
|
|
119
|
+
excluding those notices that do not pertain to any part of
|
|
120
|
+
the Derivative Works; and
|
|
121
|
+
|
|
122
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
123
|
+
distribution, then any Derivative Works that You distribute must
|
|
124
|
+
include a readable copy of the attribution notices contained
|
|
125
|
+
within such NOTICE file, excluding those notices that do not
|
|
126
|
+
pertain to any part of the Derivative Works, in at least one
|
|
127
|
+
of the following places: within a NOTICE text file distributed
|
|
128
|
+
as part of the Derivative Works; within the Source form or
|
|
129
|
+
documentation, if provided along with the Derivative Works; or,
|
|
130
|
+
within a display generated by the Derivative Works, if and
|
|
131
|
+
wherever such third-party notices normally appear. The contents
|
|
132
|
+
of the NOTICE file are for informational purposes only and
|
|
133
|
+
do not modify the License. You may add Your own attribution
|
|
134
|
+
notices within Derivative Works that You distribute, alongside
|
|
135
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
136
|
+
that such additional attribution notices cannot be construed
|
|
137
|
+
as modifying the License.
|
|
138
|
+
|
|
139
|
+
You may add Your own copyright statement to Your modifications and
|
|
140
|
+
may provide additional or different license terms and conditions
|
|
141
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
142
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
143
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
144
|
+
the conditions stated in this License.
|
|
145
|
+
|
|
146
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
147
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
148
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
149
|
+
this License, without any additional terms or conditions.
|
|
150
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
151
|
+
the terms of any separate license agreement you may have executed
|
|
152
|
+
with Licensor regarding such Contributions.
|
|
153
|
+
|
|
154
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
155
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
156
|
+
except as required for reasonable and customary use in describing the
|
|
157
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
158
|
+
|
|
159
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
160
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
161
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
162
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
163
|
+
implied, including, without limitation, any warranties or conditions
|
|
164
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
165
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
166
|
+
appropriateness of using or redistributing the Work and assume any
|
|
167
|
+
risks associated with Your exercise of permissions under this License.
|
|
168
|
+
|
|
169
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
170
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
171
|
+
unless required by applicable law (such as deliberate and grossly
|
|
172
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
173
|
+
liable to You for damages, including any direct, indirect, special,
|
|
174
|
+
incidental, or consequential damages of any character arising as a
|
|
175
|
+
result of this License or out of the use or inability to use the
|
|
176
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
177
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
178
|
+
other commercial damages or losses), even if such Contributor
|
|
179
|
+
has been advised of the possibility of such damages.
|
|
180
|
+
|
|
181
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
182
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
183
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
184
|
+
or other liability obligations and/or rights consistent with this
|
|
185
|
+
License. However, in accepting such obligations, You may act only
|
|
186
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
187
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
188
|
+
defend, and hold each Contributor harmless for any liability
|
|
189
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
190
|
+
of your accepting any such warranty or additional liability.
|
|
191
|
+
|
|
192
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @hazeljs/pdf-to-audio
|
|
2
|
+
|
|
3
|
+
Convert PDF documents to audio using OpenAI TTS. Extracts text from PDFs, chunks it, generates speech per chunk, and merges the audio.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@hazeljs/pdf-to-audio)
|
|
6
|
+
[](https://www.npmjs.com/package/@hazeljs/pdf-to-audio)
|
|
7
|
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @hazeljs/pdf-to-audio @hazeljs/core @hazeljs/ai @hazeljs/queue @hazeljs/rag ioredis
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Note:** Requires Redis for the job queue. Start Redis before using PDF-to-audio.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Module (REST API)
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { HazelApp } from '@hazeljs/core';
|
|
23
|
+
import { PdfToAudioModule } from '@hazeljs/pdf-to-audio';
|
|
24
|
+
|
|
25
|
+
const app = new HazelApp({
|
|
26
|
+
module: YourAppModule,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// In your app module (use forRoot with Redis connection):
|
|
30
|
+
import { HazelModule } from '@hazeljs/core';
|
|
31
|
+
import { PdfToAudioModule } from '@hazeljs/pdf-to-audio';
|
|
32
|
+
|
|
33
|
+
@HazelModule({
|
|
34
|
+
imports: [
|
|
35
|
+
PdfToAudioModule.forRoot({
|
|
36
|
+
connection: {
|
|
37
|
+
host: process.env.REDIS_HOST || 'localhost',
|
|
38
|
+
port: parseInt(process.env.REDIS_PORT || '6379', 10),
|
|
39
|
+
},
|
|
40
|
+
outputDir: './data/pdf-to-audio', // optional, default: ./data/pdf-to-audio
|
|
41
|
+
}),
|
|
42
|
+
],
|
|
43
|
+
})
|
|
44
|
+
export class AppModule {}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Endpoints (async job-based):**
|
|
48
|
+
|
|
49
|
+
1. `POST /api/pdf-to-audio/convert` — Submit PDF, returns `{ jobId }` (202)
|
|
50
|
+
- Content-Type: `multipart/form-data`
|
|
51
|
+
- Field: `file` (PDF file)
|
|
52
|
+
- Optional: `includeSummary` = `"false"`, `summaryOnly` = `"true"`, `voice` = `"alloy"` etc.
|
|
53
|
+
|
|
54
|
+
2. `GET /api/pdf-to-audio/status/:jobId` — Check job status (`pending`, `processing`, `completed`, `failed`)
|
|
55
|
+
|
|
56
|
+
3. `GET /api/pdf-to-audio/download/:jobId` — Download MP3 when job is completed (reads from disk; files stored in `outputDir`)
|
|
57
|
+
|
|
58
|
+
### Service (programmatic)
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { PdfToAudioService } from '@hazeljs/pdf-to-audio';
|
|
62
|
+
import { OpenAIProvider } from '@hazeljs/ai';
|
|
63
|
+
|
|
64
|
+
const provider = new OpenAIProvider();
|
|
65
|
+
const service = new PdfToAudioService(provider);
|
|
66
|
+
const audioBuffer = await service.convert(pdfBuffer, { voice: 'alloy', model: 'tts-1' });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### CLI
|
|
70
|
+
|
|
71
|
+
Requires a running API server. Uses async job flow: submit → poll status → download.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Submit job and wait for completion, then save to output
|
|
75
|
+
hazel pdf-to-audio convert document.pdf --api-url http://localhost:3000 --wait -o audio.mp3
|
|
76
|
+
|
|
77
|
+
# Submit only (returns job ID)
|
|
78
|
+
hazel pdf-to-audio convert document.pdf --api-url http://localhost:3000
|
|
79
|
+
|
|
80
|
+
# Check status and download when ready
|
|
81
|
+
hazel pdf-to-audio status <jobId> --api-url http://localhost:3000 -o audio.mp3
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Environment
|
|
85
|
+
|
|
86
|
+
- `OPENAI_API_KEY` — Required for TTS
|
|
87
|
+
|
|
88
|
+
## Options
|
|
89
|
+
|
|
90
|
+
| Option | Description | Default |
|
|
91
|
+
|--------|-------------|---------|
|
|
92
|
+
| voice | TTS voice (alloy, echo, fable, onyx, nova, shimmer) | alloy |
|
|
93
|
+
| model | TTS model (tts-1, tts-1-hd) | tts-1 |
|
|
94
|
+
| format | Output format (mp3, opus) | mp3 |
|
|
95
|
+
| includeSummary | Include AI-generated document summary at the start of the audio | true |
|
|
96
|
+
| summaryOnly | Output only the summary—do not read the full document | false |
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hazeljs/pdf-to-audio
|
|
3
|
+
* Convert PDF documents to audio using TTS
|
|
4
|
+
*/
|
|
5
|
+
export { PdfToAudioModule } from './pdf-to-audio.module';
|
|
6
|
+
export { PdfToAudioService } from './pdf-to-audio.service';
|
|
7
|
+
export { PDF_TO_AUDIO_QUEUE } from './pdf-to-audio-queue.worker';
|
|
8
|
+
export { extractText } from './pdf-extractor';
|
|
9
|
+
export type { PdfToAudioOptions } from './types';
|
|
10
|
+
export { PDF_TO_AUDIO_OUTPUT_DIR } from './pdf-to-audio.module';
|
|
11
|
+
export type { PdfToAudioModuleOptions } from './pdf-to-audio.module';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,YAAY,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @hazeljs/pdf-to-audio
|
|
4
|
+
* Convert PDF documents to audio using TTS
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.PDF_TO_AUDIO_OUTPUT_DIR = exports.extractText = exports.PDF_TO_AUDIO_QUEUE = exports.PdfToAudioService = exports.PdfToAudioModule = void 0;
|
|
8
|
+
var pdf_to_audio_module_1 = require("./pdf-to-audio.module");
|
|
9
|
+
Object.defineProperty(exports, "PdfToAudioModule", { enumerable: true, get: function () { return pdf_to_audio_module_1.PdfToAudioModule; } });
|
|
10
|
+
var pdf_to_audio_service_1 = require("./pdf-to-audio.service");
|
|
11
|
+
Object.defineProperty(exports, "PdfToAudioService", { enumerable: true, get: function () { return pdf_to_audio_service_1.PdfToAudioService; } });
|
|
12
|
+
var pdf_to_audio_queue_worker_1 = require("./pdf-to-audio-queue.worker");
|
|
13
|
+
Object.defineProperty(exports, "PDF_TO_AUDIO_QUEUE", { enumerable: true, get: function () { return pdf_to_audio_queue_worker_1.PDF_TO_AUDIO_QUEUE; } });
|
|
14
|
+
var pdf_extractor_1 = require("./pdf-extractor");
|
|
15
|
+
Object.defineProperty(exports, "extractText", { enumerable: true, get: function () { return pdf_extractor_1.extractText; } });
|
|
16
|
+
var pdf_to_audio_module_2 = require("./pdf-to-audio.module");
|
|
17
|
+
Object.defineProperty(exports, "PDF_TO_AUDIO_OUTPUT_DIR", { enumerable: true, get: function () { return pdf_to_audio_module_2.PDF_TO_AUDIO_OUTPUT_DIR; } });
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6DAAyD;AAAhD,uHAAA,gBAAgB,OAAA;AACzB,+DAA2D;AAAlD,yHAAA,iBAAiB,OAAA;AAC1B,yEAAiE;AAAxD,+HAAA,kBAAkB,OAAA;AAC3B,iDAA8C;AAArC,4GAAA,WAAW,OAAA;AAEpB,6DAAgE;AAAvD,8HAAA,uBAAuB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const pdfToAudio = __importStar(require("./index"));
|
|
37
|
+
describe('@hazeljs/pdf-to-audio exports', () => {
|
|
38
|
+
it('should export PdfToAudioModule', () => {
|
|
39
|
+
expect(pdfToAudio.PdfToAudioModule).toBeDefined();
|
|
40
|
+
});
|
|
41
|
+
it('should export PdfToAudioService', () => {
|
|
42
|
+
expect(pdfToAudio.PdfToAudioService).toBeDefined();
|
|
43
|
+
});
|
|
44
|
+
it('should export extractText', () => {
|
|
45
|
+
expect(pdfToAudio.extractText).toBeDefined();
|
|
46
|
+
expect(typeof pdfToAudio.extractText).toBe('function');
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACxC,MAAM,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,WAAW,EAAE,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,WAAW,EAAE,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7C,MAAM,CAAC,OAAO,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-extractor.d.ts","sourceRoot":"","sources":["../src/pdf-extractor.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGjE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractText = extractText;
|
|
7
|
+
const pdf_parse_1 = __importDefault(require("pdf-parse"));
|
|
8
|
+
/**
|
|
9
|
+
* Extract raw text from a PDF buffer
|
|
10
|
+
*/
|
|
11
|
+
async function extractText(buffer) {
|
|
12
|
+
const data = await (0, pdf_parse_1.default)(buffer);
|
|
13
|
+
return data.text;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=pdf-extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-extractor.js","sourceRoot":"","sources":["../src/pdf-extractor.ts"],"names":[],"mappings":";;;;;AAKA,kCAGC;AARD,0DAA4B;AAE5B;;GAEG;AACI,KAAK,UAAU,WAAW,CAAC,MAAc;IAC9C,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAG,EAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-extractor.test.d.ts","sourceRoot":"","sources":["../src/pdf-extractor.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pdf_extractor_1 = require("./pdf-extractor");
|
|
4
|
+
const mockPdf = jest.fn();
|
|
5
|
+
jest.mock('pdf-parse', () => ({
|
|
6
|
+
__esModule: true,
|
|
7
|
+
default: (buffer) => mockPdf(buffer),
|
|
8
|
+
}));
|
|
9
|
+
describe('extractText', () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
it('should extract text from PDF buffer', async () => {
|
|
14
|
+
const buffer = Buffer.from('fake-pdf-content');
|
|
15
|
+
mockPdf.mockResolvedValue({ text: 'Extracted document text' });
|
|
16
|
+
const result = await (0, pdf_extractor_1.extractText)(buffer);
|
|
17
|
+
expect(mockPdf).toHaveBeenCalledWith(buffer);
|
|
18
|
+
expect(result).toBe('Extracted document text');
|
|
19
|
+
});
|
|
20
|
+
it('should return empty string when PDF has no text', async () => {
|
|
21
|
+
mockPdf.mockResolvedValue({ text: '' });
|
|
22
|
+
const result = await (0, pdf_extractor_1.extractText)(Buffer.from('empty-pdf'));
|
|
23
|
+
expect(result).toBe('');
|
|
24
|
+
});
|
|
25
|
+
it('should propagate pdf-parse errors', async () => {
|
|
26
|
+
mockPdf.mockRejectedValue(new Error('Invalid PDF'));
|
|
27
|
+
await expect((0, pdf_extractor_1.extractText)(Buffer.from('invalid'))).rejects.toThrow('Invalid PDF');
|
|
28
|
+
});
|
|
29
|
+
it('should handle PDF with metadata', async () => {
|
|
30
|
+
mockPdf.mockResolvedValue({
|
|
31
|
+
text: 'Document content',
|
|
32
|
+
numpages: 5,
|
|
33
|
+
info: {},
|
|
34
|
+
metadata: {},
|
|
35
|
+
});
|
|
36
|
+
const result = await (0, pdf_extractor_1.extractText)(Buffer.from('pdf'));
|
|
37
|
+
expect(result).toBe('Document content');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=pdf-extractor.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-extractor.test.js","sourceRoot":"","sources":["../src/pdf-extractor.test.ts"],"names":[],"mappings":";;AAAA,mDAA8C;AAE9C,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAE1B,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;IAC5B,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;CAC7C,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACnD,MAAM,MAAM,GAAG,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C,KAAK,CAAC,CAAC,CAAC;QAErD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { QueueService } from '@hazeljs/queue';
|
|
2
|
+
import type { PdfToAudioOptions } from './types';
|
|
3
|
+
export declare const PDF_TO_AUDIO_QUEUE = "pdf-to-audio";
|
|
4
|
+
export interface PdfToAudioJobData {
|
|
5
|
+
pdfBase64: string;
|
|
6
|
+
options: PdfToAudioOptions;
|
|
7
|
+
}
|
|
8
|
+
export declare class PdfToAudioQueueWorker {
|
|
9
|
+
private readonly queueService;
|
|
10
|
+
private readonly outputDir;
|
|
11
|
+
private worker;
|
|
12
|
+
constructor(queueService: QueueService, outputDir: string);
|
|
13
|
+
private start;
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=pdf-to-audio-queue.worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-to-audio-queue.worker.d.ts","sourceRoot":"","sources":["../src/pdf-to-audio-queue.worker.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,iBAAiB,CAAC;CAC5B;AAED,qBACa,qBAAqB;IAI9B,OAAO,CAAC,QAAQ,CAAC,YAAY;IACI,OAAO,CAAC,QAAQ,CAAC,SAAS;IAJ7D,OAAO,CAAC,MAAM,CAAkD;gBAG7C,YAAY,EAAE,YAAY,EACO,SAAS,EAAE,MAAM;IAKrE,OAAO,CAAC,KAAK;IAwEP,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAO5B"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.PdfToAudioQueueWorker = exports.PDF_TO_AUDIO_QUEUE = void 0;
|
|
19
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const core_1 = require("@hazeljs/core");
|
|
22
|
+
const bullmq_1 = require("bullmq");
|
|
23
|
+
const queue_1 = require("@hazeljs/queue");
|
|
24
|
+
const pdf_to_audio_service_1 = require("./pdf-to-audio.service");
|
|
25
|
+
const pdf_to_audio_module_1 = require("./pdf-to-audio.module");
|
|
26
|
+
exports.PDF_TO_AUDIO_QUEUE = 'pdf-to-audio';
|
|
27
|
+
let PdfToAudioQueueWorker = class PdfToAudioQueueWorker {
|
|
28
|
+
constructor(queueService, outputDir) {
|
|
29
|
+
this.queueService = queueService;
|
|
30
|
+
this.outputDir = outputDir;
|
|
31
|
+
this.worker = null;
|
|
32
|
+
this.start();
|
|
33
|
+
}
|
|
34
|
+
start() {
|
|
35
|
+
const connection = this.queueService.getConnection();
|
|
36
|
+
if (!connection) {
|
|
37
|
+
core_1.logger.warn('PdfToAudioQueueWorker: QueueService not configured (no Redis connection). PDF-to-audio jobs will not be processed.');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Ensure queue exists
|
|
41
|
+
this.queueService.getQueue(exports.PDF_TO_AUDIO_QUEUE);
|
|
42
|
+
this.worker = new bullmq_1.Worker(exports.PDF_TO_AUDIO_QUEUE, async (job) => {
|
|
43
|
+
core_1.logger.info(`PdfToAudio job ${job.id} started`);
|
|
44
|
+
const container = core_1.Container.getInstance();
|
|
45
|
+
const service = container.resolve(pdf_to_audio_service_1.PdfToAudioService);
|
|
46
|
+
if (!service) {
|
|
47
|
+
throw new Error('PdfToAudioService not found in container');
|
|
48
|
+
}
|
|
49
|
+
const { pdfBase64, options } = job.data;
|
|
50
|
+
const pdfBuffer = Buffer.from(pdfBase64, 'base64');
|
|
51
|
+
core_1.logger.info(`PdfToAudio job ${job.id}: PDF decoded (${(pdfBuffer.length / 1024).toFixed(1)} KB), starting conversion`);
|
|
52
|
+
const audioBuffer = await service.convert(pdfBuffer, options, (completed, total, phase) => {
|
|
53
|
+
void job.updateProgress({ completed, total, phase });
|
|
54
|
+
if (phase) {
|
|
55
|
+
core_1.logger.info(`PdfToAudio job ${job.id}: ${phase}`);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const pct = total > 0 ? Math.round((completed / total) * 100) : 0;
|
|
59
|
+
const everyN = total > 20 ? 5 : total > 10 ? 3 : 1;
|
|
60
|
+
const shouldLog = completed === total || completed <= 3 || completed % everyN === 0;
|
|
61
|
+
if (shouldLog) {
|
|
62
|
+
core_1.logger.info(`PdfToAudio job ${job.id}: ${completed}/${total} chunks (${pct}%)`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const jobId = String(job.id);
|
|
67
|
+
const defaultDir = path_1.default.resolve(process.cwd(), 'data/pdf-to-audio');
|
|
68
|
+
const rawDir = this.outputDir != null && this.outputDir !== '' ? String(this.outputDir).trim() : '';
|
|
69
|
+
const outputDir = rawDir || defaultDir;
|
|
70
|
+
const outPath = path_1.default.join(outputDir, `${jobId}.mp3`);
|
|
71
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
72
|
+
fs_1.default.writeFileSync(outPath, audioBuffer);
|
|
73
|
+
core_1.logger.info(`PdfToAudio job ${job.id} completed, saved to ${outPath}`);
|
|
74
|
+
return outPath;
|
|
75
|
+
}, {
|
|
76
|
+
connection: connection,
|
|
77
|
+
concurrency: 1,
|
|
78
|
+
lockDuration: 30 * 60 * 1000, // 30 min - job can take many minutes for large PDFs
|
|
79
|
+
lockRenewTime: 30 * 1000, // renew lock every 30 sec so job doesn't stall
|
|
80
|
+
});
|
|
81
|
+
this.worker.on('active', (job) => {
|
|
82
|
+
core_1.logger.info(`PdfToAudio job ${job.id} picked up by worker`);
|
|
83
|
+
});
|
|
84
|
+
this.worker.on('failed', (job, err) => {
|
|
85
|
+
core_1.logger.error(`PdfToAudio job ${job?.id} failed:`, err);
|
|
86
|
+
});
|
|
87
|
+
core_1.logger.info('PdfToAudioQueueWorker started');
|
|
88
|
+
}
|
|
89
|
+
async stop() {
|
|
90
|
+
if (this.worker) {
|
|
91
|
+
await this.worker.close();
|
|
92
|
+
this.worker = null;
|
|
93
|
+
core_1.logger.info('PdfToAudioQueueWorker stopped');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.PdfToAudioQueueWorker = PdfToAudioQueueWorker;
|
|
98
|
+
exports.PdfToAudioQueueWorker = PdfToAudioQueueWorker = __decorate([
|
|
99
|
+
(0, core_1.Service)(),
|
|
100
|
+
__param(1, (0, core_1.Inject)(pdf_to_audio_module_1.PDF_TO_AUDIO_OUTPUT_DIR)),
|
|
101
|
+
__metadata("design:paramtypes", [queue_1.QueueService, String])
|
|
102
|
+
], PdfToAudioQueueWorker);
|
|
103
|
+
//# sourceMappingURL=pdf-to-audio-queue.worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-to-audio-queue.worker.js","sourceRoot":"","sources":["../src/pdf-to-audio-queue.worker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,wCAAmE;AACnE,mCAAgC;AAChC,0CAA8C;AAC9C,iEAA2D;AAC3D,+DAAgE;AAGnD,QAAA,kBAAkB,GAAG,cAAc,CAAC;AAQ1C,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAGhC,YACmB,YAA0B,EACV,SAAkC;QADlD,iBAAY,GAAZ,YAAY,CAAc;QACO,cAAS,GAAT,SAAS,CAAQ;QAJ7D,WAAM,GAA6C,IAAI,CAAC;QAM9D,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAEO,KAAK;QACX,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC;QACrD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,aAAM,CAAC,IAAI,CACT,oHAAoH,CACrH,CAAC;YACF,OAAO;QACT,CAAC;QAED,sBAAsB;QACtB,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,0BAAkB,CAAC,CAAC;QAE/C,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CACtB,0BAAkB,EAClB,KAAK,EAAE,GAAG,EAAE,EAAE;YACZ,aAAM,CAAC,IAAI,CAAC,kBAAkB,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;YAEhD,MAAM,SAAS,GAAG,gBAAS,CAAC,WAAW,EAAE,CAAC;YAC1C,MAAM,OAAO,GA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E;YAC/B,aAAM,CAAC,IAAI,CAAC,kBAAkB,GAAG,CAAC,EAAE,sBAAsB,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACpC,aAAM,CAAC,KAAK,CAAC,kBAAkB,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;QAEH,aAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,aAAM,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;CACF,CAAA;AAzFY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,cAAO,GAAE;IAML,WAAA,IAAA,aAAM,EAAC,6CAAuB,CAAC,CAAA;qCADD,oBAAY;GAJlC,qBAAqB,CAyFjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-to-audio-queue.worker.test.d.ts","sourceRoot":"","sources":["../src/pdf-to-audio-queue.worker.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pdf_to_audio_queue_worker_1 = require("./pdf-to-audio-queue.worker");
|
|
4
|
+
describe('PdfToAudioQueueWorker', () => {
|
|
5
|
+
it('should not create worker when QueueService has no connection', () => {
|
|
6
|
+
const mockQueueService = {
|
|
7
|
+
getConnection: jest.fn().mockReturnValue(null),
|
|
8
|
+
getQueue: jest.fn(),
|
|
9
|
+
};
|
|
10
|
+
const worker = new pdf_to_audio_queue_worker_1.PdfToAudioQueueWorker(mockQueueService, '/tmp/pdf-to-audio');
|
|
11
|
+
expect(mockQueueService.getConnection).toHaveBeenCalled();
|
|
12
|
+
expect(mockQueueService.getQueue).not.toHaveBeenCalled();
|
|
13
|
+
expect(worker).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
it('should call stop without error when worker was never started', async () => {
|
|
16
|
+
const mockQueueService = {
|
|
17
|
+
getConnection: jest.fn().mockReturnValue(null),
|
|
18
|
+
getQueue: jest.fn(),
|
|
19
|
+
};
|
|
20
|
+
const worker = new pdf_to_audio_queue_worker_1.PdfToAudioQueueWorker(mockQueueService, '/tmp/pdf-to-audio');
|
|
21
|
+
await expect(worker.stop()).resolves.not.toThrow();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
//# sourceMappingURL=pdf-to-audio-queue.worker.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-to-audio-queue.worker.test.js","sourceRoot":"","sources":["../src/pdf-to-audio-queue.worker.test.ts"],"names":[],"mappings":";;AAAA,2EAAoE;AAEpE,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;QACtE,MAAM,gBAAgB,GAAG;YACvB,aAAa,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC;YAC9C,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;SACpB,CAAC;QACF,MAAM,MAAM,GAAG,IAAI,iDAAqB,CAAC,gBAAyB,EAAE,mBAAmB,CAAC,CAAC;QACzF,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAC1D,MAAM,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACzD,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8DAA8D,EAAE,KAAK,IAAI,EAAE;QAC5E,MAAM,gBAAgB,GAAG;YACvB,aAAa,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC;YAC9C,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;SACpB,CAAC;QACF,MAAM,MAAM,GAAG,IAAI,iDAAqB,CAAC,gBAAyB,EAAE,mBAAmB,CAAC,CAAC;QACzF,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|