// Uploaded photos published without where they were taken: checked, stripped, checked again.
//
//   quillo run exif_strip.qwe      then open http://localhost:8080/publish

use "exif_strip.qwer"

route GET /publish {
    let before = exif_strip_check("exif_strip_sample.jpg")?
    let sizes = exif_strip("exif_strip_sample.jpg", "data/public/photo.jpg")?
    { before, sizes, after: exif_strip_check("data/public/photo.jpg")? }
}

route GET /photo.jpg {
    exif_strip("exif_strip_sample.jpg", "data/public/photo.jpg")?
    file("data/public/photo.jpg")
}

route POST /upload {
    let f = request.files.photo ?? reply 400 "Choose a photo"
    let raw = save_upload(f, `data/incoming/${uuid()}`)?
    let public = `data/public/${uuid()}.jpg`
    let r = exif_strip(raw, public)
    delete_file(raw)
    if is_err(r) { reply 415 "JPEG, PNG or WebP photos only" }
    { url: `/${public}`, removed_bytes: r.removed }
}
