1
+ const fs = require ( 'fs' ) ;
2
+ const child_process = require ( "node:child_process" ) ;
3
+
4
+ /**
5
+ * @typedef {Object } LLSEntry
6
+ * @property {string } llsname
7
+ * @property {number } llsidx
8
+ * @property {string } category
9
+ * @property {Omit<LLSEntry, 'subitems'>[] } [subitems]
10
+ */
11
+
12
+ /**
13
+ * @type {{lls: Record<string, LLSEntry[]>} }
14
+ */
15
+ const optionTable = JSON . parse ( fs . readFileSync ( '/etc/factorymanager/db/optionTable.json' , 'utf-8' ) ) ;
16
+
17
+ /**
18
+ * @typedef {Object } ExportOption
19
+ * @property {string } key
20
+ * @property {string } name
21
+ * @property {string } type
22
+ */
23
+
24
+ /**
25
+ * @type {{'export': Record<string, ExportOption[]>} }
26
+ */
27
+ const exportTable = JSON . parse ( fs . readFileSync ( '/etc/factorymanager/db/exportOptions.json' , 'utf-8' ) ) ;
28
+
29
+ /**
30
+ *
31
+ * @param dbid {string}
32
+ * @param llsname {string}
33
+ */
34
+ function getLLSValue ( dbid , llsname ) {
35
+ const buf = child_process . execSync ( `luna-send -n 1 -f 'luna://com.webos.service.lowlevelstorage/getData' '{"dbgroups":[{"dbid":"${ dbid } ","items":["${ llsname } "]}]}'` , { encoding : 'utf-8' } ) ;
36
+ const data = JSON . parse ( buf ) ;
37
+ if ( data . returnValue ) {
38
+ return `\`${ JSON . stringify ( data . dbgroups [ 0 ] . items [ llsname ] ) } \`` ;
39
+ }
40
+ return null ;
41
+ }
42
+
43
+ const categoryMapping = {
44
+ 'factorydb' : 'factory' ,
45
+ 'tv.model' : 'factory' ,
46
+ 'system' : 'system' ,
47
+ } ;
48
+
49
+ /**
50
+ * @param key {string}
51
+ * @returns {ExportOption | null }
52
+ */
53
+ function getExportOption ( key ) {
54
+ for ( const groupKey in exportTable . export ) {
55
+ for ( const entry of exportTable . export [ groupKey ] ) {
56
+ if ( entry . key === key ) {
57
+ return entry ;
58
+ }
59
+ }
60
+ }
61
+ return null ;
62
+ }
63
+
64
+ console . log ( '| Category | LLS Name | Export Option | Example Value |' ) ;
65
+ console . log ( '|---|---|---|---|' ) ;
66
+ for ( const groupKey in optionTable . lls ) {
67
+ for ( const entry of optionTable . lls [ groupKey ] ) {
68
+ const category = categoryMapping [ entry . category ] || entry . category ;
69
+ if ( entry . llsname === 'null' ) {
70
+ continue ;
71
+ }
72
+ if ( ! entry . subitems ?. length ) {
73
+ console . log ( '|' , category , '|' , entry . llsname , '|' , getExportOption ( entry . llsname ) ?. name ?? '' , '|' , getLLSValue ( category , entry . llsname ) , '|' ) ;
74
+ } else {
75
+ for ( const subitem of entry . subitems ) {
76
+ if ( ! subitem . llsname ) {
77
+ continue ;
78
+ }
79
+ console . log ( '|' , category , '|' , subitem . llsname , '|' , getExportOption ( subitem . llsname ) ?. name ?? '' , '|' , getLLSValue ( category , subitem . llsname ) , '|' ) ;
80
+ }
81
+ }
82
+ }
83
+ }
0 commit comments