// Photos uploaded by the browser straight to a Google Cloud Storage bucket, and shown from it.
//
//   GCS_SERVICE_ACCOUNT=key.json GCS_BUCKET=my-photos quillo run gcs_sign.qwe      then open http://localhost:8080/upload-link
//   (gcs_sign_sample.json is a made-up account: its links are well formed, Google would refuse them)

use "gcs_sign.qwer"

let SA = env("GCS_SERVICE_ACCOUNT", "gcs_sign_sample.json")
let BUCKET = env("GCS_BUCKET", "example-photos")

// The page then does: fetch(put, { method: "PUT", headers: { "content-type": "image/jpeg" }, body: file })
route GET /upload-link {
    let key = `photos/${uuid()}.jpg`
    { key, put: gcs_upload_url(SA, BUCKET, key, "image/jpeg", 600, "")?, get: gcs_download_url(SA, BUCKET, key, 3600, "")? }
}

route GET /photo/:name = redirect(gcs_download_url(SA, BUCKET, `photos/${name}`, 300, "")?)

// A fixed time gives the same link each time: what the signature covers is easy to see.
route GET /fixed = { url: gcs_download_url(SA, BUCKET, "reports/2026 Q1.pdf", 900, "20260301T090000Z")? }
