lint: napcat.webui

This commit is contained in:
时瑾 2025-11-03 12:58:38 +08:00
parent 9b1ea32808
commit 52c3712200
No known key found for this signature in database
GPG Key ID: 023F70A1B8F8C196
21 changed files with 82 additions and 83 deletions

View File

@ -15,12 +15,12 @@ import { IoAdd, IoRemove } from 'react-icons/io5';
import FileManager from '@/controllers/file_manager';
interface MoveModalProps {
isOpen: boolean
moveTargetPath: string
selectionInfo: string
onClose: () => void
onMove: () => void
onSelect: (dir: string) => void // 新增回调
isOpen: boolean;
moveTargetPath: string;
selectionInfo: string;
onClose: () => void;
onMove: () => void;
onSelect: (dir: string) => void; // 新增回调
}
// 将 DirectoryTree 改为递归组件
@ -30,9 +30,9 @@ function DirectoryTree ({
onSelect,
selectedPath,
}: {
basePath: string
onSelect: (dir: string) => void
selectedPath?: string
basePath: string;
onSelect: (dir: string) => void;
selectedPath?: string;
}) {
const [dirs, setDirs] = useState<string[]>([]);
const [expanded, setExpanded] = useState(false);
@ -112,9 +112,9 @@ function DirectoryTree ({
: (
dirs.map((dirName) => {
const childPath =
basePath === '/' && /^[A-Z]:$/i.test(dirName)
? dirName
: path.join(basePath, dirName);
basePath === '/' && /^[A-Z]:$/i.test(dirName)
? dirName
: path.join(basePath, dirName);
return (
<DirectoryTree
key={childPath}

View File

@ -3,10 +3,10 @@ import { Input } from '@heroui/input';
import { useRef, useState } from 'react';
export interface FileInputProps {
onChange: (file: File) => Promise<void> | void
onDelete?: () => Promise<void> | void
label?: string
accept?: string
onChange: (file: File) => Promise<void> | void;
onDelete?: () => Promise<void> | void;
label?: string;
accept?: string;
}
const FileInput: React.FC<FileInputProps> = ({
@ -34,7 +34,7 @@ const FileInput: React.FC<FileInputProps> = ({
if (file) {
await onChange(file);
}
} catch (_error) {
} catch (error) {
console.error(error);
} finally {
setIsLoading(false);
@ -49,7 +49,7 @@ const FileInput: React.FC<FileInputProps> = ({
try {
setIsLoading(true);
if (onDelete) await onDelete();
} catch (_error) {
} catch (error) {
console.error(error);
} finally {
setIsLoading(false);

View File

@ -51,7 +51,7 @@ const RealTimeLogs = () => {
.join('\r\n');
Xterm.current?.clear();
Xterm.current?.write(_data);
} catch (_error) {
} catch (error) {
console.error(error);
toast.error('获取实时日志失败');
}

View File

@ -20,13 +20,13 @@ const modalTitle = {
export interface NetworkFormModalProps<
T extends keyof OneBotConfig['network']
> {
isOpen: boolean
field: T
data?: OneBotConfig['network'][T][0]
onOpenChange: (isOpen: boolean) => void
isOpen: boolean;
field: T;
data?: OneBotConfig['network'][T][0];
onOpenChange: (isOpen: boolean) => void;
}
const NetworkFormModal = <T extends keyof OneBotConfig['network']>(
const NetworkFormModal = <T extends keyof OneBotConfig['network']> (
props: NetworkFormModalProps<T>
) => {
const { isOpen, onOpenChange, field, data } = props;
@ -41,7 +41,7 @@ const NetworkFormModal = <T extends keyof OneBotConfig['network']>(
await updateNetworkConfig(field, data);
}
toast.success('保存配置成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`保存配置失败: ${msg}`);

View File

@ -23,8 +23,8 @@ import { generateDefaultJson, parse } from '@/utils/zod';
import DisplayStruct from './display_struct';
export interface OneBotApiDebugProps {
path: OneBotHttpApiPath
data: OneBotHttpApiContent
path: OneBotHttpApiPath;
data: OneBotHttpApiContent;
}
const OneBotApiDebug: React.FC<OneBotApiDebugProps> = (props) => {

View File

@ -1,5 +1,4 @@
import { Image } from '@heroui/image';
import React from 'react';
import bkg_color from '@/assets/images/bkg-color.png';

View File

@ -6,8 +6,8 @@ import { LogLevel } from '@/const/enum';
import { serverRequest } from '@/utils/request';
export interface Log {
level: LogLevel
message: string
level: LogLevel;
message: string;
}
export default class WebUIManager {
@ -34,7 +34,7 @@ export default class WebUIManager {
return data.data;
}
public static async proxy<T>(url = '') {
public static async proxy<T> (url = '') {
const data = await serverRequest.get<ServerResponse<string>>(
'/base/proxy?url=' + encodeURIComponent(url)
);
@ -100,7 +100,7 @@ export default class WebUIManager {
const data = JSON.parse(event.data);
data.message = data.message.replace(/\n/g, '\r\n');
writer([data]);
} catch (_error) {
} catch (error) {
console.error(error);
}
};
@ -134,7 +134,7 @@ export default class WebUIManager {
try {
const data = JSON.parse(event.data) as SystemStatus;
writer(data);
} catch (_error) {
} catch (error) {
console.error(error);
}
};

View File

@ -42,7 +42,7 @@ const findTitle = (menus: MenuItem[], pathname: string): string[] => {
return paths;
};
const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
const location = useLocation();
const contentRef = useRef<HTMLDivElement>(null);
const [openSideBar, setOpenSideBar] = useLocalStorage(key.sideBarOpen, true);

View File

@ -42,7 +42,7 @@ const ChangePasswordCard = () => {
setToken('');
localStorage.removeItem(key.token);
navigate('/web_login');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`修改失败: ${msg}`);
}

View File

@ -22,7 +22,7 @@ const LoginConfigCard = () => {
formState: { isSubmitting },
setValue: setOnebotValue,
} = useForm<{
quickLoginQQ: string
quickLoginQQ: string;
}>({
defaultValues: {
quickLoginQQ: '',
@ -37,7 +37,7 @@ const LoginConfigCard = () => {
try {
await QQManager.setQuickLoginQQ(data.quickLoginQQ);
toast.success('保存成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`保存失败: ${msg}`);
}
@ -47,7 +47,7 @@ const LoginConfigCard = () => {
try {
await refreshQuickLogin();
toast.success('刷新成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`刷新失败: ${msg}`);
}

View File

@ -34,7 +34,7 @@ const OneBotConfigCard = () => {
try {
await saveConfigWithoutNetwork(data);
toast.success('保存成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`保存失败: ${msg}`);
}
@ -45,7 +45,7 @@ const OneBotConfigCard = () => {
setLoading(true);
await refreshConfig();
if (shotTip) toast.success('刷新成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`刷新失败: ${msg}`);
} finally {

View File

@ -53,7 +53,7 @@ const ServerConfigCard = () => {
try {
await WebUIManager.updateWebUIConfig(data);
toast.success('保存成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`保存失败: ${msg}`);
}
@ -63,7 +63,7 @@ const ServerConfigCard = () => {
try {
await refreshConfig();
toast.success('刷新成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`刷新失败: ${msg}`);
}

View File

@ -21,8 +21,8 @@ import { colorKeys, generateTheme, loadTheme } from '@/utils/theme';
import WebUIManager from '@/controllers/webui_manager';
export type PreviewThemeCardProps = {
theme: ThemeInfo
onPreview: () => void
theme: ThemeInfo;
onPreview: () => void;
};
const values = [
@ -110,7 +110,7 @@ const ThemeConfigCard = () => {
formState: { isSubmitting },
setValue: setOnebotValue,
} = useForm<{
theme: ThemeConfig
theme: ThemeConfig;
}>({
defaultValues: {
theme: {
@ -146,7 +146,7 @@ const ThemeConfigCard = () => {
await WebUIManager.setThemeConfig(data.theme);
toast.success('保存成功');
loadTheme();
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`保存失败: ${msg}`);
}
@ -156,7 +156,7 @@ const ThemeConfigCard = () => {
try {
await refreshAsync();
toast.success('刷新成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`刷新失败: ${msg}`);
}

View File

@ -48,7 +48,7 @@ const WebUIConfigCard = () => {
setCustomIcons(data.customIcons);
setB64img(data.background);
toast.success('保存成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`保存失败: ${msg}`);
}
@ -74,7 +74,7 @@ const WebUIConfigCard = () => {
setTimeout(() => {
window.location.reload();
}, 1000);
} catch (_error) {
} catch (error) {
toast.error('上传失败: ' + (error as Error).message);
}
}}
@ -85,7 +85,7 @@ const WebUIConfigCard = () => {
setTimeout(() => {
window.location.reload();
}, 1000);
} catch (_error) {
} catch (error) {
toast.error('删除失败: ' + (error as Error).message);
}
}}

View File

@ -41,8 +41,8 @@ export default function FileManagerPage () {
currentPath = currentPath.slice(1);
}
const [editingFile, setEditingFile] = useState<{
path: string
content: string
path: string;
content: string;
} | null>(null);
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const [newFileName, setNewFileName] = useState('');
@ -175,7 +175,7 @@ export default function FileManagerPage () {
setIsCreateModalOpen(false);
setNewFileName('');
loadFiles();
} catch (_error) {
} catch (error) {
toast.error((error as Error)?.message || '创建失败');
}
};

View File

@ -29,7 +29,7 @@ export default function LogsPage () {
try {
const result = await WebUIManager.getLogContent(selectedLog);
setLogContent(result);
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`加载日志失败: ${msg}`);
} finally {

View File

@ -19,21 +19,21 @@ import useConfig from '@/hooks/use-config';
import useDialog from '@/hooks/use-dialog';
export interface SectionProps {
title: string
title: string;
color?:
| 'violet'
| 'yellow'
| 'blue'
| 'cyan'
| 'green'
| 'pink'
| 'foreground'
icon: React.ReactNode
children: React.ReactNode
| 'violet'
| 'yellow'
| 'blue'
| 'cyan'
| 'green'
| 'pink'
| 'foreground';
icon: React.ReactNode;
children: React.ReactNode;
}
export interface EmptySectionProps {
isEmpty: boolean
isEmpty: boolean;
}
const EmptySection: React.FC<EmptySectionProps> = ({ isEmpty }) => {
@ -84,7 +84,7 @@ export default function NetworkPage () {
try {
await refreshConfig();
setLoading(false);
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`获取配置失败: ${msg}`);
@ -112,7 +112,7 @@ export default function NetworkPage () {
await deleteNetworkConfig(field, name);
toast.success('删除配置成功');
resolve();
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`删除配置失败: ${msg}`);
@ -134,7 +134,7 @@ export default function NetworkPage () {
try {
await enableNetworkConfig(field, name);
toast.success('更新配置成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`更新配置失败: ${msg}`);
@ -150,7 +150,7 @@ export default function NetworkPage () {
try {
await enableDebugNetworkConfig(field, name);
toast.success('更新配置成功');
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`更新配置失败: ${msg}`);
@ -165,7 +165,7 @@ export default function NetworkPage () {
onOpen();
};
const renderCard = <T extends keyof OneBotConfig['network']>(
const renderCard = <T extends keyof OneBotConfig['network']> (
type: T,
item: OneBotConfig['network'][T][0],
showType = false

View File

@ -23,8 +23,8 @@ import { TerminalInstance } from '@/components/terminal/terminal-instance';
import terminalManager from '@/controllers/terminal_manager';
interface TerminalTab {
id: string
title: string
id: string;
title: string;
}
export default function TerminalPage () {

View File

@ -34,7 +34,7 @@ export default function QQLoginPage () {
setIsLoading(true);
try {
await QQManager.setQuickLogin(uinValue);
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`快速登录QQ失败: ${msg}`);
@ -60,7 +60,7 @@ export default function QQLoginPage () {
} else {
setQrcode(data.qrcodeurl);
}
} catch (_error) {
} catch (error) {
const msg = (error as Error).message;
toast.error(`获取二维码失败: ${msg}`);
@ -82,7 +82,7 @@ export default function QQLoginPage () {
setQQList(qqList);
} catch (_error) {
const msg = (error as Error).message;
const msg = (_error as Error).message;
toast.error(`获取QQ列表失败: ${msg}`);
}

View File

@ -39,7 +39,7 @@ export default function WebLoginPage () {
setLocalToken(data);
navigate('/qq_login', { replace: true });
}
} catch (_error) {
} catch (error) {
toast.error((error as Error).message);
} finally {
setIsLoading(false);

View File

@ -4,14 +4,14 @@
"type": "module",
"version": "4.9.21",
"scripts": {
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
"build:shell": "npm run build:webui && vite build --mode shell || exit 1",
"build:universal": "npm run build:webui && npm run dev:universal || exit 1",
"build:framework": "npm run build:webui && npm run dev:framework || exit 1",
"build:shell": "npm run build:webui && npm run dev:shell || exit 1",
"build:webui": "cd napcat.webui && npm run build",
"dev:universal": "vite build --mode universal",
"dev:framework": "vite build --mode framework",
"dev:shell": "vite build --mode shell",
"dev:shell-analysis": "vite build --mode shell-analysis",
"dev:universal": "tsc --noEmit && vite build --mode universal",
"dev:framework": "tsc --noEmit && vite build --mode framework",
"dev:shell": "tsc --noEmit && vite build --mode shell",
"dev:shell-analysis": "tsc --noEmit && vite build --mode shell-analysis",
"dev:webui": "cd napcat.webui && npm run dev",
"tsc": "npm run tsc:core && npm run tsc:webui",
"tsc:core": "tsc --noEmit",