fix(settings): add DingTalk spaces and render the real login QR
Address two gaps in the first DingTalk-session UI: - add an explicit admin-only '+ 新增钉钉知识库' action on the data-source panel; it accepts an alidocs space URL, resolves the live name/root through the authenticated sidecar, writes the inventory root atomically, upserts a deterministic source connection, and enqueues its first catalog refresh - read DingTalk's real QR canvas pixels rather than taking a DOM screenshot; select by dark-pixel content, composite onto a white quiet zone, and render at 320x320 so the dialog contains a large complete code, not a page thumbnail The live refresh path resolves registered roots from the connection locator, while existing name-based DingTalk sources remain compatible.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { useState } from 'react'
|
||||
|
||||
import { registerDingtalkSpace } from './dingtalkSession'
|
||||
|
||||
// Admin-only entry in 系统设置 → 数据源配置: paste a DingTalk knowledge-base
|
||||
// space URL (or space id) and register it as a governed source. The sidecar
|
||||
// resolves name+root with the current scan session; 409 login_required tells
|
||||
// the operator to refresh the QR first.
|
||||
|
||||
export function DingtalkSpaceRegistrar({ onRegistered }: { onRegistered: () => void }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [url, setUrl] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [failure, setFailure] = useState<string | null>(null)
|
||||
const [done, setDone] = useState<string | null>(null)
|
||||
|
||||
const submit = async () => {
|
||||
setBusy(true); setFailure(null)
|
||||
try {
|
||||
const registered = await registerDingtalkSpace(url.trim())
|
||||
setDone(`「${registered.name}」已登记为钉钉来源,首次目录扫描已在后台排队。`)
|
||||
setUrl('')
|
||||
onRegistered()
|
||||
} catch (cause) {
|
||||
setFailure(cause instanceof Error ? cause.message : '登记钉钉知识库失败')
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return <div className="dingtalk-space-registrar">
|
||||
<button className="secondary" onClick={() => { setOpen(true); setDone(null); setFailure(null) }}>+ 新增钉钉知识库</button>
|
||||
{open ? <div className="modal-backdrop" role="dialog" aria-modal="true" aria-label="新增钉钉知识库">
|
||||
<div className="modal-card">
|
||||
<h3>新增钉钉知识库</h3>
|
||||
<p>粘贴知识库空间链接(形如 https://alidocs.dingtalk.com/i/spaces/…/overview),平台会解析空间名称与根目录并登记为新来源;首次扫描自动排队。</p>
|
||||
<label className="kb-binding-editor-label">空间链接
|
||||
<input value={url} onChange={(event) => { setUrl(event.target.value); setDone(null) }} placeholder="https://alidocs.dingtalk.com/i/spaces/…" disabled={busy} />
|
||||
</label>
|
||||
{done ? <p className="success-message" role="status">{done}</p> : null}
|
||||
{failure ? <p className="error-message" role="alert">{failure}</p> : null}
|
||||
<div className="modal-actions">
|
||||
<button className="secondary" onClick={() => setOpen(false)}>{done ? '完成' : '取消'}</button>
|
||||
<button disabled={busy || !url.trim()} onClick={() => void submit()}>{busy ? '正在解析…' : '登记'}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div> : null}
|
||||
</div>
|
||||
}
|
||||
Reference in New Issue
Block a user