1+ import asar from 'asar' ;
12import * as sqlite3 from 'better-sqlite3' ;
23import { Buffer } from 'buffer' ;
34import fs from 'fs' ;
@@ -7,6 +8,7 @@ import { getPath } from '../shared/object';
78import { GetProjectRequest , MakeProjectRequest } from '../shared/rpc' ;
89import {
910 ConnectorInfo ,
11+ DatabaseConnectorInfo ,
1012 DatabasePanelInfo ,
1113 doOnEncryptFields ,
1214 Encrypt ,
@@ -185,7 +187,11 @@ export class Store {
185187 const name = f . slice ( 0 , f . length - ( '.' + PROJECT_EXTENSION ) . length ) ;
186188 return { createdAt, name } ;
187189 } ) ;
188- files . sort ( ) ;
190+ // Sort timestamp DESC
191+ files . sort (
192+ ( a , b ) =>
193+ new Date ( b . createdAt ) . valueOf ( ) - new Date ( a . createdAt ) . valueOf ( )
194+ ) ;
189195 return files ;
190196 } ,
191197 } ;
@@ -378,17 +384,56 @@ GROUP BY panel_id
378384 } ,
379385 } ;
380386
387+ // Example: /private/var/folders/l0/51ds3d1d2214wb1y0vbtl5qr0000gn/T/AppTranslocation/6AC58880-BE22-4AB7-8006-47D9764BC590/d/DataStation Desktop CE.app/Contents/Resources/app.asar/sampledata/nginx_logs.jsonl
388+ unmangleAsar ( file : string ) : string {
389+ const asarName = 'app.asar' ;
390+ if ( ! file . includes ( asarName ) ) {
391+ return file ;
392+ }
393+
394+ // Since Go reads from the filesystem it doesn't look into the asar that is used in release builds. So we need to extract it if it doesn't exist.
395+ const [ asarParent , fileName ] = file . split ( asarName ) ;
396+ const asarFile = asarParent + asarName ;
397+ const newFile = path . join ( asarParent , fileName ) ;
398+ // TODO: if these files change then checksum will be needed
399+ if ( ! fs . existsSync ( newFile ) ) {
400+ fs . mkdirSync ( path . dirname ( newFile ) , { recursive : true } ) ;
401+ fs . writeFileSync (
402+ newFile ,
403+ asar . extractFile ( asarFile , fileName . slice ( 1 ) /* drop leading / */ )
404+ ) ;
405+ }
406+
407+ return newFile ;
408+ }
409+
381410 cleanupSampleProject ( sampleProject : ProjectState ) {
382411 for ( const page of sampleProject . pages || [ ] ) {
383412 for ( const panel of page . panels || [ ] ) {
384413 if ( panel . type === 'file' ) {
385414 const fp = panel as FilePanelInfo ;
386415 if ( fp . file . name . startsWith ( 'sampledata' ) ) {
387- fp . file . name = path . join ( CODE_ROOT , fp . file . name ) ;
416+ fp . file . name = this . unmangleAsar (
417+ path . join ( CODE_ROOT , fp . file . name )
418+ ) ;
388419 }
389420 }
390421 }
391422 }
423+
424+ for ( const con of sampleProject . connectors || [ ] ) {
425+ if ( con . type === 'database' ) {
426+ const dc = con as DatabaseConnectorInfo ;
427+ if (
428+ dc . database . type === 'sqlite' &&
429+ dc . database . database . startsWith ( 'sampledata' )
430+ ) {
431+ dc . database . database = this . unmangleAsar (
432+ path . join ( CODE_ROOT , dc . database . database )
433+ ) ;
434+ }
435+ }
436+ }
392437 }
393438
394439 makeProjectHandler : MakeProjectHandler = {
0 commit comments