@kyyinfinite/lumina 1.0.4 → 1.0.5
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 +0 -82
- package/package.json +1 -1
- package/src/media/video.js +19 -30
- package/src/parsers/code-tokenizer-keywords.js +0 -2
- package/src/parsers/code-tokenizer.js +0 -4
- package/src/proto/updater.js +0 -12
package/README.md
CHANGED
|
@@ -360,88 +360,6 @@ Type-checked features:
|
|
|
360
360
|
- Enum-like catalogs (`MessageType`, `HeaderType`, `LayoutKind`, ...) are `Readonly`
|
|
361
361
|
- `Bot.raw` escape hatch typed as `WASocket`
|
|
362
362
|
|
|
363
|
-
|
|
364
|
-
---
|
|
365
|
-
|
|
366
|
-
## Baileys Compatibility
|
|
367
|
-
|
|
368
|
-
Lumina is not tied to a specific Baileys version or fork. When `new Bot(sock)` is called, Lumina automatically detects the available Baileys package in your project.
|
|
369
|
-
|
|
370
|
-
### Auto-Detect (default)
|
|
371
|
-
|
|
372
|
-
No configuration is required. Lumina tries the following packages in order and uses the first one that can be successfully imported:
|
|
373
|
-
|
|
374
|
-
```
|
|
375
|
-
@kyyinfinite/baileys
|
|
376
|
-
@whiskeysockets/baileys
|
|
377
|
-
baileys
|
|
378
|
-
@adiwajshing/baileys
|
|
379
|
-
@brunocgc/baileys
|
|
380
|
-
@open-wa/baileys
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
```js
|
|
384
|
-
// Lumina automatically detects @kyyinfinite/baileys (or any installed fork)
|
|
385
|
-
const bot = new Bot(sock)
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
---
|
|
389
|
-
|
|
390
|
-
### Explicit Package Name
|
|
391
|
-
|
|
392
|
-
If you're using a custom-named fork, specify it with `baileysPackage`:
|
|
393
|
-
|
|
394
|
-
```js
|
|
395
|
-
const bot = new Bot(sock, {
|
|
396
|
-
baileysPackage: '@namafork/baileys',
|
|
397
|
-
})
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
---
|
|
401
|
-
|
|
402
|
-
### Module Injection
|
|
403
|
-
|
|
404
|
-
The fastest option — zero dynamic imports. Simply inject the module directly:
|
|
405
|
-
|
|
406
|
-
```js
|
|
407
|
-
import * as baileys from '@kyyinfinite/baileys'
|
|
408
|
-
|
|
409
|
-
const bot = new Bot(sock, {
|
|
410
|
-
baileys,
|
|
411
|
-
})
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
This is ideal if you've already imported Baileys elsewhere and want to avoid duplicate imports.
|
|
415
|
-
|
|
416
|
-
---
|
|
417
|
-
|
|
418
|
-
### Socket Fallback
|
|
419
|
-
|
|
420
|
-
If no Baileys package is found, Lumina falls back to its internal socket-based implementation. Core features (text, buttons, carousel, stickers) continue to work. Media uploads require `sock.waUploadToServer` to be available.
|
|
421
|
-
|
|
422
|
-
---
|
|
423
|
-
|
|
424
|
-
### Debug: Check the Active Adapter
|
|
425
|
-
|
|
426
|
-
```js
|
|
427
|
-
const bot = new Bot(sock)
|
|
428
|
-
console.log(await bot.connection.adapterSource())
|
|
429
|
-
// → '@kyyinfinite/baileys'
|
|
430
|
-
// → '@whiskeysockets/baileys'
|
|
431
|
-
// → 'injected-module'
|
|
432
|
-
// → 'socket-fallback'
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
---
|
|
436
|
-
|
|
437
|
-
### Summary
|
|
438
|
-
|
|
439
|
-
| Option | When to use |
|
|
440
|
-
|---|---|
|
|
441
|
-
| _(not set)_ | Auto-detect. Recommended for most use cases. |
|
|
442
|
-
| `baileysPackage: 'name'` | For custom forks that are not included in the auto-detect list. |
|
|
443
|
-
| `baileys: module` | Manual module injection for the best performance. |
|
|
444
|
-
|
|
445
363
|
---
|
|
446
364
|
|
|
447
365
|
## API Reference
|
package/package.json
CHANGED
package/src/media/video.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
*
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
1
|
import { PassThrough, Readable } from 'node:stream'
|
|
6
|
-
|
|
7
2
|
import { MediaError } from '../errors.js'
|
|
8
3
|
import { resize } from './image.js'
|
|
9
4
|
|
|
@@ -16,7 +11,7 @@ async function loadFfmpeg() {
|
|
|
16
11
|
return (await import('fluent-ffmpeg')).default
|
|
17
12
|
} catch (err) {
|
|
18
13
|
throw new MediaError(
|
|
19
|
-
|
|
14
|
+
'fluent-ffmpeg is not installed. Run: npm i fluent-ffmpeg',
|
|
20
15
|
{ code: 'LUMINA_MEDIA_FFMPEG_MISSING', cause: err },
|
|
21
16
|
)
|
|
22
17
|
}
|
|
@@ -25,8 +20,6 @@ async function loadFfmpeg() {
|
|
|
25
20
|
return ffmpegPromise
|
|
26
21
|
}
|
|
27
22
|
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
23
|
export function getMp4Duration(buffer, opts = {}) {
|
|
31
24
|
const { silent = true } = opts
|
|
32
25
|
|
|
@@ -36,16 +29,12 @@ export function getMp4Duration(buffer, opts = {}) {
|
|
|
36
29
|
}
|
|
37
30
|
|
|
38
31
|
try {
|
|
39
|
-
if (!Buffer.isBuffer(buffer) || buffer.length < 8)
|
|
40
|
-
return fail('invalid buffer: too short')
|
|
41
|
-
}
|
|
32
|
+
if (!Buffer.isBuffer(buffer) || buffer.length < 8) return fail('invalid buffer: too short')
|
|
42
33
|
|
|
43
34
|
let offset = 0
|
|
44
35
|
while (offset < buffer.length - 8) {
|
|
45
36
|
const size = buffer.readUInt32BE(offset)
|
|
46
|
-
if (size < 8 || offset + size > buffer.length)
|
|
47
|
-
return fail('invalid atom size')
|
|
48
|
-
}
|
|
37
|
+
if (size < 8 || offset + size > buffer.length) return fail('invalid atom size')
|
|
49
38
|
|
|
50
39
|
const type = buffer.toString('ascii', offset + 4, offset + 8)
|
|
51
40
|
if (type === 'moov') {
|
|
@@ -53,9 +42,7 @@ export function getMp4Duration(buffer, opts = {}) {
|
|
|
53
42
|
const moovEnd = offset + size
|
|
54
43
|
while (moovOffset < moovEnd - 8) {
|
|
55
44
|
const childSize = buffer.readUInt32BE(moovOffset)
|
|
56
|
-
if (childSize < 8 || moovOffset + childSize > moovEnd)
|
|
57
|
-
return fail('invalid child atom size')
|
|
58
|
-
}
|
|
45
|
+
if (childSize < 8 || moovOffset + childSize > moovEnd) return fail('invalid child atom size')
|
|
59
46
|
const childType = buffer.toString('ascii', moovOffset + 4, moovOffset + 8)
|
|
60
47
|
if (childType === 'mvhd') {
|
|
61
48
|
const version = buffer.readUInt8(moovOffset + 8)
|
|
@@ -87,8 +74,6 @@ export function getMp4Duration(buffer, opts = {}) {
|
|
|
87
74
|
}
|
|
88
75
|
}
|
|
89
76
|
|
|
90
|
-
|
|
91
|
-
*
|
|
92
77
|
export async function extractThumbnail(videoBuffer, opts = {}) {
|
|
93
78
|
const {
|
|
94
79
|
time,
|
|
@@ -105,10 +90,14 @@ export async function extractThumbnail(videoBuffer, opts = {}) {
|
|
|
105
90
|
return new Promise((resolve, reject) => {
|
|
106
91
|
const fail = (err) => {
|
|
107
92
|
if (silent) return resolve(result === 'base64' ? '' : Buffer.alloc(0))
|
|
108
|
-
reject(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
93
|
+
reject(
|
|
94
|
+
err instanceof MediaError
|
|
95
|
+
? err
|
|
96
|
+
: new MediaError(err?.message ?? String(err), {
|
|
97
|
+
code: 'LUMINA_MEDIA_FFMPEG_FAILED',
|
|
98
|
+
cause: err,
|
|
99
|
+
}),
|
|
100
|
+
)
|
|
112
101
|
}
|
|
113
102
|
|
|
114
103
|
if (!Buffer.isBuffer(videoBuffer) || videoBuffer.length === 0) {
|
|
@@ -130,9 +119,7 @@ export async function extractThumbnail(videoBuffer, opts = {}) {
|
|
|
130
119
|
if (frame.length === 0) {
|
|
131
120
|
return fail(new MediaError('ffmpeg produced empty output', { code: 'LUMINA_MEDIA_FFMPEG_EMPTY' }))
|
|
132
121
|
}
|
|
133
|
-
if (resizeOutput) {
|
|
134
|
-
frame = await resize(frame, { width, height, fit: 'cover', format })
|
|
135
|
-
}
|
|
122
|
+
if (resizeOutput) frame = await resize(frame, { width, height, fit: 'cover', format })
|
|
136
123
|
resolve(result === 'base64' ? frame.toString('base64') : frame)
|
|
137
124
|
} catch (err) {
|
|
138
125
|
fail(err)
|
|
@@ -143,10 +130,12 @@ export async function extractThumbnail(videoBuffer, opts = {}) {
|
|
|
143
130
|
try {
|
|
144
131
|
ffmpeg(input)
|
|
145
132
|
.outputOptions([`-ss ${seekTime}`, '-vframes 1', '-vcodec png', '-f image2pipe'])
|
|
146
|
-
.on('error', (err) =>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
133
|
+
.on('error', (err) =>
|
|
134
|
+
fail(new MediaError(`ffmpeg error: ${err.message}`, {
|
|
135
|
+
code: 'LUMINA_MEDIA_FFMPEG_FAILED',
|
|
136
|
+
cause: err,
|
|
137
|
+
})),
|
|
138
|
+
)
|
|
150
139
|
.pipe(output, { end: true })
|
|
151
140
|
} catch (err) {
|
|
152
141
|
fail(err)
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
*
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
1
|
|
|
5
2
|
import { HighlightType, HighlightLabel } from '../proto/enums.js'
|
|
6
3
|
import { KEYWORDS, SLASH_COMMENT_LANGS, HASH_COMMENT_LANGS, BLOCK_COMMENT_LANGS } from './code-tokenizer-keywords.js'
|
|
@@ -17,7 +14,6 @@ function identifierChar(lang) {
|
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
*
|
|
21
17
|
export function tokenizeCode(code, lang = 'javascript') {
|
|
22
18
|
if (typeof code !== 'string' || code.length === 0) {
|
|
23
19
|
return { codeBlock: [], unifiedBlocks: [] }
|
package/src/proto/updater.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
*
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
1
|
|
|
6
2
|
import { promises as fs } from 'node:fs'
|
|
7
3
|
import path from 'node:path'
|
|
@@ -47,7 +43,6 @@ const RE_CONST_REQUIRE =
|
|
|
47
43
|
const RE_DESTRUCT_REQUIRE =
|
|
48
44
|
/(?:const|let|var)\s*\{([^}]+)\}\s*=\s*require\(\s*(['"])([^'"]+)\2\s*\)/g
|
|
49
45
|
|
|
50
|
-
*
|
|
51
46
|
export function transformToESM(src) {
|
|
52
47
|
let out = src
|
|
53
48
|
out = out.replace(RE_CONST_REQUIRE, (_, name, _q, mod) => `import ${name} from '${mod}'`)
|
|
@@ -67,7 +62,6 @@ export function transformToESM(src) {
|
|
|
67
62
|
return out
|
|
68
63
|
}
|
|
69
64
|
|
|
70
|
-
*
|
|
71
65
|
export function applyKnownFixes(filename, content) {
|
|
72
66
|
const applied = []
|
|
73
67
|
let next = content
|
|
@@ -100,7 +94,6 @@ export class ProtoUpdater {
|
|
|
100
94
|
}
|
|
101
95
|
}
|
|
102
96
|
|
|
103
|
-
*
|
|
104
97
|
async #listJsFiles(dir) {
|
|
105
98
|
const entries = await fs.readdir(dir, { withFileTypes: true })
|
|
106
99
|
const out = []
|
|
@@ -112,7 +105,6 @@ export class ProtoUpdater {
|
|
|
112
105
|
return out
|
|
113
106
|
}
|
|
114
107
|
|
|
115
|
-
*
|
|
116
108
|
async backup() {
|
|
117
109
|
await fs.mkdir(this.backupDir, { recursive: true })
|
|
118
110
|
const timestamp = Date.now()
|
|
@@ -127,7 +119,6 @@ export class ProtoUpdater {
|
|
|
127
119
|
return record
|
|
128
120
|
}
|
|
129
121
|
|
|
130
|
-
*
|
|
131
122
|
async #hashTree(dir) {
|
|
132
123
|
const files = (await this.#listJsFiles(dir)).sort()
|
|
133
124
|
const hashes = await Promise.all(
|
|
@@ -139,7 +130,6 @@ export class ProtoUpdater {
|
|
|
139
130
|
return sha256(hashes.join('\n'))
|
|
140
131
|
}
|
|
141
132
|
|
|
142
|
-
*
|
|
143
133
|
async restore(id) {
|
|
144
134
|
const record = this.history.find((h) => h.id === id)
|
|
145
135
|
if (!record) {
|
|
@@ -160,7 +150,6 @@ export class ProtoUpdater {
|
|
|
160
150
|
await this.restore(last.id)
|
|
161
151
|
}
|
|
162
152
|
|
|
163
|
-
*
|
|
164
153
|
async validate() {
|
|
165
154
|
const files = await this.#listJsFiles(this.protoPath)
|
|
166
155
|
const errors = []
|
|
@@ -176,7 +165,6 @@ export class ProtoUpdater {
|
|
|
176
165
|
return { ok: errors.length === 0, errors }
|
|
177
166
|
}
|
|
178
167
|
|
|
179
|
-
*
|
|
180
168
|
async update(opts = {}) {
|
|
181
169
|
const autoRollback = opts.autoRollback ?? true
|
|
182
170
|
const dryRun = opts.dryRun ?? false
|