* feat(web): multi-user accounts with fixed admin/operator/viewer roles - migration 6 adds web_users and copies the existing single admin with the same id and password hash, so upgrades need no action and existing sessions stay logged in - table-driven permission middleware on every business route (default deny), 403 for missing permission, 401 when logged out - hooks/override and secrets redacted for non-admins; operators may only pick registered bilibili accounts for templates - /v1/web-users management API, /v1/me and self password change - login rate limit: 5 consecutive failures lock the username for 30s - revoked sessions cut long-lived websocket/stream responses Refs #1717 * feat(cli): add `biliup user list` and `biliup user reset-password` Refs #1717 * feat(web-ui): user management page, account menu and editable login name - /users page (super admin only): create users, change role, reset password, disable, force logout, delete; table on desktop, cards on mobile, with loading/empty/error states - sidebar filters menu entries by the permissions from /v1/me and shows a no-access state for pages the role cannot open - account menu in the sidebar footer with change password and logout, hidden when --auth is off - 403 responses show a warning toast instead of redirecting - login page username is editable (default biliup) Refs #1717 * feat(web-ui): hide actions the current role cannot perform Streamer add/edit/delete/pause, hook and override editing, template and upload actions, bilibili account management and config saving are only rendered for roles that have the matching permission. Account and type tree requests are skipped for roles that would get 403. Refs #1717 * fix(web-ui): wait for permissions on restricted pages, surface pause errors - pages that need a permission not every role has render a spinner until /v1/me returns, so roles without it never fire requests doomed to 403 - user management is hidden when --auth is off, with an explanation if the page is opened directly - the pause button goes through the shared response handler, so a 403 shows the permission toast instead of failing silently - permission errors sent as plain text keep their message Refs #1717 * fix(web-ui): keep user actions reachable on tablet and narrow desktop Refs #1717 * fix(py): handle the user subcommand in the stream-gears entry point Refs #1717
48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { useSWRConfig } from 'swr';
|
|
import useSWRMutation from 'swr/mutation';
|
|
import {Button} from "@douyinfe/semi-ui";
|
|
import type {ButtonProps} from "@douyinfe/semi-ui/lib/es/button";
|
|
import {IconPause, IconPlay} from "@douyinfe/semi-icons";
|
|
import {LiveStreamerEntity, proxy} from "@/app/lib/api-streamer";
|
|
|
|
interface PauseButtonProps extends Omit<ButtonProps, 'onClick' | 'icon' | 'theme' | 'onError'> {
|
|
streamer: LiveStreamerEntity;
|
|
onSuccess?: () => void;
|
|
onError?: (error: Error) => void;
|
|
}
|
|
|
|
// 暂停主播
|
|
// 走统一的响应处理:未登录跳转登录页,没有权限时提示,其它失败抛给调用方
|
|
export const pauseStreamer = (url: string) => proxy(url, { method: 'PUT' });
|
|
|
|
export const PauseButton: React.FC<PauseButtonProps> = ({
|
|
streamer,
|
|
onSuccess,
|
|
onError,
|
|
type = 'tertiary',
|
|
...rest
|
|
}) => {
|
|
const { mutate } = useSWRConfig();
|
|
|
|
const { trigger: pauseTrigger } = useSWRMutation(
|
|
`/v1/streamers/${streamer.id}/pause`,
|
|
pauseStreamer
|
|
);
|
|
|
|
const handlePause = async () => {
|
|
try {
|
|
await pauseTrigger();
|
|
// 重新加载列表数据
|
|
await mutate('/v1/streamers');
|
|
onSuccess?.();
|
|
} catch (error) {
|
|
console.error('暂停失败:', error);
|
|
onError?.(error as Error);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Button onClick={handlePause} icon={streamer.status === 'Pause'? <IconPlay />: <IconPause />} theme="borderless" type={type} aria-label="暂停" {...rest} />
|
|
);
|
|
}; |