@@ -19,6 +19,7 @@ import {
1919import { overwriteConfigData } from '@shared/config/util' ;
2020import {
2121 CURATIONS_FOLDER_EXPORTED ,
22+ CURATIONS_FOLDER_TEMPLATES ,
2223 CURATIONS_FOLDER_WORKING ,
2324 LOGOS ,
2425 SCREENSHOTS ,
@@ -189,7 +190,6 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
189190 state . socketServer . register ( BackIn . GET_RENDERER_EXTENSION_INFO , async ( ) => {
190191 return {
191192 contextButtons : await state . extensionsService . getEnabledContributions ( 'contextButtons' , state . preferences . disabledExtensions ) ,
192- curationTemplates : await state . extensionsService . getEnabledContributions ( 'curationTemplates' , state . preferences . disabledExtensions ) ,
193193 extConfigs : await state . extensionsService . getEnabledContributions ( 'configuration' , state . preferences . disabledExtensions ) ,
194194 extConfig : state . extConfig ,
195195 extensions : ( await state . extensionsService . getExtensions ( ) ) . map ( e => {
@@ -2200,8 +2200,11 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
22002200 return result ;
22012201 } ) ;
22022202
2203- state . socketServer . register ( BackIn . CURATE_LOAD_ARCHIVES , async ( event , filePaths , taskId ) => {
2203+ state . socketServer . register ( BackIn . CURATE_LOAD_ARCHIVES , async ( event , filePaths , isTemplate , taskId ) => {
22042204 let processed = 0 ;
2205+ if ( isTemplate ) {
2206+ filePaths = filePaths . map ( f => path . join ( state . config . flashpointPath , CURATIONS_FOLDER_TEMPLATES , f ) ) ;
2207+ }
22052208 const taskProgress = new TaskProgress ( filePaths . length ) ;
22062209 if ( taskId ) {
22072210 taskProgress . on ( 'progress' , ( text , done ) => {
@@ -2223,7 +2226,7 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
22232226 for ( const filePath of filePaths ) {
22242227 processed = processed + 1 ;
22252228 taskProgress . setStage ( processed , `Loading ${ filePath } ` ) ;
2226- await loadCurationArchive ( filePath , null , throttle ( ( progress : Progress ) => {
2229+ await loadCurationArchive ( filePath , ! ! isTemplate , undefined , throttle ( ( progress : Progress ) => {
22272230 taskProgress . setStageProgress ( ( progress . percent / 100 ) , `Extracting Files - ${ progress . fileCount } ` ) ;
22282231 } , 200 ) )
22292232 . catch ( ( error ) => {
@@ -2239,6 +2242,10 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
22392242 return genCurationWarnings ( curation , state . config . flashpointPath , state . suggestions , state . languageContainer . curate , state . apiEmitters . curations . onWillGenCurationWarnings ) ;
22402243 } ) ;
22412244
2245+ state . socketServer . register ( BackIn . CURATE_GET_TEMPLATES , ( ) => {
2246+ return state . curationTemplates ;
2247+ } ) ;
2248+
22422249 state . socketServer . register ( BackIn . CURATE_GET_LIST , async ( ) => {
22432250 if ( state . curationsReady ) {
22442251 return state . loadedCurations ;
@@ -2415,7 +2422,6 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
24152422 await fs . ensureDir ( curationsPath ) ;
24162423 const curations = await fs . promises . readdir ( curationsPath , { withFileTypes : true } ) ;
24172424 for ( const curation of curations ) {
2418- console . log ( curation . name ) ;
24192425 if ( curation . isDirectory ( ) ) {
24202426 const exists = state . loadedCurations . find ( c => c . folder === curation . name ) ;
24212427 if ( ! exists ) {
@@ -2475,6 +2481,44 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
24752481 }
24762482 } ) ;
24772483
2484+ state . socketServer . register ( BackIn . CURATE_CREATE_TEMPLATE_FROM_CURATION , async ( event , folder , name ) => {
2485+ const curation = state . loadedCurations . find ( c => c . folder === folder ) ;
2486+ if ( curation ) {
2487+ let filename = `${ sanitizeFilename ( name ) } .7z` ;
2488+ const templateFolder = path . join ( state . config . flashpointPath , CURATIONS_FOLDER_TEMPLATES ) ;
2489+ let fullPath = path . join ( templateFolder , filename ) ;
2490+
2491+ await fs . ensureDir ( templateFolder ) ;
2492+ // Don't overwrite existing templates
2493+ if ( fs . existsSync ( fullPath ) ) {
2494+ filename = `${ sanitizeFilename ( name ) } -${ Date . now ( ) } .7z` ;
2495+ fullPath = path . join ( templateFolder , filename ) ;
2496+ }
2497+
2498+ // Make sure curation is up to date on disk
2499+ const curPath = path . resolve ( state . config . flashpointPath , CURATIONS_FOLDER_WORKING , curation . folder ) ;
2500+ await saveCuration ( curPath , curation ) ;
2501+ state . socketServer . broadcast ( BackOut . CURATE_SELECT_LOCK , curation . folder , true ) ;
2502+ await new Promise < void > ( ( resolve ) => {
2503+ // Cast required until types fixed
2504+ return ( add as any ) ( fullPath , curPath , { recursive : true , exclude : [ `!${ FPFSS_INFO_FILENAME } ` ] , $bin : pathTo7zBack ( state . isDev , state . isElectron , state . exePath ) } )
2505+ . on ( 'end' , ( ) => { resolve ( ) ; } )
2506+ . on ( 'error' , ( error : any ) => {
2507+ log . error ( 'Curate' , error . message ) ;
2508+ resolve ( ) ;
2509+ } ) ;
2510+ } )
2511+ . finally ( ( ) => {
2512+ state . socketServer . broadcast ( BackOut . CURATE_SELECT_LOCK , curation . folder , false ) ;
2513+ } ) ;
2514+
2515+ state . curationTemplates . push ( filename ) ;
2516+ } else {
2517+ throw new Error ( `No curation found with folder '${ folder } '` ) ;
2518+ }
2519+ state . socketServer . broadcast ( BackOut . CURATE_TEMPLATES_CHANGE , state . curationTemplates ) ;
2520+ } ) ;
2521+
24782522 state . socketServer . register ( BackIn . FPFSS_OPEN_CURATION , async ( event , fpfssInfo , url , accessToken , taskId ) => {
24792523 // Setup task info
24802524 const taskProgress = new TaskProgress ( 2 ) ;
@@ -2509,7 +2553,7 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
25092553
25102554
25112555 taskProgress . setStage ( 2 , `Loading ${ tempFile } ` ) ;
2512- await loadCurationArchive ( tempFile , fpfssInfo , throttle ( ( progress : Progress ) => {
2556+ await loadCurationArchive ( tempFile , false , fpfssInfo , throttle ( ( progress : Progress ) => {
25132557 taskProgress . setStageProgress ( ( progress . percent / 100 ) , `Extracting Files - ${ progress . fileCount } ` ) ;
25142558 } , 200 ) )
25152559 . catch ( ( error ) => {
0 commit comments