Comment on No JS, No CSS, No HTML: online "clubs" celebrate plainer websites

<- View Parent
raldone01@lemmy.world ⁨3⁩ ⁨days⁩ ago

I used this script:

import Axios from 'axios'
import OldFS from 'fs'
import { PromiseChain } from '@feather-ink/ts-utils'

const fs = OldFS.promises

const image = process.argv[2]
const destination = `http://${process.argv[3]}/vfs/ota`
const now = process.argv[4] === 'now'
const once = process.argv[4] === 'once'

async function triggerUpdate(): Promise<void> {
  console.log('Uploading new binary')
  const file = await fs.readFile(image)

  await Axios({
    method: 'POST',
    url: destination,
    headers: {
      'Content-Type': 'application/octet-stream',
      'Content-Length': file.byteLength
    },
    data: file
  })
  console.log('Finished uploading')
}

(async () => {
  const updateChain = new PromiseChain()
  console.log(`Watching file '${image}' for changes\nWill upload to '${destination}'!`)
  if (once) {
    await triggerUpdate()
    return
  }
  if (now)
    await updateChain.enqueue(triggerUpdate)
  OldFS.watch(image, async (eventType) => {
    if (eventType !== 'change')
      return
    let succ = false
    do {
      try {
        console.log('Change detected')
        await updateChain.enqueue(triggerUpdate)
        succ = true
      } catch (e) {
        console.error(e)
        console.log('Retrying upload')
      }
    } while (!succ)
    console.log('Upload finished')
  })
})()

source
Sort:hotnewtop