Skip to content

Commit

Permalink
fix(web): 修复web项目的lint工具 (#1349)
Browse files Browse the repository at this point in the history
web项目现在已经可以正常使用eslint 9进行lint。
  • Loading branch information
ddadaal authored Jul 9, 2024
1 parent 0275a9e commit 8463268
Show file tree
Hide file tree
Showing 231 changed files with 1,844 additions and 1,553 deletions.
25 changes: 23 additions & 2 deletions apps/ai/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
/**
* Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy
* SCOW is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

const base = require("../../eslint.config");
const react = require("@ddadaal/eslint-config/react");

module.export = {
module.exports = [
...base,
...react,
};
{
rules: {
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/only-throw-error": "off",
"@typescript-eslint/prefer-promise-reject-errors": "off",
}
}
];
3 changes: 0 additions & 3 deletions apps/ai/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ export default async () => {
// });
return config;
},
compiler: {
styledComponents: true,
},
skipTrailingSlashRedirect: true,
transpilePackages: ["antd", "@ant-design/icons"],
};
Expand Down
13 changes: 7 additions & 6 deletions apps/ai/src/app/(auth)/algorithm/AlgorithmVersionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const AlgorithmVersionList: React.FC<Props> = (
versionDescription:r.versionDescription,
}}
>
编辑
编辑
</EditVersionModalButton>
<Button
type="link"
Expand All @@ -168,7 +168,7 @@ export const AlgorithmVersionList: React.FC<Props> = (
}
}}
>
查看文件
查看文件
</Button>
<Button
type="link"
Expand All @@ -178,16 +178,17 @@ export const AlgorithmVersionList: React.FC<Props> = (
title: "分享算法版本",
content: `确认${getSharedStatusText(r.sharedStatus)}算法版本 ${r.versionName}?`,
onOk: async () => {
r.sharedStatus === SharedStatus.SHARED ?
if (r.sharedStatus === SharedStatus.SHARED) {
await unShareMutation.mutateAsync({
algorithmVersionId: r.id,
algorithmId,
})
:
});
} else {
await shareMutation.mutateAsync({
algorithmVersionId: r.id,
algorithmId,
});
}
},
});
}}
Expand All @@ -201,7 +202,7 @@ export const AlgorithmVersionList: React.FC<Props> = (
deleteAlgorithmVersion(r.id);
}}
>
删除
删除
</Button>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions apps/ai/src/app/(auth)/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const PublicConfigContext = React.createContext<{
defaultCluster: Cluster;
setDefaultCluster: (cluster: Cluster) => void;
removeDefaultCluster: () => void;
}
}>(undefined!);
}
}>(undefined!);

export const usePublicConfig = () => {
return useContext(PublicConfigContext);
Expand Down
19 changes: 12 additions & 7 deletions apps/ai/src/app/(auth)/dataset/CreateEditDSVersionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,25 @@ export const CreateEditDSVersionModal: React.FC<Props> = (
const onOk = async () => {
form.validateFields();
const { versionName, versionDescription, path } = await form.validateFields();
isEdit && editData ? editMutation.mutate({
datasetVersionId: editData.id,
versionName,
versionDescription,
datasetId: editData.datasetId,
})
: createMutation.mutate({

if (isEdit && editData) {
editMutation.mutate({
datasetVersionId: editData.id,
versionName,
versionDescription,
datasetId: editData.datasetId,
});
} else {
createMutation.mutate({
versionName,
versionDescription,
path,
datasetId,
});
}
};


return (
<Modal
title={isEdit ? "编辑版本" : "创建新版本"}
Expand Down
27 changes: 17 additions & 10 deletions apps/ai/src/app/(auth)/dataset/CreateEditDatasetModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ export const CreateEditDatasetModal: React.FC<Props> = (
}, []);

const resetForm = () => {
isEdit && editData ?
if (isEdit && editData) {
form.setFieldsValue({
type: editData.type,
scene: editData.scene,
}) : form.setFieldsValue({
});
} else {
form.setFieldsValue({
type: DatasetType.IMAGE,
scene: SceneType.CWS,
});
}
};

const createMutation = trpc.dataset.createDataset.useMutation({
Expand Down Expand Up @@ -117,20 +120,24 @@ export const CreateEditDatasetModal: React.FC<Props> = (

const onOk = async () => {
const { name, type, description, scene, cluster } = await form.validateFields();
(isEdit && editData) ? editMutation.mutate({
id: editData.id,
name,
type,
scene,
description,
})
: createMutation.mutate({
if (isEdit && editData) {

editMutation.mutate({
id: editData.id,
name,
type,
scene,
description,
});
} else {
createMutation.mutate({
name,
clusterId: cluster.id,
type,
description,
scene,
});
}
};

return (
Expand Down
6 changes: 3 additions & 3 deletions apps/ai/src/app/(auth)/dataset/DatasetListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface Props {
const FilterType = {
ALL: "全部",
...DatasetTypeText,
} as { [key: string]: string };
} as Record<string, string>;

type FilterTypeKeys = Extract<keyof typeof FilterType, string>;

Expand All @@ -52,8 +52,8 @@ interface FilterForm {
}

interface PageInfo {
page: number;
pageSize?: number;
page: number;
pageSize?: number;
}

const CreateDatasetModalButton = ModalButton(CreateEditDatasetModal, { type: "primary", icon: <PlusOutlined /> });
Expand Down
9 changes: 5 additions & 4 deletions apps/ai/src/app/(auth)/dataset/DatasetVersionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const DatasetVersionList: React.FC<Props> = (
editData={r}
refetch={refetch}
>
编辑
编辑
</CreateEditVersionModalButton>
<Button
type="link"
Expand All @@ -171,16 +171,17 @@ export const DatasetVersionList: React.FC<Props> = (
title: "分享数据集版本",
content: `确认${getSharedStatusText(r.sharedStatus)}数据集版本 ${r.versionName}?`,
onOk: async () => {
r.sharedStatus === SharedStatus.SHARED ?
if (r.sharedStatus === SharedStatus.SHARED) {
await unShareMutation.mutateAsync({
datasetVersionId: r.id,
datasetId: r.datasetId,
})
:
});
} else {
await shareMutation.mutateAsync({
datasetVersionId: r.id,
datasetId: r.datasetId,
});
}
},
});
}}
Expand Down
2 changes: 1 addition & 1 deletion apps/ai/src/app/(auth)/files/CreateFileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const CreateFileModal: React.FC<Props> = ({ open, onClose, path, reload,
<Form.Item label="要创建的文件的目录">
<strong>{path}</strong>
</Form.Item>
<Form.Item<FormProps> label="文件名" name="newFileName" rules={[{ required: true }]}>
<Form.Item label="文件名" name="newFileName" rules={[{ required: true }]}>
<Input />
</Form.Item>
</Form>
Expand Down
10 changes: 8 additions & 2 deletions apps/ai/src/app/(auth)/files/FileManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export const FileManager: React.FC<Props> = ({ cluster, loginNodes, path, urlPre
<div>
<TitleText>
<span>
集群{getI18nConfigCurrentText(cluster.name, undefined)}文件管理
集群{getI18nConfigCurrentText(cluster.name, undefined)}文件管理
</span>
</TitleText>
<TopBar>
Expand All @@ -280,7 +280,13 @@ export const FileManager: React.FC<Props> = ({ cluster, loginNodes, path, urlPre
<PathBar
path={path}
loading={filesQuery.isFetching}
onPathChange={(curPath) => { curPath === path ? reload() : router.push(fullUrl(curPath)); }}
onPathChange={(curPath) => {
if (curPath === path) {
reload();
} else {
router.push(fullUrl(curPath));
}
}}
breadcrumbItemRender={(pathSegment, index, path) =>
(index === 0 ? (
<Link href={fullUrl("/")} title="/" onClick={(e) => e.stopPropagation()}>
Expand Down
2 changes: 1 addition & 1 deletion apps/ai/src/app/(auth)/files/RenameModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const RenameModal: React.FC<Props> = ({ open, onClose, path, reload, clus
<Form.Item label="要重命名的文件">
<strong>{path}</strong>
</Form.Item>
<Form.Item<FormProps> label="新文件名" name="newFileName" rules={[{ required: true }]}>
<Form.Item label="新文件名" name="newFileName" rules={[{ required: true }]}>
<Input />
</Form.Item>
</Form>
Expand Down
10 changes: 8 additions & 2 deletions apps/ai/src/app/(auth)/files/[cluster]/[[...path]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@

"use client";

import { getI18nConfigCurrentText } from "@scow/lib-web/build/utils/systemLanguage";
import { useRouter } from "next/navigation";
import { join } from "path";
import { useEffect, useMemo } from "react";
import { usePublicConfig } from "src/app/(auth)/context";
import { FileManager } from "src/app/(auth)/files/FileManager";
import { useI18n } from "src/i18n";
import { NotFoundPage } from "src/layouts/error/NotFoundPage";
import { Head } from "src/utils/head";
import { trpc } from "src/utils/trpc";

export default function Page({ params }: { params: { cluster: string; resourceId: string; path: string[] }}) {
export default function Page({ params }: { params: { cluster: string; resourceId: string; path: string[] } }) {

const router = useRouter();

Expand Down Expand Up @@ -55,9 +57,13 @@ export default function Page({ params }: { params: { cluster: string; resourceId

const clusterObj = clusters.find((x) => x.id === cluster);

const i18n = useI18n();

const i18nClusterName = getI18nConfigCurrentText(clusterObj?.name ?? cluster, i18n.currentLanguage.id);

return (
<>
<Head title={`${clusters.find((x) => x.id === cluster)?.name ?? cluster}文件管理`} />
<Head title={`${i18nClusterName}文件管理`} />
{
clusterObj ? (
<FileManager
Expand Down
2 changes: 1 addition & 1 deletion apps/ai/src/app/(auth)/files/[cluster]/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface Operation {
export const OperationContext = React.createContext<{
operation: Operation | undefined,
setOperation: Dispatch<SetStateAction<Operation | undefined>>;
}>(undefined!);
}>(undefined!);

export const useOperation = () => {
return useContext(OperationContext);
Expand Down
16 changes: 6 additions & 10 deletions apps/ai/src/app/(auth)/files/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,16 @@ export async function POST(request: NextRequest) {
return await sshConnect(host, user.identityId, logger, async (ssh) => {
const sftp = await ssh.requestSFTP();

try {
const writeStream = sftp.createWriteStream(path);
const writeStream = sftp.createWriteStream(path);

const pipelineAsync = promisify(pipeline);
const pipelineAsync = promisify(pipeline);

const readableStream = uploadedFile.stream();
const nodeReadableStream = readableStreamToNodeReadable(readableStream);
await pipelineAsync(nodeReadableStream, writeStream);
const readableStream = uploadedFile.stream();
const nodeReadableStream = readableStreamToNodeReadable(readableStream);
await pipelineAsync(nodeReadableStream, writeStream);

return NextResponse.json({ message: "success" }, { status: 200 });
return NextResponse.json({ message: "success" }, { status: 200 });

} catch (e: any) {

}
});

}
Expand Down
Loading

0 comments on commit 8463268

Please sign in to comment.