Skip to content

Email for professionals and teams

feat: profile picture upload for users

Dinesh-30186d835219d226
diff --git a/drizzle/migrations/0010_hard_squirrel_girl.sql b/drizzle/migrations/0010_hard_squirrel_girl.sql
new file mode 100644
index 0000000..93bd877
--- /dev/null
+++ b/drizzle/migrations/0010_hard_squirrel_girl.sql
@@ -0,0 +1 @@
+ALTER TABLE `users` ADD `avatar_key` text;
diff --git a/drizzle/migrations/meta/0010_snapshot.json b/drizzle/migrations/meta/0010_snapshot.json
new file mode 100644
index 0000000..f991521
--- /dev/null
+++ b/drizzle/migrations/meta/0010_snapshot.json
@@ -0,0 +1,1852 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "4c74f4c9-1553-4cf7-823a-1fba2913c1f2",
+ "prevId": "f58cce61-805b-480c-8fcc-0afd19982514",
+ "tables": {
+ "api_keys": {
+ "name": "api_keys",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "prefix": {
+ "name": "prefix",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "key_hash": {
+ "name": "key_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "scopes": {
+ "name": "scopes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_used_at": {
+ "name": "last_used_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "api_keys_user_id_users_id_fk": {
+ "name": "api_keys_user_id_users_id_fk",
+ "tableFrom": "api_keys",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "audit_logs": {
+ "name": "audit_logs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "actor_user_id": {
+ "name": "actor_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "target_user_id": {
+ "name": "target_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "mailbox_id": {
+ "name": "mailbox_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "message_id": {
+ "name": "message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "action": {
+ "name": "action",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "audit_logs_actor_idx": {
+ "name": "audit_logs_actor_idx",
+ "columns": [
+ "actor_user_id"
+ ],
+ "isUnique": false
+ },
+ "audit_logs_mailbox_idx": {
+ "name": "audit_logs_mailbox_idx",
+ "columns": [
+ "mailbox_id"
+ ],
+ "isUnique": false
+ },
+ "audit_logs_created_idx": {
+ "name": "audit_logs_created_idx",
+ "columns": [
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "audit_logs_actor_user_id_users_id_fk": {
+ "name": "audit_logs_actor_user_id_users_id_fk",
+ "tableFrom": "audit_logs",
+ "tableTo": "users",
+ "columnsFrom": [
+ "actor_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "audit_logs_target_user_id_users_id_fk": {
+ "name": "audit_logs_target_user_id_users_id_fk",
+ "tableFrom": "audit_logs",
+ "tableTo": "users",
+ "columnsFrom": [
+ "target_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "audit_logs_mailbox_id_mailboxes_id_fk": {
+ "name": "audit_logs_mailbox_id_mailboxes_id_fk",
+ "tableFrom": "audit_logs",
+ "tableTo": "mailboxes",
+ "columnsFrom": [
+ "mailbox_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "audit_logs_message_id_messages_id_fk": {
+ "name": "audit_logs_message_id_messages_id_fk",
+ "tableFrom": "audit_logs",
+ "tableTo": "messages",
+ "columnsFrom": [
+ "message_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "backup_settings": {
+ "name": "backup_settings",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "enabled": {
+ "name": "enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "schedule_type": {
+ "name": "schedule_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'daily'"
+ },
+ "schedule_value": {
+ "name": "schedule_value",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "retention_enabled": {
+ "name": "retention_enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "retention_days": {
+ "name": "retention_days",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 30
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "backups": {
+ "name": "backups",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'queued'"
+ },
+ "trigger": {
+ "name": "trigger",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "r2_key": {
+ "name": "r2_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "filename": {
+ "name": "filename",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "size": {
+ "name": "size",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "error": {
+ "name": "error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_by_user_id": {
+ "name": "created_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "started_at": {
+ "name": "started_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "completed_at": {
+ "name": "completed_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "backups_created_idx": {
+ "name": "backups_created_idx",
+ "columns": [
+ "created_at"
+ ],
+ "isUnique": false
+ },
+ "backups_status_idx": {
+ "name": "backups_status_idx",
+ "columns": [
+ "status"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "backups_created_by_user_id_users_id_fk": {
+ "name": "backups_created_by_user_id_users_id_fk",
+ "tableFrom": "backups",
+ "tableTo": "users",
+ "columnsFrom": [
+ "created_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "contacts": {
+ "name": "contacts",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "display_name": {
+ "name": "display_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'inbound'"
+ },
+ "last_seen_at": {
+ "name": "last_seen_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "contacts_user_email_idx": {
+ "name": "contacts_user_email_idx",
+ "columns": [
+ "user_id",
+ "email"
+ ],
+ "isUnique": true
+ },
+ "contacts_user_idx": {
+ "name": "contacts_user_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "contacts_user_id_users_id_fk": {
+ "name": "contacts_user_id_users_id_fk",
+ "tableFrom": "contacts",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "domains": {
+ "name": "domains",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "hostname": {
+ "name": "hostname",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "zone_id": {
+ "name": "zone_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "routing_status": {
+ "name": "routing_status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "sending_subdomain_tag": {
+ "name": "sending_subdomain_tag",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "sending_enabled": {
+ "name": "sending_enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "routing_enabled": {
+ "name": "routing_enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "domains_hostname_idx": {
+ "name": "domains_hostname_idx",
+ "columns": [
+ "hostname"
+ ],
+ "isUnique": true
+ },
+ "domains_user_idx": {
+ "name": "domains_user_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "domains_user_id_users_id_fk": {
+ "name": "domains_user_id_users_id_fk",
+ "tableFrom": "domains",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "folders": {
+ "name": "folders",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mailbox_id": {
+ "name": "mailbox_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "folders_mailbox_name_idx": {
+ "name": "folders_mailbox_name_idx",
+ "columns": [
+ "mailbox_id",
+ "name"
+ ],
+ "isUnique": true
+ },
+ "folders_user_idx": {
+ "name": "folders_user_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ },
+ "folders_mailbox_idx": {
+ "name": "folders_mailbox_idx",
+ "columns": [
+ "mailbox_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "folders_user_id_users_id_fk": {
+ "name": "folders_user_id_users_id_fk",
+ "tableFrom": "folders",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "folders_mailbox_id_mailboxes_id_fk": {
+ "name": "folders_mailbox_id_mailboxes_id_fk",
+ "tableFrom": "folders",
+ "tableTo": "mailboxes",
+ "columnsFrom": [
+ "mailbox_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "mailbox_access": {
+ "name": "mailbox_access",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mailbox_id": {
+ "name": "mailbox_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "permission": {
+ "name": "permission",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'read_only'"
+ },
+ "created_by_user_id": {
+ "name": "created_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "mailbox_access_mailbox_user_idx": {
+ "name": "mailbox_access_mailbox_user_idx",
+ "columns": [
+ "mailbox_id",
+ "user_id"
+ ],
+ "isUnique": true
+ },
+ "mailbox_access_user_idx": {
+ "name": "mailbox_access_user_idx",
+ "columns": [
+ "user_id"
+ ],
+ "isUnique": false
+ },
+ "mailbox_access_mailbox_idx": {
+ "name": "mailbox_access_mailbox_idx",
+ "columns": [
+ "mailbox_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "mailbox_access_mailbox_id_mailboxes_id_fk": {
+ "name": "mailbox_access_mailbox_id_mailboxes_id_fk",
+ "tableFrom": "mailbox_access",
+ "tableTo": "mailboxes",
+ "columnsFrom": [
+ "mailbox_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "mailbox_access_user_id_users_id_fk": {
+ "name": "mailbox_access_user_id_users_id_fk",
+ "tableFrom": "mailbox_access",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "mailbox_access_created_by_user_id_users_id_fk": {
+ "name": "mailbox_access_created_by_user_id_users_id_fk",
+ "tableFrom": "mailbox_access",
+ "tableTo": "users",
+ "columnsFrom": [
+ "created_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "mailboxes": {
+ "name": "mailboxes",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "domain_id": {
+ "name": "domain_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "local_part": {
+ "name": "local_part",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "display_name": {
+ "name": "display_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'personal'"
+ },
+ "disabled": {
+ "name": "disabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "mailboxes_address_idx": {
+ "name": "mailboxes_address_idx",
+ "columns": [
+ "domain_id",
+ "local_part"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "mailboxes_user_id_users_id_fk": {
+ "name": "mailboxes_user_id_users_id_fk",
+ "tableFrom": "mailboxes",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "mailboxes_domain_id_domains_id_fk": {
+ "name": "mailboxes_domain_id_domains_id_fk",
+ "tableFrom": "mailboxes",
+ "tableTo": "domains",
+ "columnsFrom": [
+ "domain_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "message_attachments": {
+ "name": "message_attachments",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message_id": {
+ "name": "message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "filename": {
+ "name": "filename",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "content_type": {
+ "name": "content_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "size": {
+ "name": "size",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "disposition": {
+ "name": "disposition",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'attachment'"
+ },
+ "content_id": {
+ "name": "content_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "r2_key": {
+ "name": "r2_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "message_attachments_r2_key_unique": {
+ "name": "message_attachments_r2_key_unique",
+ "columns": [
+ "r2_key"
+ ],
+ "isUnique": true
+ },
+ "message_attachments_message_idx": {
+ "name": "message_attachments_message_idx",
+ "columns": [
+ "message_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "message_attachments_message_id_messages_id_fk": {
+ "name": "message_attachments_message_id_messages_id_fk",
+ "tableFrom": "message_attachments",
+ "tableTo": "messages",
+ "columnsFrom": [
+ "message_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "message_bodies": {
+ "name": "message_bodies",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message_id": {
+ "name": "message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "text_body": {
+ "name": "text_body",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "html_body": {
+ "name": "html_body",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "raw_r2_key": {
+ "name": "raw_r2_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "message_bodies_message_id_unique": {
+ "name": "message_bodies_message_id_unique",
+ "columns": [
+ "message_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "message_bodies_message_id_messages_id_fk": {
+ "name": "message_bodies_message_id_messages_id_fk",
+ "tableFrom": "message_bodies",
+ "tableTo": "messages",
+ "columnsFrom": [
+ "message_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "messages": {
+ "name": "messages",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mailbox_id": {
+ "name": "mailbox_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "direction": {
+ "name": "direction",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider_message_id": {
+ "name": "provider_message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "folder_id": {
+ "name": "folder_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "from_addr": {
+ "name": "from_addr",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "to_addr": {
+ "name": "to_addr",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "subject": {
+ "name": "subject",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "snippet": {
+ "name": "snippet",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'received'"
+ },
+ "read": {
+ "name": "read",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "thread_id": {
+ "name": "thread_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "messages_user_created_idx": {
+ "name": "messages_user_created_idx",
+ "columns": [
+ "user_id",
+ "created_at"
+ ],
+ "isUnique": false
+ },
+ "messages_mailbox_idx": {
+ "name": "messages_mailbox_idx",
+ "columns": [
+ "mailbox_id"
+ ],
+ "isUnique": false
+ },
+ "messages_folder_idx": {
+ "name": "messages_folder_idx",
+ "columns": [
+ "folder_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "messages_user_id_users_id_fk": {
+ "name": "messages_user_id_users_id_fk",
+ "tableFrom": "messages",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "messages_mailbox_id_mailboxes_id_fk": {
+ "name": "messages_mailbox_id_mailboxes_id_fk",
+ "tableFrom": "messages",
+ "tableTo": "mailboxes",
+ "columnsFrom": [
+ "mailbox_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "messages_folder_id_folders_id_fk": {
+ "name": "messages_folder_id_folders_id_fk",
+ "tableFrom": "messages",
+ "tableTo": "folders",
+ "columnsFrom": [
+ "folder_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "outbound_jobs": {
+ "name": "outbound_jobs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message_id": {
+ "name": "message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'queued'"
+ },
+ "payload": {
+ "name": "payload",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "error": {
+ "name": "error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "outbound_jobs_user_id_users_id_fk": {
+ "name": "outbound_jobs_user_id_users_id_fk",
+ "tableFrom": "outbound_jobs",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "outbound_jobs_message_id_messages_id_fk": {
+ "name": "outbound_jobs_message_id_messages_id_fk",
+ "tableFrom": "outbound_jobs",
+ "tableTo": "messages",
+ "columnsFrom": [
+ "message_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "routing_rules": {
+ "name": "routing_rules",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "domain_id": {
+ "name": "domain_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "pattern": {
+ "name": "pattern",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "match_field": {
+ "name": "match_field",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'email'"
+ },
+ "match_operator": {
+ "name": "match_operator",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'contains'"
+ },
+ "match_value": {
+ "name": "match_value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "mailbox_id": {
+ "name": "mailbox_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "folder_id": {
+ "name": "folder_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "action": {
+ "name": "action",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'store'"
+ },
+ "forward_to": {
+ "name": "forward_to",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "priority": {
+ "name": "priority",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "routing_rules_user_id_users_id_fk": {
+ "name": "routing_rules_user_id_users_id_fk",
+ "tableFrom": "routing_rules",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "routing_rules_domain_id_domains_id_fk": {
+ "name": "routing_rules_domain_id_domains_id_fk",
+ "tableFrom": "routing_rules",
+ "tableTo": "domains",
+ "columnsFrom": [
+ "domain_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "routing_rules_mailbox_id_mailboxes_id_fk": {
+ "name": "routing_rules_mailbox_id_mailboxes_id_fk",
+ "tableFrom": "routing_rules",
+ "tableTo": "mailboxes",
+ "columnsFrom": [
+ "mailbox_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "routing_rules_folder_id_folders_id_fk": {
+ "name": "routing_rules_folder_id_folders_id_fk",
+ "tableFrom": "routing_rules",
+ "tableTo": "folders",
+ "columnsFrom": [
+ "folder_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "sessions": {
+ "name": "sessions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "token_hash": {
+ "name": "token_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "sessions_token_hash_unique": {
+ "name": "sessions_token_hash_unique",
+ "columns": [
+ "token_hash"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "sessions_user_id_users_id_fk": {
+ "name": "sessions_user_id_users_id_fk",
+ "tableFrom": "sessions",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "users": {
+ "name": "users",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "reset_email": {
+ "name": "reset_email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "password_hash": {
+ "name": "password_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "avatar_key": {
+ "name": "avatar_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'user'"
+ },
+ "disabled": {
+ "name": "disabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_by_user_id": {
+ "name": "created_by_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "users_email_unique": {
+ "name": "users_email_unique",
+ "columns": [
+ "email"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "users_created_by_user_id_users_id_fk": {
+ "name": "users_created_by_user_id_users_id_fk",
+ "tableFrom": "users",
+ "tableTo": "users",
+ "columnsFrom": [
+ "created_by_user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "webhook_deliveries": {
+ "name": "webhook_deliveries",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "webhook_id": {
+ "name": "webhook_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "event_type": {
+ "name": "event_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "payload": {
+ "name": "payload",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "webhook_deliveries_webhook_id_webhooks_id_fk": {
+ "name": "webhook_deliveries_webhook_id_webhooks_id_fk",
+ "tableFrom": "webhook_deliveries",
+ "tableTo": "webhooks",
+ "columnsFrom": [
+ "webhook_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "webhooks": {
+ "name": "webhooks",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "secret": {
+ "name": "secret",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "events": {
+ "name": "events",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "enabled": {
+ "name": "enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "webhooks_user_id_users_id_fk": {
+ "name": "webhooks_user_id_users_id_fk",
+ "tableFrom": "webhooks",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ }
+ },
+ "views": {},
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "indexes": {}
+ }
+}
\ No newline at end of file
diff --git a/drizzle/migrations/meta/_journal.json b/drizzle/migrations/meta/_journal.json
index e3f652c..801ce47 100644
--- a/drizzle/migrations/meta/_journal.json
+++ b/drizzle/migrations/meta/_journal.json
@@ -71,6 +71,13 @@
"when": 1781312400000,
"tag": "0009_add_backups",
"breakpoints": true
+ },
+ {
+ "idx": 10,
+ "version": "6",
+ "when": 1784285031058,
+ "tag": "0010_hard_squirrel_girl",
+ "breakpoints": true
}
]
-}
+}
\ No newline at end of file
diff --git a/src/app/(dashboard)/settings/page.tsx b/src/app/(dashboard)/settings/page.tsx
index b29a159..46b8058 100644
--- a/src/app/(dashboard)/settings/page.tsx
+++ b/src/app/(dashboard)/settings/page.tsx
@@ -1,5 +1,13 @@
import { CurrentMailboxForm } from "@/components/settings/current-mailbox-form";
+import { ProfileAvatarForm } from "@/components/settings/profile-avatar-form";
export default function SettingsPage() {
- return <CurrentMailboxForm />;
+ return (
+ <div className="space-y-6">
+ <CurrentMailboxForm />
+ <div className="max-w-2xl px-8 pb-8">
+ <ProfileAvatarForm />
+ </div>
+ </div>
+ );
}
diff --git a/src/app/api/auth/me/route.ts b/src/app/api/auth/me/route.ts
index a91b43e..b9f66a5 100644
--- a/src/app/api/auth/me/route.ts
+++ b/src/app/api/auth/me/route.ts
@@ -18,6 +18,7 @@ export async function GET(request: Request) {
name: user.name,
resetEmail: user.resetEmail,
role: user.role,
+ hasAvatar: !!user.avatarKey,
},
hasMailboxes,
});
diff --git a/src/app/api/profile/avatar/route.ts b/src/app/api/profile/avatar/route.ts
new file mode 100644
index 0000000..ccfd220
--- /dev/null
+++ b/src/app/api/profile/avatar/route.ts
@@ -0,0 +1,76 @@
+import { NextResponse } from "next/server";
+import { eq } from "drizzle-orm";
+import { getDb } from "@/db";
+import { users } from "@/db/schema";
+import { getCurrentUser } from "@/lib/auth/cookies";
+import { getEnv } from "@/lib/cloudflare";
+
+const MAX_AVATAR_SIZE = 2 * 1024 * 1024;
+const ALLOWED_TYPES = ["image/jpeg", "image/png", "image/webp", "image/gif"];
+
+function avatarKeyFor(userId: string) {
+ return `avatars/${userId}`;
+}
+
+export async function GET(request: Request) {
+ const env = getEnv();
+ const user = await getCurrentUser(env, request);
+ if (!user) return new Response("Unauthorized", { status: 401 });
+ if (!user.avatarKey) return new Response("Not found", { status: 404 });
+
+ const object = await env.BUCKET.get(user.avatarKey);
+ if (!object) return new Response("Not found", { status: 404 });
+
+ const headers = new Headers();
+ object.writeHttpMetadata(headers);
+ headers.set("X-Content-Type-Options", "nosniff");
+ headers.set(
+ "Content-Security-Policy",
+ "default-src 'none'; img-src 'self'; sandbox",
+ );
+ headers.set("Cache-Control", "private, no-cache");
+ return new Response(object.body, { headers });
+}
+
+export async function POST(request: Request) {
+ const env = getEnv();
+ const user = await getCurrentUser(env, request);
+ if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
+
+ let form: FormData;
+ try {
+ form = await request.formData();
+ } catch {
+ return NextResponse.json({ error: "Expected multipart form data" }, { status: 400 });
+ }
+ const file = form.get("file");
+ if (!(file instanceof File)) {
+ return NextResponse.json({ error: "Missing image file" }, { status: 400 });
+ }
+ if (!ALLOWED_TYPES.includes(file.type)) {
+ return NextResponse.json({ error: "Use a JPEG, PNG, WebP, or GIF image" }, { status: 400 });
+ }
+ if (file.size > MAX_AVATAR_SIZE) {
+ return NextResponse.json({ error: "Image must be 2 MB or smaller" }, { status: 413 });
+ }
+
+ const key = avatarKeyFor(user.id);
+ await env.BUCKET.put(key, await file.arrayBuffer(), {
+ httpMetadata: { contentType: file.type },
+ });
+ await getDb(env).update(users).set({ avatarKey: key }).where(eq(users.id, user.id));
+
+ return NextResponse.json({ ok: true });
+}
+
+export async function DELETE(request: Request) {
+ const env = getEnv();
+ const user = await getCurrentUser(env, request);
+ if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
+
+ if (user.avatarKey) {
+ await env.BUCKET.delete(user.avatarKey);
+ await getDb(env).update(users).set({ avatarKey: null }).where(eq(users.id, user.id));
+ }
+ return NextResponse.json({ ok: true });
+}
diff --git a/src/components/mailbox-selector.tsx b/src/components/mailbox-selector.tsx
index fef780b..e3d7ae7 100644
--- a/src/components/mailbox-selector.tsx
+++ b/src/components/mailbox-selector.tsx
@@ -18,6 +18,7 @@ export function MailboxSelector() {
const router = useRouter();
const [open, setOpen] = useState(false);
const [isAdmin, setIsAdmin] = useState(false);
+ const [hasAvatar, setHasAvatar] = useState(false);
const ref = useRef<HTMLDivElement>(null);
const { counts } = useMessageCounts(null, open);
@@ -34,8 +35,9 @@ export function MailboxSelector() {
authFetch("/api/auth/me", { redirectOnUnauthorized: false })
.then((response) => response.ok ? response.json() : null)
.then((data) => {
- const authData = data as { user?: { role?: string } } | null;
+ const authData = data as { user?: { role?: string; hasAvatar?: boolean } } | null;
setIsAdmin(authData?.user?.role === "admin");
+ setHasAvatar(!!authData?.user?.hasAvatar);
})
.catch(() => setIsAdmin(false));
}, []);
@@ -82,9 +84,19 @@ export function MailboxSelector() {
<p className="truncate text-sm font-medium text-neutral-800">{selectedName}</p>
<p className="truncate text-[11px] text-neutral-500">{selectedEmail}</p>
</div>
- <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-blue-600 text-white">
- <Mail className="h-4 w-4" />
- </div>
+ {hasAvatar ? (
+ // eslint-disable-next-line @next/next/no-img-element
+ <img
+ src="/api/profile/avatar"
+ alt="Profile"
+ className="h-8 w-8 shrink-0 rounded-full object-cover"
+ onError={() => setHasAvatar(false)}
+ />
+ ) : (
+ <div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-blue-600 text-white">
+ <Mail className="h-4 w-4" />
+ </div>
+ )}
</div>
{/* <ChevronDown className="h-4 w-4 shrink-0 text-neutral-500" /> */}
</button>
diff --git a/src/components/settings/profile-avatar-form.tsx b/src/components/settings/profile-avatar-form.tsx
new file mode 100644
index 0000000..9ae71f6
--- /dev/null
+++ b/src/components/settings/profile-avatar-form.tsx
@@ -0,0 +1,130 @@
+"use client";
+
+import { useEffect, useRef, useState } from "react";
+import { Trash2, Upload, User } from "lucide-react";
+import { Button } from "@/components/ui/button";
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
+import { authFetch } from "@/lib/auth/client";
+
+export function ProfileAvatarForm() {
+ const [hasAvatar, setHasAvatar] = useState(false);
+ const [preview, setPreview] = useState<string | null>(null);
+ const [file, setFile] = useState<File | null>(null);
+ const [status, setStatus] = useState<string | null>(null);
+ const [busy, setBusy] = useState(false);
+ const inputRef = useRef<HTMLInputElement>(null);
+
+ useEffect(() => {
+ authFetch("/api/auth/me", { redirectOnUnauthorized: false })
+ .then((response) => (response.ok ? response.json() : null))
+ .then((data) => {
+ const authData = data as { user?: { hasAvatar?: boolean } } | null;
+ setHasAvatar(!!authData?.user?.hasAvatar);
+ })
+ .catch(() => setHasAvatar(false));
+ }, []);
+
+ useEffect(() => {
+ if (!file) {
+ setPreview(null);
+ return;
+ }
+ const url = URL.createObjectURL(file);
+ setPreview(url);
+ return () => URL.revokeObjectURL(url);
+ }, [file]);
+
+ function onPick(event: React.ChangeEvent<HTMLInputElement>) {
+ const picked = event.target.files?.[0] ?? null;
+ setStatus(null);
+ if (picked && picked.size > 2 * 1024 * 1024) {
+ setStatus("Image must be 2 MB or smaller");
+ return;
+ }
+ setFile(picked);
+ }
+
+ async function upload() {
+ if (!file) return;
+ setBusy(true);
+ setStatus(null);
+ try {
+ const body = new FormData();
+ body.append("file", file);
+ const response = await authFetch("/api/profile/avatar", { method: "POST", body });
+ if (!response.ok) {
+ const json = (await response.json().catch(() => null)) as { error?: string } | null;
+ throw new Error(json?.error ?? "Upload failed");
+ }
+ window.location.reload();
+ } catch (err) {
+ setStatus(err instanceof Error ? err.message : "Upload failed");
+ setBusy(false);
+ }
+ }
+
+ async function remove() {
+ setBusy(true);
+ setStatus(null);
+ try {
+ const response = await authFetch("/api/profile/avatar", { method: "DELETE" });
+ if (!response.ok) throw new Error("Failed to remove picture");
+ window.location.reload();
+ } catch (err) {
+ setStatus(err instanceof Error ? err.message : "Failed to remove picture");
+ setBusy(false);
+ }
+ }
+
+ const shownImage = preview ?? (hasAvatar ? "/api/profile/avatar" : null);
+
+ return (
+ <Card>
+ <CardHeader>
+ <CardTitle>Profile picture</CardTitle>
+ <CardDescription>
+ Shown in the top-right corner of your dashboard. JPEG, PNG, WebP, or GIF up to 2 MB.
+ </CardDescription>
+ </CardHeader>
+ <CardContent className="space-y-4">
+ <div className="flex items-center gap-4">
+ {shownImage ? (
+ // eslint-disable-next-line @next/next/no-img-element
+ <img
+ src={shownImage}
+ alt="Profile picture"
+ className="h-16 w-16 rounded-full border border-neutral-200 object-cover"
+ />
+ ) : (
+ <div className="flex h-16 w-16 items-center justify-center rounded-full bg-blue-600 text-white">
+ <User className="h-7 w-7" />
+ </div>
+ )}
+ <div className="flex flex-wrap items-center gap-2">
+ <input
+ ref={inputRef}
+ type="file"
+ accept="image/jpeg,image/png,image/webp,image/gif"
+ className="hidden"
+ onChange={onPick}
+ />
+ <Button type="button" variant="outline" onClick={() => inputRef.current?.click()} disabled={busy}>
+ Choose image
+ </Button>
+ <Button type="button" onClick={upload} disabled={busy || !file}>
+ <Upload className="h-4 w-4" />
+ {busy ? "Saving..." : "Save picture"}
+ </Button>
+ {hasAvatar && (
+ <Button type="button" variant="destructive" onClick={remove} disabled={busy}>
+ <Trash2 className="h-4 w-4" />
+ Remove
+ </Button>
+ )}
+ </div>
+ </div>
+ {status && <p className="text-sm text-red-600">{status}</p>}
+ </CardContent>
+ </Card>
+ );
+}
diff --git a/src/db/schema/index.ts b/src/db/schema/index.ts
index 2b06243..5999d54 100644
--- a/src/db/schema/index.ts
+++ b/src/db/schema/index.ts
@@ -7,6 +7,7 @@ export const users = sqliteTable("users", {
resetEmail: text("reset_email"),
passwordHash: text("password_hash").notNull(),
name: text("name").notNull(),
+ avatarKey: text("avatar_key"),
role: text("role", { enum: ["admin", "user"] }).notNull().default("user"),
disabled: integer("disabled", { mode: "boolean" }).notNull().default(false),
createdByUserId: text("created_by_user_id").references((): AnySQLiteColumn => users.id, { onDelete: "set null" }),