-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
znum.js
executable file
·33 lines (30 loc) · 1.22 KB
/
znum.js
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
#!/usr/bin/env node
import { join } from 'node:path';
import { rm } from 'node:fs/promises';
import { setTimeout } from 'node:timers/promises';
import prompt from 'prompt';
import { login } from './src/auth.js';
import { getTextBetween } from './src/utils.js';
import { fetchDocumentInfo } from './src/api.js';
import { convertImagesToPdf } from './src/pdf.js';
import { downloadImages } from './src/images.js';
import { WORK_DIR } from './src/constants.js';
(async () => {
await login();
const { url } = await prompt.get(['url']);
const id = getTextBetween(url, 'id=', '&');
console.log('Получение информации о книге...');
const info = await fetchDocumentInfo(url);
console.log('Скачивание изображений...');
const imagesDir = join(WORK_DIR, id);
const images = await downloadImages(imagesDir, id, info);
await setTimeout(500);
console.log('Конвертирование изображений в PDF...');
const output = join(WORK_DIR, `${id}.pdf`);
await convertImagesToPdf(images, output);
await rm(imagesDir, { recursive: true, force: true });
})();
export * from './src/auth.js';
export * from './src/api.js';
export * from './src/images.js';
export * from './src/pdf.js';