amber-backend/pb_migrations/1786500001_releases_protect_file.js

26 lines
970 B
JavaScript
Raw Normal View History

/// <reference path="../pb_data/types.d.ts" />
// Fix gating on the releases `file` field (issue #16).
//
// The original migration created the file field without `protected: true`, which
// left the artifact URL PUBLIC — a non-nsfw account (and even an anonymous
// request) could download the adult build, defeating the whole point of the
// gating rules. Protection in PocketBase is a per-field flag, not derived from
// the collection view rule: with it on, the file is served only via a
// short-lived file token whose grant re-checks the view rule.
//
// This alters the field on already-deployed instances; a fresh install gets it
// correct straight from 1786500000.
migrate((app) => {
const c = app.findCollectionByNameOrId("releases")
const f = c.fields.getByName("file")
f.protected = true
app.save(c)
}, (app) => {
const c = app.findCollectionByNameOrId("releases")
const f = c.fields.getByName("file")
f.protected = false
app.save(c)
})