aral,
@aral@mastodon.ar.al avatar

🎉 Got database backup and restore working in Kitten (so every Kitten app gets it for free) and, with the new JSDB 5 support in Kitten, you can now make your model classes EventEmitters.

The session object is now an EventEmitter so you can now listen for events on the current session. In fact, I did just that in Kitten itself to implement the upload of the backup file during the restore process to make the Streaming HTML handler get notified once the POST route has the upload.

Code listing (detail) of index.page.js in Helix Editor: const RestoreStatusUpdate = ({SLOT}) => kitten.html` <${ProgressIndicator} /> ${SLOT}

export function onConnect ({request, page}) { page.on('startRestore', () =&gt; { page.send(kitten.html<${RestoreStatusUpdate}>Uploading backup to restore from…>) }) const restoreDatabases = async (/** @type {Upload} */ upload) =&gt; { console.log('Restore: database backup uploaded', upload) // Show status indicator. page.send(kitten.html<${RestoreStatusUpdate}>Restoring from backup…>) // Delete current databases. const deleteResult = await fs.rm(kitten.databaseDirectory, {recursive: true, force: true}) // Re-create databases directory. const makeDirectoryResult = await fs.mkdir(kitten.databaseDirectory) // Decompress backed-up databases. await extract({ cwd: kitten.databaseDirectory, file: upload.filePath }) // Send refresh header and restart the server so the // restored databases are loaded into memory. page.send(kitten.html<${RestoreStatusUpdate}>Restore complete, waiting for server restart…`) // Restart the server. process.exit(99 /* code for restart request */) } request.session.removeListener('databasesUploadedForRestore', restoreDatabases) request.session.addListener('databasesUploadedForRestore', restoreDatabases)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • SmallWeb
  • kavyap
  • thenastyranch
  • GTA5RPClips
  • tester
  • InstantRegret
  • DreamBathrooms
  • ngwrru68w68
  • magazineikmin
  • everett
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • cisconetworking
  • megavids
  • khanakhh
  • normalnudes
  • osvaldo12
  • cubers
  • tacticalgear
  • Durango
  • ethstaker
  • modclub
  • anitta
  • provamag3
  • Leos
  • JUstTest
  • lostlight
  • All magazines