自建affine
注意!affine目前的账号系统只能说是半成品,如果自建使用,多用户使用体验会很糟糕
部署
使用下面的docker compose
部署
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 services: affine: image: ghcr.io/toeverything/affine-graphql:stable container_name: affine_selfhosted command: - sh - -c - node ./scripts/self-host-predeploy && node ./dist/index.js ports: - 3010 :3010 - 5555 :5555 depends_on: redis: condition: service_healthy postgres: condition: service_healthy volumes: - /docker/affine/affine/config:/root/.affine/config - /docker/affine/affine/storage:/root/.affine/storage logging: driver: json-file options: max-size: 1000m restart: unless-stopped environment: - NODE_OPTIONS="--import=./scripts/register.js" - AFFINE_CONFIG_PATH=/root/.affine/config - REDIS_SERVER_HOST=redis - DATABASE_URL=postgres://affine:affine@postgres:5432/affine - NODE_ENV=production - AFFINE_ADMIN_EMAIL=${AFFINE_ADMIN_EMAIL} - AFFINE_ADMIN_PASSWORD=${AFFINE_ADMIN_PASSWORD} - AFFINE_SERVER_HOST=xxx.com redis: image: redis container_name: affine_redis restart: unless-stopped volumes: - /docker/affine/redis:/data healthcheck: test: - CMD - redis-cli - --raw - incr - ping interval: 10s timeout: 5s retries: 5 postgres: image: postgres container_name: affine_postgres restart: unless-stopped volumes: - /docker/affine/postgresql:/var/lib/postgresql/data healthcheck: test: - CMD-SHELL - pg_isready -U affine interval: 10s timeout: 5s retries: 5 environment: POSTGRES_USER: affine POSTGRES_PASSWORD: affine POSTGRES_DB: affine PGDATA: /var/lib/postgresql/data/pgdata networks: {}
注意,上面的xxx.com
记得更改成你的域名,affine只有https才会允许你复制粘贴到网页上
如果你自建完成,登录准备编辑后发现一直有个让你开启云同步的红色提示,那么就开启它,没关系的,你并不会自动创建一个云账号担心你的内容被同步上去。实在不放心的话,你就在你的服务器上做一个限制吧。
一定要创建并开启云空间同步,你的笔记才能保存在自建服务器上
设置AI的api
在首次部署时,会自动生成AFFiNE的环境配置文件,默认路径在
1 /docker/affine/affine/config/affine.js
这个文件中往下找,修改这段,记得末尾的括号要前后匹配,不要漏了
1 2 3 4 5 6 7 8 AFFiNE.use('copilot', { openai: { baseURL: 'https://API代理网址/v1', apiKey: '你的Key', }, # 后面的fal api可以不管,如果你只需要对话功能 # 末尾的括号也解开注释 })
解除AI请求限制、创建工作区限制和协作人员数量限制
进入数据库
1 sudo docker exec -it affine_postgres psql -U affine
查询用户与拥有的权限
1 select * from user_features;
返回值类似下面的
1 2 3 4 5 6 7 id | user_id | feature_id | reason | created_at | expired_at | activated ----+--------------------------------------+------------+----------------------+----------------------------+------------+----------- 2 | 9e8cf3cf-6d33-42db-aa5a-2fb347ad17d7 | 7 | Admin user | 2024-10-17 03:01:45.403+00 | | t 3 | 9e8cf3cf-6d33-42db-aa5a-2fb347ad17d7 | 4 | AI request unlimited | 2024-10-17 03:14:53.072+00 | | t 4 | 9e8cf3cf-6d33-42db-aa5a-2fb347ad17d7 | 5 | AI request unlimited | 2024-10-17 03:25:33.177+00 | | t 5 | 9e8cf3cf-6d33-42db-aa5a-2fb347ad17d7 | 16 | AI request unlimited | 2024-10-17 03:25:47.012+00 | | t 6 | 8d40f879-aaa3-46eb-b329-3c63a2f101c6 | 13 | sign up | 2024-10-17 03:49:32.168+00 | | t
其中,user_id记下来,然后让我们给这个用户解除AI请求限制、创建工作区限制和协作人员数量限制
解除各种限制
1 2 3 insert into user_features (id,user_id,feature_id,reason,activated) values (3 ,'8d40f879-aaa3-46eb-b329-3c63a2f101c6' ,4 ,'解除工作区限制' ,'t' );insert into user_features (id,user_id,feature_id,reason,activated) values (3 ,'8d40f879-aaa3-46eb-b329-3c63a2f101c6' ,5 ,'解除AI限制' ,'t' );insert into user_features (id,user_id,feature_id,reason,activated) values (3 ,'8d40f879-aaa3-46eb-b329-3c63a2f101c6' ,16 ,'设置为lifetime_pro_plan' ,'t' );
删除免费计划,下面这个id要看哪个id那行的reason值是sign up
1 DELETE FROM user_features WHERE id = 1 ;
修改成员数
1 update features set configs = '{"name":"Lifetime Pro","blobLimit":104857600,"storageQuota":1099511627776,"historyPeriod":2592000000,"memberLimit":1000,"copilotActionLimit":10}' where id = 16 ;
一切做完后,重启整个PostgreSQL和affine
1 2 sudo docker restart affine_postgres sudo docker restart affine_selfhosted
新用户的注册
要去xxx.com/admin/accounts 添加用户
添加好的用户没有密码,要重置密码,重置之后就能正常登录了
然后再参考上面解除AI请求限制、创建工作区限制和协作人员数量限制的那一步,再来一遍