|
1 |
| -#!/usr/bin/env tsx |
2 |
| - |
3 |
| -import fs from 'node:fs' |
4 |
| -import path from 'node:path' |
5 |
| -import process from 'node:process' |
6 |
| -import readline from 'node:readline' |
7 |
| -import { appendFileHeaderMetaToBuffer, createGeneraterANSI } from '@qifi/generate' |
8 |
| -import mime from 'mime' |
9 |
| - |
10 |
| -// Function to read file and generate QR codes |
11 |
| -async function generateQRCodes(filePath: string, sliceSize: number = 80, fps: number = 20) { |
12 |
| - const fullPath = path.resolve(filePath) |
13 |
| - |
14 |
| - console.log('fullPath:', fullPath) |
15 |
| - await new Promise(resolve => setTimeout(resolve, 1000)) |
16 |
| - if (!fs.existsSync(fullPath)) { |
17 |
| - console.error(`File not found: ${fullPath}`) |
18 |
| - process.exit(1) |
19 |
| - } |
20 |
| - |
21 |
| - const fileBuffer = fs.readFileSync(fullPath) |
22 |
| - const data = new Uint8Array(fileBuffer) |
23 |
| - const meta = { |
24 |
| - filename: path.basename(fullPath), |
25 |
| - contentType: mime.getType(fullPath) || 'application/octet-stream', |
26 |
| - } |
27 |
| - |
28 |
| - const merged = appendFileHeaderMetaToBuffer(data, meta) |
29 |
| - |
30 |
| - const generator = createGeneraterANSI(merged, { |
31 |
| - urlPrefix: 'https://qrss.netlify.app/#', |
32 |
| - sliceSize, |
33 |
| - border: 2, |
34 |
| - }) |
35 |
| - |
36 |
| - // Clear console function |
37 |
| - const clearConsole = () => { |
38 |
| - readline.cursorTo(process.stdout, 0, 0) |
39 |
| - readline.clearScreenDown(process.stdout) |
40 |
| - } |
41 |
| - |
42 |
| - // Display QR codes |
43 |
| - for (const blockQRCode of generator.fountain()) { |
44 |
| - clearConsole() |
45 |
| - process.stdout.write(`${blockQRCode}\n`) |
46 |
| - process.stdout.write(`${meta.filename} (${meta.contentType}) | size: ${data.length} bytes`) |
47 |
| - await new Promise(resolve => setTimeout(resolve, 1000 / fps)) |
48 |
| - } |
49 |
| -} |
50 |
| - |
51 |
| -// Parse command line arguments |
52 |
| -const args = process.argv.slice(2) |
53 |
| -if (args.length < 1) { |
54 |
| - console.error('Usage: qr-file-transfer <file-path> [slice-size]') |
55 |
| - process.exit(1) |
56 |
| -} |
57 |
| - |
58 |
| -const [filePath, sliceSizeStr, fpsStr] = args |
59 |
| -const sliceSize = sliceSizeStr ? Number.parseInt(sliceSizeStr, 10) : undefined |
60 |
| -const fps = fpsStr ? Number.parseInt(fpsStr, 10) : undefined |
61 |
| - |
62 |
| -if (!filePath) { |
63 |
| - console.error('File path is required') |
64 |
| - process.exit(1) |
65 |
| -} |
66 |
| - |
67 |
| -generateQRCodes(filePath, sliceSize, fps) |
| 1 | +console.warn('qifi is a cli package, it should not be imported in other packages') |
| 2 | +export default function () {} |
0 commit comments