@@ -15,12 +15,13 @@ var http = require('http');
1515var https = require ( 'https' ) ;
1616var ua = require ( 'universal-analytics' ) ;
1717const { promisify, atob, walk, unique} = require ( './helpers' ) ;
18- const { seek4File, copyFile , uploadCopyFiles, configFilesList, configFiles , getBoards, getThermistors} = require ( './common' ) ;
18+ const { seek4File, uploadCopyFiles, configFilesList, configFilesListUpload , getBoards, getThermistors} = require ( './common' ) ;
1919var qr = require ( 'qr-image' ) ;
2020var machineId = require ( 'node-machine-id' ) . machineId ;
2121
2222const store = require ( './store' ) ;
2323store . mods . editor && ( store . mods . editor . root = ( ) => git . root ( ) )
24+ const st = require ( './store-tool' ) ;
2425
2526var server = http . Server ( app ) ;
2627var visitor = ua ( 'UA-99239389-1' ) ;
@@ -58,10 +59,10 @@ var get_cfg=()=>{
5859 . map ( i => Object . assign ( defs . defs [ i ] , { select : a . select , type : "select" } ) )
5960 return defs ;
6061 } )
61- var list = [ 'Configuration.h' , 'Configuration_adv.h' ]
62+ var list = configFilesListUpload
6263 . map ( f => base
6364 . then ( p =>
64- git . Show ( p [ 1 ] , path . join ( store . vars . baseCfg , f ) ) . catch ( e => git . Show ( p [ 1 ] , path . join ( 'Marlin' , f ) ) )
65+ git . Show ( p [ 1 ] , path . join ( store . state . baseCfg , f ) ) . catch ( e => git . Show ( p [ 1 ] , path . join ( 'Marlin' , f ) ) )
6566 . then ( file => mctool . getJson ( p [ 0 ] , file , p [ 1 ] ) ( path . join ( p [ 0 ] , 'Marlin' , f ) ) )
6667 )
6768 . then ( o => ( o . names . filter ( n => hints . d2i ( n . name ) , 1 ) . map ( n => o . defs [ n . name ] . hint = ! 0 ) , o ) )
@@ -80,19 +81,21 @@ app.get('/examples', function (req, res) {
8081 return ex_dir ( )
8182 . then ( dir => ( ex = dir ) )
8283 . then ( walk )
83- . then ( a => a . filter ( i => / C o n f i g u r a t i o n ( _ a d v ) ? \. h / . test ( i ) ) )
84+ . then ( files => files . filter ( file => configFilesList . indexOf ( path . basename ( file ) ) >= 0 ) )
8485 . then ( a => a . map ( i => path . parse ( path . relative ( ex , i ) ) . dir ) )
8586 . then ( unique )
8687 . then ( a => a . sort ( sortNCS ) )
8788 . catch ( e => [ ] )
8889 . then ( a => ( a . unshift ( 'Marlin' ) , a ) )
89- . then ( a => res . send ( { current : store . vars . baseCfg , list : a } ) )
90+ . then ( a => res . send ( { current : store . state . baseCfg , list : a } ) )
9091} ) ;
9192
9293app . get ( '/set-base/:path' , function ( req , res ) {
9394 return Promise . resolve ( atob ( decodeURI ( req . params . path ) ) . toString ( ) )
9495 . then ( base => base == 'Marlin' && base || ex_dir ( 1 ) . then ( ex => path . join ( ex , base ) ) )
95- . then ( base => res . send ( store . vars . baseCfg = base ) )
96+ . then ( base => store . state . baseCfg = base )
97+ . then ( st . write )
98+ . then ( base => res . send ( store . state . baseCfg ) )
9699} ) ;
97100
98101/* VERSION */
@@ -129,9 +132,14 @@ app.get('/version/:screen', function (req, res) {
129132 ul :req . headers [ 'accept-language' ] . split ( ',' ) [ 0 ] ,
130133 } ) . send ( )
131134 )
132- Promise . all ( [ pio . isPIO ( ) . catch ( ( ) => false ) , git . root ( ) , pioRoot ( ) . then ( pioEnv ) . catch ( e => [ ] ) ] )
133- . then ( pp => {
134- var cfg = { pio : pp [ 0 ] , version : pjson . version , root : pp [ 1 ] , base : store . vars . baseCfg , env : pp [ 2 ] } ;
135+ Promise . all ( [
136+ pio . isPIO ( ) . catch ( ( ) => false ) ,
137+ git . root ( ) ,
138+ pioRoot ( ) . then ( pioEnv ) . catch ( e => [ ] ) ,
139+ st . read ( ) ,
140+ ] )
141+ . then ( ( [ pio , root , env ] ) => {
142+ var cfg = { pio, version : pjson . version , root, base : store . state . baseCfg , env} ;
135143 res . set ( 'Content-Type' , 'application/javascript' ) . send ( "var config = " + JSON . stringify ( cfg ) ) ;
136144 } )
137145} ) ;
0 commit comments