// Uploaded avatars for accounts (for now, organizations set one in their settings; see lib/orgs.ts).
// Like a repository's image: one raster file, protected so only the server reads it, with its type
// and upload time (avatar_updated_at, which busts caches) beside it.
const MIME_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"];
migrate(
(app) => {
const users = app.findCollectionByNameOrId("users");
// PocketBase's default users collection comes with an open "avatar" field that takes SVGs.
const avatar = users.fields.getByName("avatar");
if (avatar) {
avatar.maxSelect = 1;
avatar.maxSize = 1024 * 1024;
avatar.mimeTypes = MIME_TYPES;
avatar.thumbs = [];
avatar.protected = true;
} else {
users.fields.add(new FileField({ name: "avatar", maxSelect: 1, maxSize: 1024 * 1024, mimeTypes: MIME_TYPES, protected: true }));
}
users.fields.add(new TextField({ name: "avatar_type", max: 20 }));
users.fields.add(new NumberField({ name: "avatar_updated_at", onlyInt: true, min: 0 }));
app.save(users);
},
(app) => {
const users = app.findCollectionByNameOrId("users");
for (const name of ["avatar_type", "avatar_updated_at"]) users.fields.removeByName(name);
app.save(users);
},
);