web_site_id 在创建时,能自定义吗 #4449
Unanswered
AlwaysOnLinees
asked this question in
Q&A
Replies: 1 comment
|
可以,但只能通过 API,界面上没有这个输入框。
const schema = z.object({
name: z.string().trim().min(1).max(100),
domain: z.string().trim().regex(DOMAIN_REGEX).max(500),
shareId: z.string().max(50).nullable().optional(),
teamId: z.uuid().nullable().optional(),
id: z.uuid().nullable().optional(), // ← 这里
});紧接着写入数据库时: id: id ?? uuid(),也就是说传了就用你的,没传才生成新的。所以你完全不需要改前端代码,用原来那个 ID 重建就行。 先登录拿 token: curl -X POST https://<你的域名>/api/auth/login \
-H 'Content-Type: application/json' \
-d '{"username":"admin","password":"<密码>"}'
# => { "token": "...", ... }再带上原来的 ID 建站点: curl -X POST https://<你的域名>/api/websites \
-H "Authorization: Bearer <上一步的 token>" \
-H 'Content-Type: application/json' \
-d '{
"name": "我的站点",
"domain": "example.com",
"id": "<原来的 website id>"
}'两点要注意:
另外这个字段没有做“已存在则报错”的友好处理,重复的 ID 会直接撞到数据库主键约束上。确认旧站点记录确实没了再建,别在同一个库里拿一个还存在的 ID 去创建。 顺带一提,这个方法平时也有用:把 website id 写进部署脚本,在新环境里用固定 ID 建站,前端埋点代码就可以在所有环境保持一致,不用每次搭环境都回头改 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
服务器数据丢了,重新创建时会生成一个新的ID,这时候需要改前端代码,用新ID地址,比较麻烦,如果能直接在创建时自定义就会方便很多
All reactions