feat(music): per-user music accounts with an admin-owned account pool

Every member saw the admin's library: the bot keeps one shared login per
platform (data/cookies/<platform>.json) and search, playlists and playback
URLs all read through it. #164 added a personal NetEase login, but only for
私人FM — the rest still came from the shared account.

On top of that, most members do not own a paid login, so "everyone links their
own" is not enough: the admin has to be able to hand out accounts.

What this adds, behind one admin switch (`perUserMusicAccounts`, default off):

- One login per request, resolved in this order: the caller's OWN linked
  account, then an account an admin ASSIGNED, then the bot's shared login.
- An admin-owned pool (`music_accounts`) plus per-member assignments
  (`music_account_grants`, PK userId+platform = one per platform). Assignments
  are capacity-checked inside a transaction, so an exclusive account cannot be
  handed to two members by two concurrent clicks. `enabled = 0` is an instant
  rollback of every grant without deleting them.
- Own-beats-assigned, and the two live in separate tables: a member scanning
  their own QR code never overwrites an admin's assignment, and unlinking on
  the member side never revokes what the admin granted.
- QQ / Kugou / Bilibili now implement `withCookie`, so all four sources can be
  isolated. Only NetEase exposes QR self-linking (it is the only one with
  `pollQrLogin`); the rest accept an assigned account, which is the workflow
  that actually matters for members without a paid login.
- `/api/music-accounts` is admin-only (`requireAdmin`, not `bot.manage`):
  members must never see which account was handed to whom. Cookies are masked
  in every response.

Switch off = no behaviour change at all, except 私人FM keeps the #164 behaviour
through `alwaysPersonal`.
This commit is contained in:
jiayuLian committed 2026-11-08 17:07:42 +08:00
1 parent 17008ae52e
commit 61c24cc219
20 files changed
+2568 -114

No files matched your search

