import { ParamValues } from "@resoc/core" ; import { promises as fs } from 'fs' ; export const fileExists = async ( path ) : Promise < boolean > => { try { await fs . access ( path ) ; return true ; } catch ( e ) { return false ; } } ; export type ImageData = { template : string ; values : ParamValues ; } ; export const initImageDateStorage = async ( storagePath ) : Promise < void > => { await fs . writeFile ( storagePath , JSON . stringify ( { } ) ) ; } ; export const storeImageData = async ( storagePath , slug , imageData ) : Promise < void > => { if ( ! await fileExists ( storagePath ) ) { await initImageDateStorage ( storagePath ) ; } const storageContent = await fs . readFile ( storagePath ) ; const storage = JSON . parse ( storageContent . toString ( ) ) ; storage [ slug ] = imageData ; return fs . writeFile ( storagePath , JSON . stringify ( storage ) ) ; } ; export const getImageData = async ( storagePath , slug ) : Promise < ImageData | null > => { const storageContent = await fs . readFile ( storagePath ) ; const storage = JSON . parse ( storageContent . toString ( ) ) ; return storage [ slug ] ; } ;