feat(youtube-assign): dedupe by room_id and blacklist detect/ban/purge
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
9b2eef646c
commit
e943e7873b
@ -2582,6 +2582,35 @@ async def yt_assign_set_featured(group_id: str, body: YtAssignFeaturedSet) -> di
|
||||
raise HTTPException(400, str(exc)) from exc
|
||||
|
||||
|
||||
@app.post("/api/youtube/assign/groups/{group_id}/dedupe")
|
||||
async def yt_assign_dedupe(group_id: str) -> dict[str, Any]:
|
||||
try:
|
||||
return yt_assign_db.dedupe_group(group_id)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400, str(exc)) from exc
|
||||
|
||||
|
||||
@app.post("/api/youtube/assign/groups/{group_id}/purge-blacklist")
|
||||
async def yt_assign_purge_blacklist(group_id: str) -> dict[str, Any]:
|
||||
try:
|
||||
return yt_assign_db.purge_blacklisted(group_id, from_pool=True, from_featured=True)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400, str(exc)) from exc
|
||||
|
||||
|
||||
@app.post("/api/youtube/assign/pool/{pool_url_id}/ban")
|
||||
async def yt_assign_ban_pool(pool_url_id: str, body: dict[str, Any] | None = None) -> dict[str, Any]:
|
||||
raw = body or {}
|
||||
try:
|
||||
return yt_assign_db.ban_pool_url(
|
||||
pool_url_id,
|
||||
reason=str(raw.get("reason") or "分配页拉黑"),
|
||||
remove_from_lists=bool(raw.get("remove_from_lists", True)),
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400, str(exc)) from exc
|
||||
|
||||
|
||||
@app.delete("/api/youtube/assign/featured/{featured_id}")
|
||||
async def yt_assign_remove_featured(featured_id: str) -> dict[str, Any]:
|
||||
try:
|
||||
|
||||
@ -163,6 +163,8 @@ def _lookup_cover_and_anchor(conn: sqlite3.Connection, room_id: str) -> tuple[st
|
||||
|
||||
|
||||
def _enrich_pool_row(conn: sqlite3.Connection, row: dict[str, Any]) -> dict[str, Any]:
|
||||
from .db import _is_blacklisted_conn
|
||||
|
||||
out = dict(row)
|
||||
rid = str(out.get("room_id") or "").strip() or extract_room_id(str(out.get("url") or ""))
|
||||
if rid and not out.get("room_id"):
|
||||
@ -175,9 +177,20 @@ def _enrich_pool_row(conn: sqlite3.Connection, row: dict[str, Any]) -> dict[str,
|
||||
out["cover_url"] = found_cover
|
||||
if not title and found_anchor:
|
||||
out["title"] = found_anchor
|
||||
hit = _is_blacklisted_conn(conn, rid, str(out.get("url") or ""))
|
||||
out["blacklisted"] = bool(hit)
|
||||
out["blacklist_reason"] = str((hit or {}).get("reason") or (hit or {}).get("value") or "") if hit else ""
|
||||
out["blacklist_id"] = str((hit or {}).get("id") or "") if hit else ""
|
||||
return out
|
||||
|
||||
|
||||
def _dedupe_key(url: str, room_id: str = "") -> str:
|
||||
rid = (room_id or extract_room_id(url) or "").strip().lower()
|
||||
if rid:
|
||||
return f"rid:{rid}"
|
||||
return f"url:{_normalize_url(url).lower()}"
|
||||
|
||||
|
||||
def _normalize_url(url: str) -> str:
|
||||
return normalize_room_url(str(url or "").strip()) or str(url or "").strip()
|
||||
|
||||
@ -409,14 +422,22 @@ def add_pool_urls(
|
||||
text: str = "",
|
||||
items: list[dict[str, Any]] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
from .db import _is_blacklisted_conn
|
||||
|
||||
parsed: list[dict[str, str]] = []
|
||||
seen: set[str] = set()
|
||||
skipped_dup_in = 0
|
||||
|
||||
def _push(item: dict[str, str]) -> None:
|
||||
nonlocal skipped_dup_in
|
||||
u = str(item.get("url") or "").strip()
|
||||
if not u or u in seen:
|
||||
if not u:
|
||||
return
|
||||
seen.add(u)
|
||||
key = _dedupe_key(u, item.get("room_id") or "")
|
||||
if key in seen:
|
||||
skipped_dup_in += 1
|
||||
return
|
||||
seen.add(key)
|
||||
parsed.append(item)
|
||||
|
||||
for it in items or []:
|
||||
@ -462,6 +483,8 @@ def add_pool_urls(
|
||||
|
||||
now = time.time()
|
||||
created: list[dict[str, Any]] = []
|
||||
skipped_dup = 0
|
||||
skipped_blacklist: list[dict[str, str]] = []
|
||||
with _lock:
|
||||
conn = _connect()
|
||||
try:
|
||||
@ -474,18 +497,29 @@ def add_pool_urls(
|
||||
(group_id,),
|
||||
).fetchone()
|
||||
ord0 = int(max_ord["m"] if max_ord else 0)
|
||||
existing = {
|
||||
str(r["url"])
|
||||
for r in conn.execute(
|
||||
"SELECT url FROM yt_assign_pool_urls WHERE group_id = ?",
|
||||
(group_id,),
|
||||
).fetchall()
|
||||
}
|
||||
existing_keys: set[str] = set()
|
||||
for r in conn.execute(
|
||||
"SELECT url, room_id FROM yt_assign_pool_urls WHERE group_id = ?",
|
||||
(group_id,),
|
||||
).fetchall():
|
||||
existing_keys.add(_dedupe_key(str(r["url"] or ""), str(r["room_id"] or "")))
|
||||
for item in parsed:
|
||||
url = item["url"]
|
||||
if url in existing:
|
||||
continue
|
||||
rid = item.get("room_id") or extract_room_id(url)
|
||||
key = _dedupe_key(url, rid)
|
||||
if key in existing_keys:
|
||||
skipped_dup += 1
|
||||
continue
|
||||
hit = _is_blacklisted_conn(conn, rid, url)
|
||||
if hit:
|
||||
skipped_blacklist.append(
|
||||
{
|
||||
"url": url,
|
||||
"title": str(item.get("title") or ""),
|
||||
"reason": str(hit.get("reason") or hit.get("value") or "黑名单"),
|
||||
}
|
||||
)
|
||||
continue
|
||||
title = str(item.get("title") or "").strip()
|
||||
cover, anchor = _lookup_cover_and_anchor(conn, rid)
|
||||
if not title and anchor:
|
||||
@ -513,12 +547,18 @@ def add_pool_urls(
|
||||
),
|
||||
)
|
||||
created.append({"id": uid, "url": url, "title": title, "cover_url": cover})
|
||||
existing.add(url)
|
||||
existing_keys.add(key)
|
||||
conn.execute("UPDATE yt_assign_groups SET updated_at = ? WHERE id = ?", (now, group_id))
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
return {"ok": True, "added": created, "group": get_group(group_id)}
|
||||
return {
|
||||
"ok": True,
|
||||
"added": created,
|
||||
"skipped_dup": skipped_dup + skipped_dup_in,
|
||||
"skipped_blacklist": skipped_blacklist,
|
||||
"group": get_group(group_id),
|
||||
}
|
||||
|
||||
|
||||
def update_pool_url(pool_url_id: str, **fields: Any) -> dict[str, Any]:
|
||||
@ -579,10 +619,23 @@ def delete_pool_url(pool_url_id: str) -> dict[str, Any]:
|
||||
|
||||
|
||||
def add_featured(group_id: str, pool_url_ids: list[str]) -> dict[str, Any]:
|
||||
from .db import _is_blacklisted_conn
|
||||
|
||||
ids = [str(x).strip() for x in pool_url_ids if str(x).strip()]
|
||||
if not ids:
|
||||
raise ValueError("未选择普通列表 URL")
|
||||
# preserve order, unique
|
||||
seen_ids: set[str] = set()
|
||||
uniq_ids: list[str] = []
|
||||
for pid in ids:
|
||||
if pid in seen_ids:
|
||||
continue
|
||||
seen_ids.add(pid)
|
||||
uniq_ids.append(pid)
|
||||
now = time.time()
|
||||
added = 0
|
||||
skipped_dup = 0
|
||||
skipped_blacklist: list[dict[str, str]] = []
|
||||
with _lock:
|
||||
conn = _connect()
|
||||
try:
|
||||
@ -595,9 +648,20 @@ def add_featured(group_id: str, pool_url_ids: list[str]) -> dict[str, Any]:
|
||||
(group_id,),
|
||||
).fetchone()
|
||||
ord0 = int(max_ord["m"] if max_ord else 0)
|
||||
for pid in ids:
|
||||
# also dedupe by room_id already in featured
|
||||
feat_room_keys: set[str] = set()
|
||||
for r in conn.execute(
|
||||
"""
|
||||
SELECT p.url, p.room_id FROM yt_assign_featured_urls f
|
||||
JOIN yt_assign_pool_urls p ON p.id = f.pool_url_id
|
||||
WHERE f.group_id = ?
|
||||
""",
|
||||
(group_id,),
|
||||
).fetchall():
|
||||
feat_room_keys.add(_dedupe_key(str(r["url"] or ""), str(r["room_id"] or "")))
|
||||
for pid in uniq_ids:
|
||||
pool = conn.execute(
|
||||
"SELECT id FROM yt_assign_pool_urls WHERE id = ? AND group_id = ?",
|
||||
"SELECT * FROM yt_assign_pool_urls WHERE id = ? AND group_id = ?",
|
||||
(pid, group_id),
|
||||
).fetchone()
|
||||
if not pool:
|
||||
@ -607,6 +671,21 @@ def add_featured(group_id: str, pool_url_ids: list[str]) -> dict[str, Any]:
|
||||
(group_id, pid),
|
||||
).fetchone()
|
||||
if exists:
|
||||
skipped_dup += 1
|
||||
continue
|
||||
key = _dedupe_key(str(pool["url"] or ""), str(pool["room_id"] or ""))
|
||||
if key in feat_room_keys:
|
||||
skipped_dup += 1
|
||||
continue
|
||||
hit = _is_blacklisted_conn(conn, str(pool["room_id"] or ""), str(pool["url"] or ""))
|
||||
if hit:
|
||||
skipped_blacklist.append(
|
||||
{
|
||||
"url": str(pool["url"] or ""),
|
||||
"title": str(pool["title"] or ""),
|
||||
"reason": str(hit.get("reason") or hit.get("value") or "黑名单"),
|
||||
}
|
||||
)
|
||||
continue
|
||||
ord0 += 1
|
||||
conn.execute(
|
||||
@ -616,11 +695,165 @@ def add_featured(group_id: str, pool_url_ids: list[str]) -> dict[str, Any]:
|
||||
""",
|
||||
(str(uuid.uuid4()), group_id, pid, ord0, now),
|
||||
)
|
||||
feat_room_keys.add(key)
|
||||
added += 1
|
||||
conn.execute("UPDATE yt_assign_groups SET updated_at = ? WHERE id = ?", (now, group_id))
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
return {"ok": True, "group": get_group(group_id)}
|
||||
return {
|
||||
"ok": True,
|
||||
"added": added,
|
||||
"skipped_dup": skipped_dup,
|
||||
"skipped_blacklist": skipped_blacklist,
|
||||
"group": get_group(group_id),
|
||||
}
|
||||
|
||||
|
||||
def dedupe_group(group_id: str) -> dict[str, Any]:
|
||||
"""Remove duplicate pool/featured entries by room_id (keep earliest)."""
|
||||
now = time.time()
|
||||
pool_removed = 0
|
||||
feat_removed = 0
|
||||
with _lock:
|
||||
conn = _connect()
|
||||
try:
|
||||
ensure_yt_assign_tables(conn)
|
||||
g = conn.execute("SELECT id FROM yt_assign_groups WHERE id = ?", (group_id,)).fetchone()
|
||||
if not g:
|
||||
raise ValueError("分组不存在")
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT id, url, room_id FROM yt_assign_pool_urls
|
||||
WHERE group_id = ?
|
||||
ORDER BY sort_order ASC, created_at ASC
|
||||
""",
|
||||
(group_id,),
|
||||
).fetchall()
|
||||
seen: set[str] = set()
|
||||
drop_pool: list[str] = []
|
||||
for r in rows:
|
||||
key = _dedupe_key(str(r["url"] or ""), str(r["room_id"] or ""))
|
||||
if key in seen:
|
||||
drop_pool.append(str(r["id"]))
|
||||
else:
|
||||
seen.add(key)
|
||||
for pid in drop_pool:
|
||||
conn.execute("DELETE FROM yt_assign_featured_urls WHERE pool_url_id = ?", (pid,))
|
||||
conn.execute("DELETE FROM yt_assign_pool_urls WHERE id = ?", (pid,))
|
||||
pool_removed += 1
|
||||
# featured room_id dedupe (keep earliest featured)
|
||||
frows = conn.execute(
|
||||
"""
|
||||
SELECT f.id AS fid, p.url, p.room_id
|
||||
FROM yt_assign_featured_urls f
|
||||
JOIN yt_assign_pool_urls p ON p.id = f.pool_url_id
|
||||
WHERE f.group_id = ?
|
||||
ORDER BY f.sort_order ASC, f.created_at ASC
|
||||
""",
|
||||
(group_id,),
|
||||
).fetchall()
|
||||
fseen: set[str] = set()
|
||||
for r in frows:
|
||||
key = _dedupe_key(str(r["url"] or ""), str(r["room_id"] or ""))
|
||||
if key in fseen:
|
||||
conn.execute("DELETE FROM yt_assign_featured_urls WHERE id = ?", (str(r["fid"]),))
|
||||
feat_removed += 1
|
||||
else:
|
||||
fseen.add(key)
|
||||
conn.execute("UPDATE yt_assign_groups SET updated_at = ? WHERE id = ?", (now, group_id))
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
return {
|
||||
"ok": True,
|
||||
"pool_removed": pool_removed,
|
||||
"featured_removed": feat_removed,
|
||||
"group": get_group(group_id),
|
||||
}
|
||||
|
||||
|
||||
def purge_blacklisted(group_id: str, *, from_pool: bool = True, from_featured: bool = True) -> dict[str, Any]:
|
||||
"""Remove blacklisted entries from pool and/or featured."""
|
||||
from .db import _is_blacklisted_conn
|
||||
|
||||
now = time.time()
|
||||
pool_removed = 0
|
||||
feat_removed = 0
|
||||
with _lock:
|
||||
conn = _connect()
|
||||
try:
|
||||
ensure_yt_assign_tables(conn)
|
||||
g = conn.execute("SELECT id FROM yt_assign_groups WHERE id = ?", (group_id,)).fetchone()
|
||||
if not g:
|
||||
raise ValueError("分组不存在")
|
||||
if from_featured:
|
||||
frows = conn.execute(
|
||||
"""
|
||||
SELECT f.id AS fid, p.url, p.room_id
|
||||
FROM yt_assign_featured_urls f
|
||||
JOIN yt_assign_pool_urls p ON p.id = f.pool_url_id
|
||||
WHERE f.group_id = ?
|
||||
""",
|
||||
(group_id,),
|
||||
).fetchall()
|
||||
for r in frows:
|
||||
if _is_blacklisted_conn(conn, str(r["room_id"] or ""), str(r["url"] or "")):
|
||||
conn.execute("DELETE FROM yt_assign_featured_urls WHERE id = ?", (str(r["fid"]),))
|
||||
feat_removed += 1
|
||||
if from_pool:
|
||||
prows = conn.execute(
|
||||
"SELECT id, url, room_id FROM yt_assign_pool_urls WHERE group_id = ?",
|
||||
(group_id,),
|
||||
).fetchall()
|
||||
for r in prows:
|
||||
if _is_blacklisted_conn(conn, str(r["room_id"] or ""), str(r["url"] or "")):
|
||||
conn.execute("DELETE FROM yt_assign_featured_urls WHERE pool_url_id = ?", (str(r["id"]),))
|
||||
conn.execute("DELETE FROM yt_assign_pool_urls WHERE id = ?", (str(r["id"]),))
|
||||
pool_removed += 1
|
||||
conn.execute("UPDATE yt_assign_groups SET updated_at = ? WHERE id = ?", (now, group_id))
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
return {
|
||||
"ok": True,
|
||||
"pool_removed": pool_removed,
|
||||
"featured_removed": feat_removed,
|
||||
"group": get_group(group_id),
|
||||
}
|
||||
|
||||
|
||||
def ban_pool_url(pool_url_id: str, *, reason: str = "分配页拉黑", remove_from_lists: bool = True) -> dict[str, Any]:
|
||||
"""Add room to global blacklist; optionally remove from this group's pool/featured."""
|
||||
from . import db
|
||||
|
||||
with _lock:
|
||||
conn = _connect()
|
||||
try:
|
||||
ensure_yt_assign_tables(conn)
|
||||
row = conn.execute("SELECT * FROM yt_assign_pool_urls WHERE id = ?", (pool_url_id,)).fetchone()
|
||||
if not row:
|
||||
raise ValueError("URL 不存在")
|
||||
gid = str(row["group_id"])
|
||||
url = str(row["url"] or "")
|
||||
rid = str(row["room_id"] or "") or extract_room_id(url)
|
||||
title = str(row["title"] or "")
|
||||
finally:
|
||||
conn.close()
|
||||
value = rid or url
|
||||
existing = db.is_blacklisted(rid, url)
|
||||
if existing:
|
||||
bl = existing
|
||||
else:
|
||||
try:
|
||||
bl = db.add_blacklist(value, reason=reason or f"分配页拉黑 {title}".strip())
|
||||
except Exception as exc:
|
||||
# UNIQUE value race / already exists
|
||||
bl = db.is_blacklisted(rid, url) or {"value": value, "error": str(exc)}
|
||||
removed = {"pool_removed": 0, "featured_removed": 0}
|
||||
if remove_from_lists:
|
||||
removed = purge_blacklisted(gid, from_pool=True, from_featured=True)
|
||||
return {"ok": True, "blacklist": bl, **removed, "group": get_group(gid)}
|
||||
|
||||
|
||||
def remove_featured(featured_id: str) -> dict[str, Any]:
|
||||
@ -645,7 +878,17 @@ def remove_featured(featured_id: str) -> dict[str, Any]:
|
||||
|
||||
def set_featured_order(group_id: str, pool_url_ids: list[str]) -> dict[str, Any]:
|
||||
"""Replace featured list order with given pool_url_ids (must belong to pool)."""
|
||||
from .db import _is_blacklisted_conn
|
||||
|
||||
ids = [str(x).strip() for x in pool_url_ids if str(x).strip()]
|
||||
# unique preserve order + room dedupe
|
||||
seen_ids: set[str] = set()
|
||||
uniq: list[str] = []
|
||||
for pid in ids:
|
||||
if pid in seen_ids:
|
||||
continue
|
||||
seen_ids.add(pid)
|
||||
uniq.append(pid)
|
||||
now = time.time()
|
||||
with _lock:
|
||||
conn = _connect()
|
||||
@ -655,19 +898,28 @@ def set_featured_order(group_id: str, pool_url_ids: list[str]) -> dict[str, Any]
|
||||
if not g:
|
||||
raise ValueError("分组不存在")
|
||||
conn.execute("DELETE FROM yt_assign_featured_urls WHERE group_id = ?", (group_id,))
|
||||
for i, pid in enumerate(ids):
|
||||
room_seen: set[str] = set()
|
||||
ord_i = 0
|
||||
for pid in uniq:
|
||||
pool = conn.execute(
|
||||
"SELECT id FROM yt_assign_pool_urls WHERE id = ? AND group_id = ?",
|
||||
"SELECT * FROM yt_assign_pool_urls WHERE id = ? AND group_id = ?",
|
||||
(pid, group_id),
|
||||
).fetchone()
|
||||
if not pool:
|
||||
continue
|
||||
key = _dedupe_key(str(pool["url"] or ""), str(pool["room_id"] or ""))
|
||||
if key in room_seen:
|
||||
continue
|
||||
if _is_blacklisted_conn(conn, str(pool["room_id"] or ""), str(pool["url"] or "")):
|
||||
continue
|
||||
room_seen.add(key)
|
||||
ord_i += 1
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO yt_assign_featured_urls(id, group_id, pool_url_id, sort_order, created_at)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
""",
|
||||
(str(uuid.uuid4()), group_id, pid, i + 1, now),
|
||||
(str(uuid.uuid4()), group_id, pid, ord_i, now),
|
||||
)
|
||||
conn.execute("UPDATE yt_assign_groups SET updated_at = ? WHERE id = ?", (now, group_id))
|
||||
conn.commit()
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
Ban,
|
||||
Copy,
|
||||
Download,
|
||||
Eye,
|
||||
@ -36,6 +37,8 @@ type PoolUrl = {
|
||||
title?: string;
|
||||
room_id?: string;
|
||||
cover_url?: string;
|
||||
blacklisted?: boolean;
|
||||
blacklist_reason?: string;
|
||||
};
|
||||
|
||||
type FeaturedUrl = {
|
||||
@ -46,6 +49,8 @@ type FeaturedUrl = {
|
||||
title?: string;
|
||||
room_id?: string;
|
||||
cover_url?: string;
|
||||
blacklisted?: boolean;
|
||||
blacklist_reason?: string;
|
||||
};
|
||||
|
||||
type AssignGroup = {
|
||||
@ -329,7 +334,83 @@ export function YtAssignPanel({ channels }: { channels: ManagedChannel[] }) {
|
||||
});
|
||||
setPoolDraft("");
|
||||
const n = Array.isArray(r?.added) ? r.added.length : 0;
|
||||
toast.push(`已加入普通列表 ${n} 条`, "ok");
|
||||
const dup = Number(r?.skipped_dup || 0);
|
||||
const bl = Array.isArray(r?.skipped_blacklist) ? r.skipped_blacklist.length : 0;
|
||||
const parts = [`加入 ${n}`];
|
||||
if (dup) parts.push(`去重 ${dup}`);
|
||||
if (bl) parts.push(`黑名单跳过 ${bl}`);
|
||||
toast.push(parts.join(" · "), n || dup || bl ? "ok" : "err");
|
||||
await loadGroups();
|
||||
} catch (e) {
|
||||
toast.push((e as Error).message, "err");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function banPool(poolId: string, label: string) {
|
||||
const ok = await confirm({
|
||||
title: "加入黑名单",
|
||||
message: `将「${label}」加入全局黑名单,并从本分组普通/精选列表移除?`,
|
||||
confirmLabel: "拉黑并移除",
|
||||
destructive: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const r = await fetchJson(`/api/youtube/assign/pool/${poolId}/ban`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ reason: "分配页拉黑", remove_from_lists: true }),
|
||||
});
|
||||
toast.push(
|
||||
`已拉黑(池删 ${r.pool_removed ?? 0} · 精选删 ${r.featured_removed ?? 0})`,
|
||||
"ok"
|
||||
);
|
||||
await loadGroups();
|
||||
} catch (e) {
|
||||
toast.push((e as Error).message, "err");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function dedupeSelected() {
|
||||
if (!selected) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const r = await fetchJson(`/api/youtube/assign/groups/${selected.id}/dedupe`, {
|
||||
method: "POST",
|
||||
});
|
||||
toast.push(
|
||||
`去重完成:池 ${r.pool_removed ?? 0} · 精选 ${r.featured_removed ?? 0}`,
|
||||
"ok"
|
||||
);
|
||||
await loadGroups();
|
||||
} catch (e) {
|
||||
toast.push((e as Error).message, "err");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function purgeBlacklistSelected() {
|
||||
if (!selected) return;
|
||||
const ok = await confirm({
|
||||
title: "移除黑名单项",
|
||||
message: "从本分组普通列表和精选列表中删除所有已命中全局黑名单的条目。",
|
||||
confirmLabel: "清理",
|
||||
destructive: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const r = await fetchJson(`/api/youtube/assign/groups/${selected.id}/purge-blacklist`, {
|
||||
method: "POST",
|
||||
});
|
||||
toast.push(
|
||||
`已清理:池 ${r.pool_removed ?? 0} · 精选 ${r.featured_removed ?? 0}`,
|
||||
"ok"
|
||||
);
|
||||
await loadGroups();
|
||||
} catch (e) {
|
||||
toast.push((e as Error).message, "err");
|
||||
@ -361,10 +442,13 @@ export function YtAssignPanel({ channels }: { channels: ManagedChannel[] }) {
|
||||
if (!selected) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await fetchJson(`/api/youtube/assign/groups/${selected.id}/featured`, {
|
||||
const r = await fetchJson(`/api/youtube/assign/groups/${selected.id}/featured`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ pool_url_id: poolUrlId }),
|
||||
});
|
||||
const bl = Array.isArray(r?.skipped_blacklist) ? r.skipped_blacklist.length : 0;
|
||||
if (bl) toast.push("该房间在黑名单中,未加入精选", "err");
|
||||
else if (Number(r?.skipped_dup || 0) > 0 && !r?.added) toast.push("精选已存在(已去重)", "ok");
|
||||
await loadGroups();
|
||||
} catch (e) {
|
||||
toast.push((e as Error).message, "err");
|
||||
@ -527,7 +611,30 @@ export function YtAssignPanel({ channels }: { channels: ManagedChannel[] }) {
|
||||
/>
|
||||
|
||||
<section className="rounded-2xl border border-white/10 bg-black/25 p-4">
|
||||
<h4 className="mb-3 text-sm font-medium text-slate-100">直播 KEY / 备注</h4>
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<h4 className="text-sm font-medium text-slate-100">直播 KEY / 备注</h4>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => void dedupeSelected()}
|
||||
className="rounded-lg bg-white/5 px-2 py-1 text-[11px] text-slate-200"
|
||||
>
|
||||
一键去重
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => void purgeBlacklistSelected()}
|
||||
className="rounded-lg bg-fuchsia-500/15 px-2 py-1 text-[11px] text-fuchsia-100"
|
||||
>
|
||||
清理黑名单项
|
||||
</button>
|
||||
<Link href="/blacklist" className="rounded-lg bg-white/5 px-2 py-1 text-[11px] text-slate-300">
|
||||
黑名单页 →
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<div className="relative min-w-0 flex-1">
|
||||
<input
|
||||
@ -624,10 +731,15 @@ export function YtAssignPanel({ channels }: { channels: ManagedChannel[] }) {
|
||||
) : (
|
||||
(selected.pool || []).map((u) => {
|
||||
const inFeat = featuredIds.has(u.id);
|
||||
const banned = Boolean(u.blacklisted);
|
||||
return (
|
||||
<div
|
||||
key={u.id}
|
||||
className="flex items-center gap-2 rounded-xl border border-white/10 bg-black/40 p-2"
|
||||
className={`flex items-center gap-2 rounded-xl border p-2 ${
|
||||
banned
|
||||
? "border-fuchsia-500/35 bg-fuchsia-500/10"
|
||||
: "border-white/10 bg-black/40"
|
||||
}`}
|
||||
>
|
||||
<CoverThumb
|
||||
cover={u.cover_url}
|
||||
@ -637,7 +749,14 @@ export function YtAssignPanel({ channels }: { channels: ManagedChannel[] }) {
|
||||
}
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm text-slate-100">{u.title || "未命名主播"}</div>
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<div className="truncate text-sm text-slate-100">{u.title || "未命名主播"}</div>
|
||||
{banned ? (
|
||||
<span className="rounded bg-fuchsia-500/25 px-1.5 text-[10px] text-fuchsia-100">
|
||||
黑名单
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<a
|
||||
href={u.url}
|
||||
target="_blank"
|
||||
@ -646,21 +765,33 @@ export function YtAssignPanel({ channels }: { channels: ManagedChannel[] }) {
|
||||
>
|
||||
{u.url}
|
||||
</a>
|
||||
{banned && u.blacklist_reason ? (
|
||||
<div className="truncate text-[10px] text-fuchsia-200/80">{u.blacklist_reason}</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="flex shrink-0 gap-1">
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy || inFeat}
|
||||
title={inFeat ? "已在精选" : "加入精选"}
|
||||
disabled={busy || inFeat || banned}
|
||||
title={banned ? "已在黑名单" : inFeat ? "已在精选" : "加入精选"}
|
||||
onClick={() => void addFeatured(u.id)}
|
||||
className={`rounded-lg px-2 py-1 text-[11px] ${
|
||||
inFeat
|
||||
? "bg-amber-500/20 text-amber-100"
|
||||
inFeat || banned
|
||||
? "bg-amber-500/20 text-amber-100 opacity-50"
|
||||
: "bg-white/5 text-slate-300 hover:bg-amber-500/15"
|
||||
}`}
|
||||
>
|
||||
<Star className="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
title="加入黑名单"
|
||||
onClick={() => void banPool(u.id, u.title || u.url)}
|
||||
className="rounded-lg bg-fuchsia-500/15 px-2 py-1 text-fuchsia-100"
|
||||
>
|
||||
<Ban className="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
@ -708,42 +839,69 @@ export function YtAssignPanel({ channels }: { channels: ManagedChannel[] }) {
|
||||
从左侧普通列表点星标加入精选
|
||||
</div>
|
||||
) : (
|
||||
(selected.featured || []).map((f, i) => (
|
||||
<div
|
||||
key={f.id}
|
||||
className="flex items-center gap-2 rounded-xl border border-amber-500/25 bg-black/40 p-2"
|
||||
>
|
||||
<span className="shrink-0 rounded bg-amber-500/20 px-1.5 text-[10px] text-amber-100">
|
||||
#{i + 1}
|
||||
</span>
|
||||
<CoverThumb
|
||||
cover={f.cover_url}
|
||||
title={f.title}
|
||||
onOpen={(src) =>
|
||||
setLightbox({ src, title: f.title || "封面", subtitle: f.url })
|
||||
}
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate text-sm text-amber-50">{f.title || "未命名主播"}</div>
|
||||
<a
|
||||
href={f.url || "#"}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="block truncate text-[11px] text-sky-300 hover:underline"
|
||||
>
|
||||
{f.url || f.pool_url_id}
|
||||
</a>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => void removeFeatured(f.id)}
|
||||
className="rounded-lg bg-rose-500/10 px-2 py-1 text-rose-200"
|
||||
(selected.featured || []).map((f, i) => {
|
||||
const banned = Boolean(f.blacklisted);
|
||||
return (
|
||||
<div
|
||||
key={f.id}
|
||||
className={`flex items-center gap-2 rounded-xl border p-2 ${
|
||||
banned
|
||||
? "border-fuchsia-500/35 bg-fuchsia-500/10"
|
||||
: "border-amber-500/25 bg-black/40"
|
||||
}`}
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
</button>
|
||||
</div>
|
||||
))
|
||||
<span className="shrink-0 rounded bg-amber-500/20 px-1.5 text-[10px] text-amber-100">
|
||||
#{i + 1}
|
||||
</span>
|
||||
<CoverThumb
|
||||
cover={f.cover_url}
|
||||
title={f.title}
|
||||
onOpen={(src) =>
|
||||
setLightbox({ src, title: f.title || "封面", subtitle: f.url })
|
||||
}
|
||||
/>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<div className="truncate text-sm text-amber-50">{f.title || "未命名主播"}</div>
|
||||
{banned ? (
|
||||
<span className="rounded bg-fuchsia-500/25 px-1.5 text-[10px] text-fuchsia-100">
|
||||
黑名单
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<a
|
||||
href={f.url || "#"}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="block truncate text-[11px] text-sky-300 hover:underline"
|
||||
>
|
||||
{f.url || f.pool_url_id}
|
||||
</a>
|
||||
</div>
|
||||
<div className="flex shrink-0 gap-1">
|
||||
{f.pool_url_id ? (
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
title="加入黑名单"
|
||||
onClick={() => void banPool(f.pool_url_id, f.title || f.url || "")}
|
||||
className="rounded-lg bg-fuchsia-500/15 px-2 py-1 text-fuchsia-100"
|
||||
>
|
||||
<Ban className="h-3 w-3" />
|
||||
</button>
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => void removeFeatured(f.id)}
|
||||
className="rounded-lg bg-rose-500/10 px-2 py-1 text-rose-200"
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user