feat(账号池): 对外只读 API(独立令牌)+ 资产管理入口
- GET /api/account_pool/accounts:X-Account-Token / Bearer,支持 device/q/status/online 过滤 - 令牌存 app_meta.account_pool_token,页面可查看/复制/重置 - 管理端 GET /api/account_pool/token、POST /token/reset - CORS;API/ACCOUNT_FOLDER 文档同步
This commit is contained in:
@@ -339,6 +339,7 @@ function afHtmlAsset() {
|
||||
'<div class="toolbar" style="flex-wrap:wrap;align-items:center">' +
|
||||
'<button class="btn btn-primary" onclick="afOpenAssetImport()" data-perm="devices">⬆ 批量上传素材(配模板)</button>' +
|
||||
'<button class="btn" onclick="afOpenRoster()" data-perm="devices">导入/维护账号库</button>' +
|
||||
'<button class="btn" onclick="afShowPoolApi()" data-perm="devices">🔑 账号池 API</button>' +
|
||||
'<button class="btn" onclick="afRefreshAll(true)">刷新</button>' +
|
||||
'<span class="text-muted" style="font-size:12px">账号表里点「入库 N」进素材库;' +
|
||||
'「所属手机」改了就**重新登记**(下次按新设备激活)。素材放进去 = 归这个账号。</span>' +
|
||||
@@ -1157,6 +1158,62 @@ function afHtmlRoster() {
|
||||
'</div></div>';
|
||||
}
|
||||
|
||||
// 账号池对外只读 API:给其他应用看"池子里有哪些号、在哪台手机"
|
||||
async function afShowPoolApi() {
|
||||
const r = await apiGet('/api/account_pool/token');
|
||||
if (!r || !r.ok) { showToast((r && r.error) || '需要管理员权限', 'error'); return; }
|
||||
const old = document.getElementById('af-pool-api');
|
||||
if (old) old.remove();
|
||||
const url = r.url || (location.origin + '/api/account_pool/accounts');
|
||||
const token = r.token || '';
|
||||
const curl = 'curl -H "X-Account-Token: ' + token + '" "' + url + '"';
|
||||
const d = document.createElement('div');
|
||||
d.id = 'af-pool-api';
|
||||
d.className = 'modal-overlay show';
|
||||
d.innerHTML = '<div class="modal" style="max-width:720px">' +
|
||||
'<div class="modal-header"><h3>🔑 账号池 API(只读)</h3>' +
|
||||
'<button class="close" onclick="document.getElementById(\'af-pool-api\').remove()">×</button></div>' +
|
||||
'<div class="modal-body">' +
|
||||
'<p class="text-muted" style="font-size:12px">其他应用直接 GET 这个地址,不需要登录;' +
|
||||
'请求头带 <code>X-Account-Token</code>(或 <code>Authorization: Bearer …</code>)。</p>' +
|
||||
'<div class="form-group"><label>地址</label>' +
|
||||
'<input class="form-control" readonly value="' + esc(url) + '"></div>' +
|
||||
'<div class="form-group"><label>令牌 ' + esc(r.token_created_at || '') + '</label>' +
|
||||
'<div style="display:flex;gap:6px">' +
|
||||
'<input class="form-control" readonly id="af-pool-token" value="' + esc(token) + '">' +
|
||||
'<button class="btn" onclick="afCopyPoolToken()">复制</button></div></div>' +
|
||||
'<div class="form-group"><label>示例</label>' +
|
||||
'<pre style="white-space:pre-wrap;font-size:12px;margin:0">' + esc(curl) + '</pre></div>' +
|
||||
'<p class="text-muted" style="font-size:12px">可选过滤:<code>?device=A11</code>、' +
|
||||
'<code>?q=锋哥</code>、<code>?status=正常</code>、<code>?online=1</code></p>' +
|
||||
'</div>' +
|
||||
'<div class="modal-footer">' +
|
||||
'<button class="btn btn-danger" onclick="afResetPoolToken()">重置令牌</button>' +
|
||||
'<button class="btn" onclick="document.getElementById(\'af-pool-api\').remove()">关闭</button>' +
|
||||
'</div></div>';
|
||||
document.body.appendChild(d);
|
||||
}
|
||||
|
||||
function afCopyPoolToken() {
|
||||
const el = document.getElementById('af-pool-token');
|
||||
if (!el) return;
|
||||
el.select();
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(el.value).then(function () { showToast('已复制', 'success'); });
|
||||
} else {
|
||||
document.execCommand('copy');
|
||||
showToast('已复制', 'success');
|
||||
}
|
||||
}
|
||||
|
||||
async function afResetPoolToken() {
|
||||
if (!confirm('重置后旧令牌立即失效,其他应用需要更新。继续?')) return;
|
||||
const r = await apiPost('/api/account_pool/token/reset', {});
|
||||
if (!r || !r.ok) { showToast((r && r.error) || '重置失败', 'error'); return; }
|
||||
showToast('令牌已重置', 'success');
|
||||
afShowPoolApi();
|
||||
}
|
||||
|
||||
function afOpenRoster() {
|
||||
const ov = document.getElementById('af-roster-overlay');
|
||||
if (ov) ov.remove();
|
||||
|
||||
Reference in New Issue
Block a user