+551
View File
@@ -0,0 +1,551 @@
<template>
<!-- Admin console for the music-account pool (#164 follow-up).
One row per login the admin owns; each row can be handed to members (or
to another admin). See src/web/api/music-accounts.ts for the rules. -->
<div class="pool">
<p class="hint">
这里存放管理员拥有的音乐账号,可以逐个分配给成员。成员自己扫码绑定的账号优先级更高,
管理员分配的账号只在他们没绑定自己的账号时生效。播放地址、搜索、歌单都会按被分配的账号获取。
</p>
<!-- Create -->
<div class="create-row">
<select v-model="draft.platform" class="field">
<option v-for="p in platforms" :key="p.platform" :value="p.platform">
{{ PLATFORM_LABEL[p.platform] ?? p.platform }}
{{ p.playbackSupported ? '' : '(暂不支持按账号播放)' }}
</option>
</select>
<input v-model="draft.label" class="field" placeholder="名称,如 网易云-主号" maxlength="64" />
<input
v-model.number="draft.capacity"
class="field field-narrow"
type="number"
min="0"
title="0 = 可分配给多人;1 = 独占,只能给一个人"
placeholder="人数上限"
/>
<button class="btn primary" :disabled="creating" @click="create">
<Icon icon="mdi:plus" /> 添加账号
</button>
<button class="btn" :disabled="creating" @click="importShared">
<Icon icon="mdi:download" /> 从共享账号导入
</button>
</div>
<textarea
v-model="draft.cookie"
class="field cookie-input"
rows="2"
placeholder="粘贴该账号的 Cookie(仅保存在服务器,列表里只显示掩码)"
></textarea>
<p v-if="error" class="error">{{ error }}</p>
<!-- List -->
<div v-if="accounts.length === 0" class="empty">还没有添加任何账号</div>
<div v-for="a in accounts" :key="a.id" class="account" :class="{ disabled: !a.enabled }">
<div class="account-head">
<div class="account-title">
<span class="badge">{{ PLATFORM_LABEL[a.platform] ?? a.platform }}</span>
<span class="label">{{ a.label }}</span>
<span v-if="a.capacity === 1" class="tag exclusive">独占</span>
<span v-else-if="a.capacity > 1" class="tag">最多 {{ a.capacity }} 人</span>
<span v-else class="tag">不限人数</span>
<span v-if="!a.playbackSupported" class="tag warn">该平台暂不支持按账号播放</span>
</div>
<div class="account-actions">
<button class="btn tiny" @click="probe(a)">
<Icon icon="mdi:shield-check" /> 检测
</button>
<label class="switch" :title="a.enabled ? '已启用' : '已停用'">
<input type="checkbox" :checked="a.enabled" @change="toggleEnabled(a)" />
<span class="slider"></span>
</label>
<button class="btn tiny danger" @click="remove(a)">
<Icon icon="mdi:trash-can-outline" />
</button>
</div>
</div>
<div class="account-meta">
<span class="mono">{{ a.cookiePreview }}</span>
<span v-if="probeResult[a.id]" class="probe" :class="{ ok: probeResult[a.id]!.loggedIn }">
{{ probeResult[a.id]!.loggedIn ? `登录有效${probeResult[a.id]!.nickname ? ':' + probeResult[a.id]!.nickname : ''}` : '登录已失效' }}
</span>
</div>
<div class="grantees">
<span class="grantees-label">已分配:</span>
<span v-if="a.grantees.length === 0" class="muted">无</span>
<span v-for="g in a.grantees" :key="g.userId" class="chip">
{{ g.username }}
<button class="chip-x" title="收回" @click="revoke(a, g.userId)">×</button>
</span>
<select
class="field field-narrow assign-select"
:value="''"
:disabled="assignable(a).length === 0"
@change="onAssign(a, $event)"
>
<option value="">{{ assignable(a).length === 0 ? '已满额' : '+ 分配给…' }}</option>
<option v-for="u in assignable(a)" :key="u.id" :value="u.id">
{{ u.username }}{{ u.role === 'admin' ? '(管理员)' : '' }}
</option>
</select>
</div>
<div class="cookie-edit">
<input
v-model="cookieDraft[a.id]"
class="field"
type="password"
placeholder="更新 Cookie(登录失效时用)"
/>
<button class="btn tiny" :disabled="!cookieDraft[a.id]" @click="updateCookie(a)">
保存
</button>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue';
import { Icon } from '@iconify/vue';
import axios from 'axios';
interface Grantee { userId: string; username: string; grantedAt: string }
interface PoolAccount {
id: string;
platform: string;
label: string;
cookiePreview: string;
capacity: number;
enabled: boolean;
playbackSupported: boolean;
granteeCount: number;
grantees: Grantee[];
}
interface AssignableUser { id: string; username: string; role: string }
const PLATFORM_LABEL: Record<string, string> = {
netease: '网易云',
qq: 'QQ音乐',
kugou: '酷狗',
bilibili: 'B站',
};
const accounts = ref<PoolAccount[]>([]);
const users = ref<AssignableUser[]>([]);
const platforms = ref<Array<{ platform: string; playbackSupported: boolean }>>([]);
const creating = ref(false);
const error = ref('');
const draft = reactive({ platform: 'netease', label: '', cookie: '', capacity: 0 });
const cookieDraft = reactive<Record<string, string>>({});
const probeResult = ref<Record<string, { loggedIn: boolean; nickname?: string } | undefined>>({});
const assignable = (a: PoolAccount) => {
const held = new Set(a.grantees.map((g) => g.userId));
// An exclusive account that already has a holder offers nobody: the API would
// answer 409 anyway, so don't dangle options that cannot work.
if (a.capacity === 1 && a.granteeCount >= 1) return [];
if (a.capacity > 1 && a.granteeCount >= a.capacity) return [];
return users.value.filter((u) => !held.has(u.id));
};
const errText = (err: any, fallback: string) => {
const e = err?.response?.data?.error;
if (e === 'account_exclusive') return '该账号是独占的,请先收回其他成员';
if (e === 'account_full') return '该账号已分配满额';
if (e === 'account_disabled') return '该账号已停用';
if (e === 'no_shared_login') return '机器人还没有登录该平台的共享账号';
return e ?? fallback;
};
async function load() {
try {
const res = await axios.get('/api/music-accounts');
accounts.value = res.data.accounts ?? [];
users.value = res.data.users ?? [];
platforms.value = res.data.platforms ?? [];
if (!platforms.value.some((p) => p.platform === draft.platform)) {
draft.platform = platforms.value[0]?.platform ?? 'netease';
}
} catch (err) {
error.value = errText(err, '加载失败');
}
}
async function create() {
error.value = '';
if (!draft.label.trim() || !draft.cookie.trim()) {
error.value = '名称和 Cookie 都要填';
return;
}
creating.value = true;
try {
await axios.post('/api/music-accounts', {
platform: draft.platform,
label: draft.label.trim(),
cookie: draft.cookie.trim(),
capacity: Number(draft.capacity) || 0,
});
draft.label = '';
draft.cookie = '';
draft.capacity = 0;
await load();
} catch (err) {
error.value = errText(err, '添加失败');
} finally {
creating.value = false;
}
}
async function importShared() {
error.value = '';
creating.value = true;
try {
await axios.post('/api/music-accounts/import-shared', {
platform: draft.platform,
label: `${PLATFORM_LABEL[draft.platform] ?? draft.platform} 共享账号`,
capacity: Number(draft.capacity) || 0,
});
await load();
} catch (err) {
error.value = errText(err, '导入失败');
} finally {
creating.value = false;
}
}
async function toggleEnabled(a: PoolAccount) {
error.value = '';
try {
await axios.patch(`/api/music-accounts/${a.id}`, { enabled: !a.enabled });
await load();
} catch (err) {
error.value = errText(err, '操作失败');
}
}
async function updateCookie(a: PoolAccount) {
error.value = '';
try {
await axios.patch(`/api/music-accounts/${a.id}`, { cookie: cookieDraft[a.id] });
cookieDraft[a.id] = '';
await load();
} catch (err) {
error.value = errText(err, '保存失败');
}
}
async function remove(a: PoolAccount) {
if (!confirm(`删除「${a.label}」?已分配给成员的记录会一起收回。`)) return;
error.value = '';
try {
await axios.delete(`/api/music-accounts/${a.id}`);
await load();
} catch (err) {
error.value = errText(err, '删除失败');
}
}
async function onAssign(a: PoolAccount, ev: Event) {
const select = ev.target as HTMLSelectElement;
const userId = select.value;
select.value = '';
if (!userId) return;
error.value = '';
try {
await axios.post(`/api/music-accounts/${a.id}/assign`, { userId });
await load();
} catch (err) {
error.value = errText(err, '分配失败');
}
}
async function revoke(a: PoolAccount, userId: string) {
error.value = '';
try {
await axios.delete(`/api/music-accounts/${a.id}/assign/${userId}`);
await load();
} catch (err) {
error.value = errText(err, '收回失败');
}
}
async function probe(a: PoolAccount) {
error.value = '';
try {
const res = await axios.post(`/api/music-accounts/${a.id}/probe`);
probeResult.value[a.id] = { loggedIn: Boolean(res.data.loggedIn), nickname: res.data.nickname };
} catch (err) {
probeResult.value[a.id] = { loggedIn: false };
error.value = errText(err, '检测失败');
}
}
onMounted(load);
</script>
<style lang="scss" scoped>
.pool {
margin-top: 12px;
}
.hint {
font-size: 12px;
color: var(--text-tertiary);
line-height: 1.6;
margin: 0 0 12px;
}
.create-row {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-bottom: 8px;
}
.field {
padding: 7px 10px;
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
color: inherit;
font-size: 13px;
min-width: 0;
&:focus {
outline: none;
border-color: var(--color-primary);
}
}
.field-narrow {
width: 96px;
}
.cookie-input {
width: 100%;
resize: vertical;
font-family: var(--font-mono, monospace);
margin-bottom: 8px;
}
.btn {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 7px 14px;
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
font-size: 13px;
color: inherit;
cursor: pointer;
transition: all var(--transition-fast);
&:hover:not(:disabled) {
border-color: var(--color-primary);
color: var(--color-primary);
}
&:disabled {
opacity: 0.55;
cursor: default;
}
&.primary {
border-color: var(--color-primary);
color: var(--color-primary);
}
&.tiny {
padding: 4px 8px;
font-size: 12px;
}
&.danger:hover {
border-color: #e26a6a;
color: #e26a6a;
}
}
.empty {
padding: 16px;
font-size: 13px;
color: var(--text-tertiary);
text-align: center;
}
.account {
padding: 12px 14px;
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
margin-bottom: 10px;
background: var(--hover-bg);
&.disabled {
opacity: 0.6;
}
}
.account-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
}
.account-title {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
}
.badge {
font-size: 11px;
padding: 2px 7px;
border-radius: 10px;
background: var(--bg-card);
border: 1px solid var(--border-color);
color: var(--text-secondary);
}
.label {
font-weight: 600;
font-size: 14px;
}
.tag {
font-size: 11px;
color: var(--text-tertiary);
&.exclusive {
color: var(--color-primary);
}
&.warn {
color: #d19a3a;
}
}
.account-actions {
display: flex;
align-items: center;
gap: 8px;
}
.account-meta {
display: flex;
align-items: center;
gap: 10px;
margin-top: 6px;
font-size: 12px;
color: var(--text-tertiary);
flex-wrap: wrap;
}
.mono {
font-family: var(--font-mono, monospace);
}
.probe {
color: #e26a6a;
&.ok {
color: var(--color-online);
}
}
.grantees {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
margin-top: 10px;
}
.grantees-label {
font-size: 12px;
color: var(--text-tertiary);
}
.muted {
font-size: 12px;
color: var(--text-tertiary);
}
.chip {
display: inline-flex;
align-items: center;
gap: 3px;
padding: 2px 8px;
font-size: 12px;
border-radius: 10px;
background: var(--bg-card);
border: 1px solid var(--border-color);
}
.chip-x {
border: none;
background: none;
color: var(--text-tertiary);
cursor: pointer;
font-size: 13px;
line-height: 1;
padding: 0 0 0 2px;
&:hover {
color: #e26a6a;
}
}
.assign-select {
margin-left: auto;
}
.cookie-edit {
display: flex;
gap: 8px;
margin-top: 10px;
.field {
flex: 1;
}
}
.switch {
position: relative;
display: inline-block;
width: 34px;
height: 18px;
input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
inset: 0;
background: var(--border-color);
border-radius: 9px;
cursor: pointer;
transition: background var(--transition-fast);
}
.slider::before {
content: '';
position: absolute;
width: 14px;
height: 14px;
left: 2px;
top: 2px;
background: #fff;
border-radius: 50%;
transition: transform var(--transition-fast);
}
input:checked + .slider {
background: var(--color-primary);
}
input:checked + .slider::before {
transform: translateX(16px);
}
}
.error {
margin: 6px 0;
font-size: 12px;
color: #e26a6a;
}
</style>
@@ -1,30 +1,67 @@
<template>
<!-- The signed-in user's own NetEase account, used for THEIR 私人FM instead
of the bot's shared login (#164). -->
<!-- The signed-in user's own music accounts (#164 + #164 follow-up).
Two ways an account can apply to this user:
- 自己扫码绑定 (source = personal) → they may unlink it
- 管理员分配 (source = granted) → only the admin can revoke it
Everything is read from /api/me/music/<platform>/status; the cookie never
reaches the browser. -->
<div class="account-card">
<div class="account-header">
<Icon icon="mdi:radio" class="account-icon" />
<Icon icon="mdi:account-music" class="account-icon" />
<div class="account-info">
<div class="account-name">我的网易云账号(私人FM)</div>
<div class="account-status" :class="{ logged: status.loggedIn }">
<template v-if="status.loggedIn">已绑定: {{ status.nickname }}</template>
<div class="account-name">我的音乐账号</div>
<div class="account-status" :class="{ logged: status.loggedIn, granted: status.source === 'granted' }">
<template v-if="status.source === 'granted'">
由管理员分配:{{ status.label || '已分配的账号' }}
<template v-if="status.loggedIn && status.nickname">({{ status.nickname }})</template>
<template v-else-if="!status.loggedIn">,但登录已失效,请联系管理员</template>
</template>
<template v-else-if="status.loggedIn">已绑定:{{ status.nickname }}</template>
<template v-else-if="status.linked">已绑定,但登录已失效,请重新扫码</template>
<template v-else>未绑定 — 私人FM使用机器人的共享账号</template>
<template v-else>未绑定 — 使用机器人的共享账号</template>
</div>
</div>
</div>
<!-- Platform switch: only the sources this instance has enabled. -->
<div v-if="platforms.length > 1" class="platform-tabs">
<button
v-for="p in platforms"
:key="p"
class="platform-tab"
:class="{ active: p === current }"
@click="selectPlatform(p)"
>
{{ PLATFORM_LABEL[p] ?? p }}
</button>
</div>
<p class="hint">
绑定后,你在网页端开启的网易云私人FM会按你自己的口味推荐;其他人不受影响。
仅保存在服务器上,不会显示给任何人。
<template v-if="status.source === 'granted'">
这个账号是管理员分配给你的,搜索、歌单、每日推荐和播放都会用它。想换成自己的账号,直接扫码绑定即可 — 自己的账号优先。
</template>
<template v-else-if="status.supportsQrLogin">
绑定后,{{ PLATFORM_LABEL[current] ?? current }}的搜索、歌单、每日推荐和播放地址都按你自己的账号获取,
看不到管理员的歌单和收藏。仅保存在服务器上,不会显示给任何人。
</template>
<template v-else>
该平台暂不支持在网页端自助绑定,需要账号请联系管理员分配。
</template>
</p>
<div class="login-methods">
<button class="login-btn" :disabled="qr.loading" @click="startQrLogin">
<button
v-if="status.supportsQrLogin"
class="login-btn"
:disabled="qr.loading"
@click="startQrLogin"
>
<Icon icon="mdi:qrcode" />
{{ status.linked ? '重新扫码绑定' : '扫码绑定' }}
</button>
<button v-if="status.linked" class="login-btn" @click="unlink">
<!-- Only the user's OWN login can be removed here; an admin-granted one
is managed from Settings → 音乐账号分配. -->
<button v-if="status.canUnlink" class="login-btn" @click="unlink">
<Icon icon="mdi:link-off" />
解除绑定
</button>
@@ -38,7 +75,7 @@
<img :src="qr.dataUrl" class="qr-image" alt="QR Code" />
<div class="qr-status" :class="qr.status">
<template v-if="qr.status === 'waiting'">
<Icon icon="mdi:cellphone" /> 请使用网易云音乐APP扫码
<Icon icon="mdi:cellphone" /> 请使用{{ PLATFORM_LABEL[current] ?? '' }}APP扫码
</template>
<template v-else-if="qr.status === 'scanned'">
<Icon icon="mdi:check" /> 已扫码,请在手机上确认
@@ -57,14 +94,32 @@
</template>
<script setup lang="ts">
import { onMounted, onUnmounted, reactive, ref } from 'vue';
import { onMounted, onUnmounted, reactive, ref, watch } from 'vue';
import { Icon } from '@iconify/vue';
import axios from 'axios';
import QRCode from 'qrcode';
const BASE = '/api/me/music/netease';
const props = withDefaults(defineProps<{ platforms?: string[] }>(), {
platforms: () => ['netease'],
});
const status = reactive({ linked: false, loggedIn: false, nickname: '' });
const PLATFORM_LABEL: Record<string, string> = {
netease: '网易云',
qq: 'QQ音乐',
kugou: '酷狗',
bilibili: 'B站',
};
const current = ref(props.platforms[0] ?? 'netease');
const status = reactive({
linked: false,
loggedIn: false,
nickname: '',
label: '',
source: 'none' as 'none' | 'personal' | 'granted',
canUnlink: false,
supportsQrLogin: false,
});
const qr = reactive({
loading: false,
dataUrl: '',
@@ -74,6 +129,8 @@ const qr = reactive({
const error = ref('');
let pollTimer: ReturnType<typeof setInterval> | null = null;
const base = () => `/api/me/music/${current.value}`;
function stopPolling() {
if (pollTimer) clearInterval(pollTimer);
pollTimer = null;
@@ -81,15 +138,34 @@ function stopPolling() {
async function refreshStatus() {
try {
const res = await axios.get(`${BASE}/status`);
const res = await axios.get(`${base()}/status`);
status.linked = Boolean(res.data?.linked);
status.loggedIn = Boolean(res.data?.loggedIn);
status.nickname = res.data?.nickname ?? '';
status.label = res.data?.label ?? '';
status.source = res.data?.source ?? 'none';
status.canUnlink = Boolean(res.data?.canUnlink);
status.supportsQrLogin = Boolean(res.data?.supportsQrLogin);
} catch {
// Leave the last known state
}
}
function resetQr() {
stopPolling();
qr.dataUrl = '';
qr.key = '';
qr.status = 'waiting';
}
function selectPlatform(p: string) {
if (p === current.value) return;
current.value = p;
error.value = '';
resetQr();
void refreshStatus();
}
async function startQrLogin() {
stopPolling();
error.value = '';
@@ -97,7 +173,7 @@ async function startQrLogin() {
qr.dataUrl = '';
qr.status = 'waiting';
try {
const res = await axios.post(`${BASE}/qrcode`);
const res = await axios.post(`${base()}/qrcode`);
const { qrUrl, qrImg, key } = res.data;
qr.key = key;
// Dark-on-light only: many in-app scanners can't read an inverted code.
@@ -108,7 +184,10 @@ async function startQrLogin() {
}));
pollTimer = setInterval(pollQrStatus, 2000);
} catch (err: any) {
error.value = err?.response?.data?.error ?? '二维码生成失败';
const code = err?.response?.status;
error.value = code === 501
? '该平台暂不支持自助绑定,请联系管理员分配账号'
: (err?.response?.data?.error ?? '二维码生成失败');
} finally {
qr.loading = false;
}
@@ -117,7 +196,7 @@ async function startQrLogin() {
async function pollQrStatus() {
if (!qr.key) return;
try {
const res = await axios.get(`${BASE}/qrcode/status`, { params: { key: qr.key } });
const res = await axios.get(`${base()}/qrcode/status`, { params: { key: qr.key } });
qr.status = res.data.status;
if (qr.status === 'confirmed') {
stopPolling();
@@ -133,15 +212,25 @@ async function pollQrStatus() {
async function unlink() {
error.value = '';
try {
await axios.delete(BASE);
stopPolling();
qr.dataUrl = '';
await axios.delete(base());
resetQr();
await refreshStatus();
} catch (err: any) {
error.value = err?.response?.data?.error ?? '解除绑定失败';
}
}
// Settings can render before the provider list is known; follow it if it changes.
watch(
() => props.platforms,
(list) => {
if (list.length > 0 && !list.includes(current.value)) {
current.value = list[0];
void refreshStatus();
}
},
);
onMounted(refreshStatus);
onUnmounted(stopPolling);
</script>
@@ -174,6 +263,29 @@ onUnmounted(stopPolling);
font-size: 12px;
color: var(--text-tertiary);
&.logged { color: var(--color-online); }
&.granted { color: var(--text-secondary); }
}
.platform-tabs {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 10px;
}
.platform-tab {
padding: 5px 12px;
font-size: 12px;
border-radius: 14px;
border: 1px solid var(--border-color);
background: var(--bg-card);
color: var(--text-secondary);
cursor: pointer;
transition: all var(--transition-fast);
&.active {
border-color: var(--color-primary);
color: var(--color-primary);
}
}
.hint {
+66 -2
View File
@@ -116,7 +116,10 @@
</form>
<p v-if="ownPwError" class="user-error">{{ ownPwError }}</p>
<p v-if="ownPwSuccess" class="user-success">{{ ownPwSuccess }}</p>
<PersonalNeteaseAccount v-if="providerOn('netease') && !session.isGuest.value" />
<PersonalMusicAccount
v-if="!session.isGuest.value && personalPlatforms.length > 0"
:platforms="personalPlatforms"
/>
</section>
<!-- Bot Management (create/edit/delete/start-stop) requires bot.manage -->
@@ -967,6 +970,29 @@
@change="savePlayKeepsQueue"
/>
</label>
<!-- Admin-only: per-user music accounts. Off by default so an existing
deployment keeps sharing one login with everyone. -->
<label v-if="session.isAdmin.value" class="profile-toggle behavior-toggle">
<div class="profile-toggle-text">
<div class="profile-toggle-label">每个成员使用自己的音乐账号</div>
<div class="profile-toggle-hint">开启后,成员在「我的音乐账号」里绑定自己的网易云,搜索、歌单、每日推荐和播放地址都按他自己的账号获取,看不到管理员的歌单和收藏。未绑定、游客或未开启时沿用机器人的共享账号。默认关闭。目前仅网易云支持个人绑定。</div>
</div>
<input
v-model="perUserMusicAccounts"
type="checkbox"
class="profile-toggle-switch"
@change="savePerUserMusicAccounts"
/>
</label>
<!-- Admin-only: the pool of logins that can be handed to members. Only
meaningful while the toggle above is on. -->
<div v-if="session.isAdmin.value && perUserMusicAccounts" class="pool-wrap">
<div class="pool-title">音乐账号分配</div>
<div class="pool-hint">添加管理员拥有的账号,分配给指定成员(也可以分配给其他管理员)。成员自己绑定的账号优先;未绑定的人使用分配给自己的账号;都没有时回到机器人的共享账号。</div>
<MusicAccountPool />
</div>
</section>
<!-- Guest Mode (admin only) -->
@@ -1305,7 +1331,8 @@ import axios from 'axios';
import AvatarUpload from '../components/AvatarUpload.vue';
import CustomAvatarRow from '../components/CustomAvatarRow.vue';
import AccentColorPicker from '../components/AccentColorPicker.vue';
import PersonalNeteaseAccount from '../components/PersonalNeteaseAccount.vue';
import PersonalMusicAccount from '../components/PersonalMusicAccount.vue';
import MusicAccountPool from '../components/MusicAccountPool.vue';
import QRCode from 'qrcode';
import { usePlayerStore } from '../stores/player.js';
import { useSession } from '../composables/useSession.js';
@@ -1431,6 +1458,11 @@ function providerOn(p: string): boolean {
return enabledProviders.value.length === 0 || enabledProviders.value.includes(p);
}
// Sources the member can hold a personal account for. Only enabled ones are
// offered — /api/me/music serves a fixed set regardless of config.
const PERSONAL_PLATFORMS = ['netease', 'qq', 'kugou', 'bilibili'] as const;
const personalPlatforms = computed(() => PERSONAL_PLATFORMS.filter((p) => providerOn(p)));
// --- Default music source (issue #126) ---
// Chinese labels for the gateable providers, shown in the default-source select.
const PROVIDER_LABELS: Record<string, string> = {
@@ -1825,6 +1857,8 @@ const localAudioEnabled = ref(true);
// Saved-queues + play-keeps-queue toggles (#119), both default OFF.
const savedQueuesEnabled = ref(false);
const playKeepsQueue = ref(false);
// Per-user music accounts (#164 follow-up). Admin toggle, default OFF.
const perUserMusicAccounts = ref(false);
function normalizeVoiceDuckingVolume(): number {
const raw = voiceDuckingVolumePercent.value as number | string;
@@ -1865,6 +1899,7 @@ async function loadIdleTimeout() {
localAudioEnabled.value = res.data.localAudioEnabled ?? true;
savedQueuesEnabled.value = res.data.savedQueuesEnabled ?? false;
playKeepsQueue.value = res.data.playKeepsQueue ?? false;
perUserMusicAccounts.value = res.data.perUserMusicAccounts ?? false;
store.savedQueuesEnabled = savedQueuesEnabled.value;
applyGuestModeFromServer(res.data.guestMode);
applyAdminGroupsFromServer(res.data.adminGroups);
@@ -1943,6 +1978,15 @@ async function savePlayKeepsQueue() {
} catch { /* ignore */ }
}
async function savePerUserMusicAccounts() {
try {
const res = await axios.post('/api/bot/settings', {
perUserMusicAccounts: perUserMusicAccounts.value,
});
perUserMusicAccounts.value = res.data.perUserMusicAccounts ?? perUserMusicAccounts.value;
} catch { /* ignore */ }
}
// --- Spotify (Connect) settings (§8) ---
// NOTE: This card's status comes ONLY from /api/spotify/status (playback OAuth
// `authorized`). It is deliberately NOT wired to the player store's
@@ -3383,6 +3427,26 @@ onUnmounted(() => {
line-height: 1.5;
}
// --- Music account pool (admin) ---
.pool-wrap {
margin-top: 8px;
padding-top: 12px;
border-top: 1px dashed var(--border-color);
}
.pool-title {
font-size: 13px;
font-weight: 600;
margin-bottom: 4px;
}
.pool-hint {
font-size: 12px;
color: var(--text-tertiary);
line-height: 1.5;
margin-bottom: 8px;
}
.empty-hint {
font-size: 13px;
color: var(--text-tertiary);