feat:右上角接入授权中心——常驻版本徽章+公告铃铛+新版本横幅;server 加 /api/hub/*(安装统计/心跳/公告/更新检查,机器码存 hub.json);KEY 经 restart.sh 动态注入;/api/web-site 名称同步米图设计
NodeJS with Webpack / build (push) Canceled after 0s
NodeJS with Webpack / build (push) Canceled after 0s
This commit is contained in:
1 parent
759f8a6232
commit
fdd7c2f639
6 files changed
+385
-3
No files matched your search
@@ -14,6 +14,12 @@ services:
|
||||
TEMPLATE_DIR: /app/data
|
||||
# 封面 AI 助手地址(AI 出图的图会出现在「素材 → AI 生成」里)
|
||||
COVER_AI: ${COVER_AI:-http://192.168.68.19:8128}
|
||||
# 授权中心(CardAuth:安装统计/在线数/公告/版本推送,KEY 由 restart.sh 动态注入不落盘)
|
||||
VERSION: ${VERSION:-1.0.0}
|
||||
HUB_HOST: ${HUB_HOST:-https://auth.88531.cn}
|
||||
HUB_PROJECT_ID: ${HUB_PROJECT_ID:-}
|
||||
HUB_API_KEY: ${HUB_API_KEY:-}
|
||||
volumes:
|
||||
- ./server:/app/server:ro
|
||||
- /vol1/1000/HD1/docker/kuaitu-editor-data:/app/data:ro
|
||||
# rw:仅 server 写 hub.json(授权中心机器码/节流状态),模板只读逻辑不变
|
||||
- /vol1/1000/HD1/docker/kuaitu-editor-data:/app/data
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
# 米图设计(8126)重启脚本:注入授权中心 env 并重建容器
|
||||
# KEY 从 CardAuth 库按 HEX 取回后解码注入——明文密钥经终端/文本通道会被自动打码(403 的坑),勿手工写。
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
DB_KEY=$(docker exec cardauth-db sh -c \
|
||||
'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -N -e "SELECT HEX(api_key) FROM cardauth.ca_projects WHERE id=10"' 2>/dev/null | tr -d '[:space:]')
|
||||
[ -n "$DB_KEY" ] || { echo 'ERROR: 取不到项目 10 的 KEY'; exit 1; }
|
||||
export HUB_API_KEY=$(python3 -c 'import sys,binascii;print(binascii.unhexlify(sys.argv[1]).decode())' "$DB_KEY")
|
||||
export HUB_PROJECT_ID=10
|
||||
export HUB_HOST=https://auth.88531.cn
|
||||
export VERSION=${VERSION:-1.0.0}
|
||||
|
||||
docker compose -f docker-compose.cover.yml up -d "$@"
|
||||
echo 'done: kuaitu-editor restarted (hub project=10)'
|
||||
+128
-2
@@ -10,6 +10,112 @@ const INDEX = JSON.parse(fs.readFileSync(path.join(DATA, 'index.json'), 'utf8'))
|
||||
// 封面 AI 助手(AI 生图/修图服务),素材面板从这里取图
|
||||
const COVER_AI = process.env.COVER_AI || 'http://192.168.68.19:8128';
|
||||
|
||||
/* ---------------- 授权中心(CardAuth:安装统计 / 在线数 / 公告 / 版本推送) ----------------
|
||||
* 失败开放:授权中心挂了 → 版本照常显示、公告保留上次、更新提示消失,功能零影响。
|
||||
* 机器码只存 DATA/hub.json,不进浏览器;关上报:HUB_DISABLED=1。
|
||||
* 节流:更新检查 6h(失败 30min 重试)、心跳 30min、公告 60s。 */
|
||||
const APP_VERSION = process.env.VERSION || '1.0.0';
|
||||
const HUB_HOST = (process.env.HUB_HOST || 'https://auth.88531.cn').replace(/\/+$/, '');
|
||||
const HUB_PROJECT_ID = (process.env.HUB_PROJECT_ID || '').trim();
|
||||
const HUB_API_KEY = (process.env.HUB_API_KEY || '').trim();
|
||||
const HUB_DISABLED = process.env.HUB_DISABLED === '1';
|
||||
const HUB_STATE = path.join(DATA, 'hub.json');
|
||||
|
||||
function hubState() {
|
||||
try { return JSON.parse(fs.readFileSync(HUB_STATE, 'utf8')) || {}; } catch { return {}; }
|
||||
}
|
||||
function saveHubState(patch) {
|
||||
const s = Object.assign(hubState(), patch);
|
||||
try { fs.writeFileSync(HUB_STATE, JSON.stringify(s)); } catch { /* 只读数据卷时静默 */ }
|
||||
return s;
|
||||
}
|
||||
function machineId() {
|
||||
const s = hubState();
|
||||
if (!/^\d{10,16}$/.test(String(s.machine_id || ''))) {
|
||||
const id = String(Math.floor(1e12 + Math.random() * 8e12)).slice(0, 13);
|
||||
saveHubState({ machine_id: id });
|
||||
return id;
|
||||
}
|
||||
return String(s.machine_id);
|
||||
}
|
||||
function hubReady() { return !HUB_DISABLED && !!HUB_PROJECT_ID && !!HUB_API_KEY; }
|
||||
|
||||
function hubReq(url, { method = 'GET', headers = {}, body } = {}) {
|
||||
return new Promise((resolve) => {
|
||||
const ctrl = new AbortController();
|
||||
const t = setTimeout(() => ctrl.abort(), 8000);
|
||||
fetch(url, { method, headers, body, signal: ctrl.signal })
|
||||
.then(async (r) => {
|
||||
clearTimeout(t);
|
||||
let d = null;
|
||||
try { d = await r.json(); } catch { /* 非 JSON */ }
|
||||
resolve({ status: r.status, data: d });
|
||||
})
|
||||
.catch((e) => { clearTimeout(t); resolve({ status: 0, error: String(e.message || e) }); });
|
||||
});
|
||||
}
|
||||
|
||||
async function hubCheckUpdate(force = false) {
|
||||
if (!hubReady()) return null;
|
||||
const s = hubState();
|
||||
const now = Date.now();
|
||||
const gap = s.check_failed ? 30 * 60e3 : 6 * 3600e3;
|
||||
if (!force && s.checked_at && now - s.checked_at < gap) return s.last_update || null;
|
||||
const r = await hubReq(`${HUB_HOST}/api/public/installations/check-update`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-Api-Key': HUB_API_KEY, 'X-Project-Id': HUB_PROJECT_ID },
|
||||
body: JSON.stringify({ machine_id: machineId(), client_version: APP_VERSION, device_info: 'kuaitu-editor' }),
|
||||
});
|
||||
const d = r.data;
|
||||
if (r.status !== 200 || !d || d.code !== 200 || !d.data) {
|
||||
saveHubState({ checked_at: now, check_failed: true });
|
||||
return s.last_update || null;
|
||||
}
|
||||
const u = {
|
||||
install_id: d.data.install_id ?? null,
|
||||
latest_version: String(d.data.latest_version || ''),
|
||||
update_available: !!d.data.update_available,
|
||||
update_required: !!d.data.update_required || !!d.data.is_force,
|
||||
changelog: String(d.data.changelog || ''),
|
||||
download_url: String(d.data.download_url || ''),
|
||||
checked_at: now,
|
||||
};
|
||||
saveHubState({ checked_at: now, check_failed: false, last_update: u });
|
||||
return u;
|
||||
}
|
||||
|
||||
async function hubHeartbeat(force = false) {
|
||||
if (!hubReady()) return { ok: false, skipped: true };
|
||||
const s = hubState();
|
||||
const now = Date.now();
|
||||
if (!force && s.beat_at && now - s.beat_at < 30 * 60e3) return { ok: true, throttled: true };
|
||||
const r = await hubReq(`${HUB_HOST}/api/public/installations/heartbeat`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-Api-Key': HUB_API_KEY, 'X-Project-Id': HUB_PROJECT_ID },
|
||||
body: JSON.stringify({ machine_id: machineId(), client_version: APP_VERSION, device_info: 'kuaitu-editor' }),
|
||||
});
|
||||
const ok = r.status === 200 && !!r.data && r.data.code === 200;
|
||||
if (ok) saveHubState({ beat_at: now, online_at: now });
|
||||
return { ok };
|
||||
}
|
||||
|
||||
async function hubAnnouncements(force = false) {
|
||||
if (HUB_DISABLED || !HUB_PROJECT_ID) return { list: [], popup: [] };
|
||||
const s = hubState();
|
||||
const now = Date.now();
|
||||
if (!force && s.ann_at && now - s.ann_at < 60e3) return s.ann || { list: [], popup: [] };
|
||||
const r = await hubReq(`${HUB_HOST}/api/public/announcements?target=client&project_id=${encodeURIComponent(HUB_PROJECT_ID)}&limit=20`);
|
||||
if (r.status !== 200 || !r.data || r.data.code !== 200) return s.ann || { list: [], popup: [] };
|
||||
const d = r.data.data || r.data;
|
||||
const ann = {
|
||||
list: Array.isArray(d.list) ? d.list : [],
|
||||
popup: Array.isArray(d.popup) ? d.popup : [],
|
||||
at: now,
|
||||
};
|
||||
saveHubState({ ann_at: now, ann });
|
||||
return ann;
|
||||
}
|
||||
|
||||
const TYPES = [
|
||||
{ id: 20, name: '公众号封面' },
|
||||
{ id: 21, name: '小红书' },
|
||||
@@ -88,16 +194,36 @@ function loadIndex() {
|
||||
return indexHtml;
|
||||
}
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const u = new URL(req.url, 'http://localhost');
|
||||
const p = u.pathname;
|
||||
const q = u.searchParams;
|
||||
|
||||
// ---------- 授权中心(版本 / 更新提示 / 公告,前端角标与铃铛读这里) ----------
|
||||
if (p === '/api/hub/status') {
|
||||
const [up, ann] = await Promise.all([hubCheckUpdate(), hubAnnouncements()]);
|
||||
return send(res, 200, {
|
||||
ok: true,
|
||||
version: APP_VERSION,
|
||||
hub: HUB_DISABLED ? 'off' : (hubReady() ? 'on' : 'unconfigured'),
|
||||
update: up || { update_available: false, latest_version: '', changelog: '', download_url: '' },
|
||||
announcements: (ann && ann.list) || [],
|
||||
popup: (ann && ann.popup) || [],
|
||||
});
|
||||
}
|
||||
if (p === '/api/hub/heartbeat' && req.method === 'POST') {
|
||||
return send(res, 200, await hubHeartbeat());
|
||||
}
|
||||
if (p === '/api/hub/refresh' && req.method === 'POST') {
|
||||
const [up, ann, beat] = await Promise.all([hubCheckUpdate(true), hubAnnouncements(true), hubHeartbeat(true)]);
|
||||
return send(res, 200, { ok: true, version: APP_VERSION, update: up, announcements: (ann && ann.list) || [], heartbeat: beat });
|
||||
}
|
||||
|
||||
// ---------- API ----------
|
||||
if (p === '/api/templ-types') return send(res, 200, { data: TYPES.map(t => ({ id: t.id, attributes: { name: t.name } })) });
|
||||
if (p === '/api/web-site') {
|
||||
return send(res, 200, { data: { id: 1, attributes: {
|
||||
name: '快图设计 · 封面工坊', url: '/', logo: { data: { attributes: { url: '/logo.svg' } } },
|
||||
name: '米图设计 · 封面工坊', url: '/', logo: { data: { attributes: { url: '/logo.svg' } } },
|
||||
} } });
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
<template>
|
||||
<span class="hub-info">
|
||||
<!-- 新版本横幅(知道了后按版本号记忆隐藏) -->
|
||||
<div v-if="hasNew" class="hub-banner">
|
||||
<span>
|
||||
发现新版本 v{{ upd.latest_version }}
|
||||
<template v-if="upd.changelog">:{{ upd.changelog }}</template>
|
||||
</span>
|
||||
<a v-if="upd.download_url" :href="upd.download_url" target="_blank">去更新</a>
|
||||
<a class="know" @click="dismissBanner">知道了</a>
|
||||
</div>
|
||||
|
||||
<!-- 右上角常驻版本徽章 -->
|
||||
<Tooltip
|
||||
:content="hasNew ? `有新版本 v${upd.latest_version}` : `当前版本 v${version}`"
|
||||
placement="bottom"
|
||||
>
|
||||
<Tag :color="hasNew ? 'orange' : 'default'" class="ver-chip" @click="load(true)">
|
||||
v{{ version }}
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
|
||||
<!-- 公告铃铛(有未读亮红点) -->
|
||||
<Badge :dot="unread" :offset="[8, 3]">
|
||||
<Icon
|
||||
custom="ivu-icon-ios-notifications-outline"
|
||||
size="20"
|
||||
style="cursor: pointer"
|
||||
@click="openPanel"
|
||||
/>
|
||||
</Badge>
|
||||
|
||||
<!-- 公告面板 -->
|
||||
<div v-if="annVisible" class="ann-pop">
|
||||
<div class="ann-hd">
|
||||
<span>📢 公告</span>
|
||||
<Icon type="md-close" style="cursor: pointer" @click="annVisible = false" />
|
||||
</div>
|
||||
<div v-if="!anns.length" class="ann-empty">暂无公告</div>
|
||||
<div v-for="a in anns" :key="a.id" class="ann-item">
|
||||
<div class="t">{{ a.title }}</div>
|
||||
<div class="c">{{ a.content }}</div>
|
||||
<div class="d">{{ String(a.created_at || '').slice(0, 10) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 弹窗公告(每条只弹一次,按 id 记忆) -->
|
||||
<Modal v-model="popupShow" :title="popupAnn ? popupAnn.title : ''" footer-hide>
|
||||
<div class="popup-c">{{ popupAnn ? popupAnn.content : '' }}</div>
|
||||
</Modal>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script name="HubInfo" setup lang="ts">
|
||||
const version = ref('1.0.0');
|
||||
const upd = ref<{
|
||||
update_available: boolean;
|
||||
latest_version: string;
|
||||
changelog: string;
|
||||
download_url: string;
|
||||
}>({
|
||||
update_available: false,
|
||||
latest_version: '',
|
||||
changelog: '',
|
||||
download_url: '',
|
||||
});
|
||||
const anns = ref<{ id: number; title: string; content: string; created_at: string }[]>([]);
|
||||
const popupList = ref<typeof anns.value>([]);
|
||||
const annVisible = ref(false);
|
||||
const popupShow = ref(false);
|
||||
const popupAnn = ref<(typeof anns.value)[number] | null>(null);
|
||||
|
||||
const readIds = ref(new Set<number>(JSON.parse(localStorage.getItem('mtai.annRead') || '[]')));
|
||||
const seenPop = ref(new Set<number>(JSON.parse(localStorage.getItem('mtai.annSeen') || '[]')));
|
||||
|
||||
const hasNew = computed(
|
||||
() =>
|
||||
upd.value.update_available &&
|
||||
!!upd.value.latest_version &&
|
||||
upd.value.latest_version !== version.value &&
|
||||
localStorage.getItem('mtai.updHide') !== upd.value.latest_version
|
||||
);
|
||||
const unread = computed(() => anns.value.some((a) => !readIds.value.has(a.id)));
|
||||
|
||||
function dismissBanner() {
|
||||
localStorage.setItem('mtai.updHide', upd.value.latest_version);
|
||||
}
|
||||
function openPanel() {
|
||||
annVisible.value = !annVisible.value;
|
||||
if (annVisible.value && anns.value.length) {
|
||||
anns.value.forEach((a) => readIds.value.add(a.id));
|
||||
localStorage.setItem('mtai.annRead', JSON.stringify([...readIds.value]));
|
||||
}
|
||||
}
|
||||
|
||||
async function load(_force?: boolean) {
|
||||
try {
|
||||
const d = await (await fetch('/api/hub/status')).json();
|
||||
if (d.version) version.value = d.version;
|
||||
if (d.update) upd.value = d.update;
|
||||
if (Array.isArray(d.announcements)) anns.value = d.announcements;
|
||||
if (Array.isArray(d.popup)) popupList.value = d.popup;
|
||||
// 弹窗公告:有没见过的就弹第一条
|
||||
const fresh = popupList.value.find((a) => !seenPop.value.has(a.id));
|
||||
if (fresh) {
|
||||
popupAnn.value = fresh;
|
||||
popupShow.value = true;
|
||||
seenPop.value.add(fresh.id);
|
||||
localStorage.setItem('mtai.annSeen', JSON.stringify([...seenPop.value]));
|
||||
}
|
||||
} catch {
|
||||
/* 授权中心不可用时静默:版本徽章照常显示本地版本 */
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
load();
|
||||
// 心跳(服务端已节流 30min,这里只是触发)
|
||||
fetch('/api/hub/heartbeat', { method: 'POST' }).catch(() => {});
|
||||
// 页面重新可见时补一次(服务端节流兜底)
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible') load();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.hub-info {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
position: relative;
|
||||
|
||||
.ver-chip {
|
||||
cursor: pointer;
|
||||
font-family: Consolas, Monaco, monospace;
|
||||
}
|
||||
|
||||
.hub-banner {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 300;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
padding: 7px 12px;
|
||||
background: #fff7e0;
|
||||
border-bottom: 1px solid #ffd591;
|
||||
color: #874d00;
|
||||
font-size: 13px;
|
||||
|
||||
a {
|
||||
color: #d46b08;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.know {
|
||||
color: #8c8c8c;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.ann-pop {
|
||||
position: absolute;
|
||||
top: 34px;
|
||||
right: 0;
|
||||
z-index: 400;
|
||||
width: 280px;
|
||||
max-height: 360px;
|
||||
overflow: auto;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #e5e7eb;
|
||||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
|
||||
|
||||
.ann-hd {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ann-empty {
|
||||
padding: 22px 12px;
|
||||
text-align: center;
|
||||
color: #9ca3af;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.ann-item {
|
||||
padding: 10px 12px;
|
||||
border-bottom: 1px solid #f5f5f5;
|
||||
|
||||
.t {
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.c {
|
||||
margin-top: 4px;
|
||||
color: #4b5563;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.d {
|
||||
margin-top: 4px;
|
||||
color: #9ca3af;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.popup-c {
|
||||
color: #374151;
|
||||
line-height: 1.8;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -22,6 +22,8 @@
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
<hubInfo></hubInfo>
|
||||
<Divider type="vertical" />
|
||||
<a href="https://pro.kuaitu.cc/" target="_blank" alt="商业版">
|
||||
<img width="15" :src="proIcon" alt="vue-fbric-editor" />
|
||||
</a>
|
||||
@@ -53,6 +55,7 @@ import waterMark from '@/components/waterMark.vue';
|
||||
import login from '@/components/login';
|
||||
import admin from '@/components/admin';
|
||||
import history from '@/components/history.vue';
|
||||
import hubInfo from '@/components/hubInfo.vue';
|
||||
|
||||
const props = defineProps(['ruler']);
|
||||
const emit = defineEmits(['update:ruler']);
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
<hubInfo></hubInfo>
|
||||
<Divider type="vertical" />
|
||||
<Button type="primary" to="/" size="smail" target="_blank">新建设计</Button>
|
||||
<Divider type="vertical" />
|
||||
<a href="https://pro.kuaitu.cc/" target="_blank">
|
||||
@@ -100,6 +102,7 @@ import banner from './components/banner.vue';
|
||||
// 顶部组件
|
||||
import logo from '@/components/logo.vue';
|
||||
import lang from '@/components/lang.vue';
|
||||
import hubInfo from '@/components/hubInfo.vue';
|
||||
import login from '@/components/login';
|
||||
|
||||
import { getMaterialPreviewUrl } from '@/hooks/usePageList';
|
||||
|
||||
Reference in new issue
Block a user