From 879523d261328f9e37eefa041e9873a7470e5304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Mon, 28 Aug 2023 23:31:31 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E4=BC=98=E5=8C=96=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yaml | 1 + .github/workflows/test.yaml | 1 + package-lock.json | 18 +- package.json | 4 +- src/app/service/permission/controller.ts | 8 + src/locales/en-US/translation.yaml | 1 + src/locales/zh-CN/translation.yaml | 3 + src/manifest.json | 2 +- src/pages/components/ScriptSetting/Match.tsx | 4 +- .../components/ScriptSetting/Permission.tsx | 198 ++++++++++++++++++ src/pages/components/ScriptSetting/index.tsx | 79 +------ .../options/routes/script/ScriptEditor.tsx | 2 +- src/runtime/background/permission_verify.ts | 31 ++- 13 files changed, 261 insertions(+), 91 deletions(-) create mode 100644 src/pages/components/ScriptSetting/Permission.tsx diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e3c0fbf6..a77cf2d1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - release/* - dev jobs: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ae25ff4b..cd6864e8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,6 +4,7 @@ on: push: branches: - main + - release/* - dev - develop/* pull_request: diff --git a/package-lock.json b/package-lock.json index 93ff8b6d..515bd19d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "scriptcat", - "version": "0.16.0", + "version": "0.15.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scriptcat", - "version": "0.16.0", + "version": "0.15.1", "license": "GPLv3", "dependencies": { - "@arco-design/web-react": "^2.47.0", + "@arco-design/web-react": "^2.51.1", "@dnd-kit/core": "^6.0.5", "@dnd-kit/sortable": "^7.0.1", "@dnd-kit/utilities": "^3.2.0", @@ -181,9 +181,9 @@ } }, "node_modules/@arco-design/web-react": { - "version": "2.49.0", - "resolved": "https://registry.npmjs.org/@arco-design/web-react/-/web-react-2.49.0.tgz", - "integrity": "sha512-g+B8d8am2inpMd3zGoWZ8TNDBDFZO2AiTzZurN+2q69bzpbsbiX41BG8ujV4GQPJSAt/GVGini0Hv8+LzQdmtw==", + "version": "2.52.0", + "resolved": "https://registry.npmjs.org/@arco-design/web-react/-/web-react-2.52.0.tgz", + "integrity": "sha512-c5DkPUj6F9fTaUqwKz0mYhYcoVLbCcC9VDt/hJammc94qVk9tFsiGhISSan4nhDQVIql5oWqlmdjE7eJqBDiLQ==", "dependencies": { "@arco-design/color": "^0.4.0", "@babel/runtime": "^7.5.5", @@ -17765,9 +17765,9 @@ } }, "@arco-design/web-react": { - "version": "2.49.0", - "resolved": "https://registry.npmjs.org/@arco-design/web-react/-/web-react-2.49.0.tgz", - "integrity": "sha512-g+B8d8am2inpMd3zGoWZ8TNDBDFZO2AiTzZurN+2q69bzpbsbiX41BG8ujV4GQPJSAt/GVGini0Hv8+LzQdmtw==", + "version": "2.52.0", + "resolved": "https://registry.npmjs.org/@arco-design/web-react/-/web-react-2.52.0.tgz", + "integrity": "sha512-c5DkPUj6F9fTaUqwKz0mYhYcoVLbCcC9VDt/hJammc94qVk9tFsiGhISSan4nhDQVIql5oWqlmdjE7eJqBDiLQ==", "requires": { "@arco-design/color": "^0.4.0", "@babel/runtime": "^7.5.5", diff --git a/package.json b/package.json index 19f2a5d4..9182ff84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scriptcat", - "version": "0.16.0", + "version": "0.15.1", "description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!", "author": "CodFrm", "license": "GPLv3", @@ -16,7 +16,7 @@ "changlog": "gitmoji-changelog" }, "dependencies": { - "@arco-design/web-react": "^2.47.0", + "@arco-design/web-react": "^2.51.1", "@dnd-kit/core": "^6.0.5", "@dnd-kit/sortable": "^7.0.1", "@dnd-kit/utilities": "^3.2.0", diff --git a/src/app/service/permission/controller.ts b/src/app/service/permission/controller.ts index 2c3cbb0c..cdc8a348 100644 --- a/src/app/service/permission/controller.ts +++ b/src/app/service/permission/controller.ts @@ -45,4 +45,12 @@ export default class PermissionController { confirm, }); } + + // 添加权限 + addPermission(scriptId: number, permission: Permission) { + return this.msg.syncSend("addPermission", { + scriptId, + permission, + }); + } } diff --git a/src/locales/en-US/translation.yaml b/src/locales/en-US/translation.yaml index 1bdb7f36..e8fe5788 100644 --- a/src/locales/en-US/translation.yaml +++ b/src/locales/en-US/translation.yaml @@ -198,6 +198,7 @@ script_setting: Script Setting basic_info: Basic Information update_url: Update URL permission_management: Permission Management +add_permission: Add Permission # Script Setting Match ScriptSetting/Match match: Match user_setting: User Setting diff --git a/src/locales/zh-CN/translation.yaml b/src/locales/zh-CN/translation.yaml index 655d614a..6718070d 100644 --- a/src/locales/zh-CN/translation.yaml +++ b/src/locales/zh-CN/translation.yaml @@ -199,6 +199,9 @@ script_setting: 脚本设置 basic_info: 基本信息 update_url: 更新URL permission_management: 授权管理 +add_permission: 添加授权 +permission_cors: 跨域(cors) +permission_cookie: 管理cookie # 脚本设置Match ScriptSetting/Match match: 匹配 user_setting: 用户设定 diff --git a/src/manifest.json b/src/manifest.json index e354bd9f..95f20a7f 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "ScriptCat", - "version": "0.16.0", + "version": "0.15.1", "author": "CodFrm", "description": "脚本猫,一个用户脚本管理器,支持后台脚本、定时脚本、页面脚本,可编写脚本每天帮你自动处理事务.", "options_ui": { diff --git a/src/pages/components/ScriptSetting/Match.tsx b/src/pages/components/ScriptSetting/Match.tsx index fcfdbc4f..4f0b0bad 100644 --- a/src/pages/components/ScriptSetting/Match.tsx +++ b/src/pages/components/ScriptSetting/Match.tsx @@ -289,7 +289,7 @@ const Match: React.FC<{ - +
{t("website_exclude")} @@ -318,7 +318,7 @@ const Match: React.FC<{
-
+
); diff --git a/src/pages/components/ScriptSetting/Permission.tsx b/src/pages/components/ScriptSetting/Permission.tsx new file mode 100644 index 00000000..7ea21411 --- /dev/null +++ b/src/pages/components/ScriptSetting/Permission.tsx @@ -0,0 +1,198 @@ +import React, { useEffect, useState } from "react"; +import { Permission } from "@App/app/repo/permission"; +import { Script } from "@App/app/repo/scripts"; +import { useTranslation } from "react-i18next"; +import IoC from "@App/app/ioc"; +import PermissionController from "@App/app/service/permission/controller"; +import { + Space, + Popconfirm, + Message, + Button, + Checkbox, + Input, + Modal, + Select, + Typography, +} from "@arco-design/web-react"; +import Table, { ColumnProps } from "@arco-design/web-react/es/Table"; +import { IconDelete } from "@arco-design/web-react/icon"; +import ScriptController from "@App/app/service/script/controller"; + +const PermissionManager: React.FC<{ + script: Script; +}> = ({ script }) => { + const permissionCtrl = IoC.instance( + PermissionController + ) as PermissionController; + const scriptCtrl = IoC.instance(ScriptController) as ScriptController; + const [permission, setPermission] = useState([]); + const [permissionVisible, setPermissionVisible] = useState(false); + const [permissionValue, setPermissionValue] = useState(); + + const { t } = useTranslation(); + + const columns: ColumnProps[] = [ + { + title: t("type"), + dataIndex: "permission", + key: "permission", + width: 100, + }, + { + title: t("permission_value"), + dataIndex: "permissionValue", + key: "permissionValue", + }, + { + title: t("allow"), + dataIndex: "allow", + key: "allow", + render(col) { + if (col) { + return {t("yes")}; + } + return {t("no")}; + }, + }, + { + title: t("action"), + render(_, item: Permission) { + return ( + + { + permissionCtrl + .deletePermission(script!.id, { + permission: item.permission, + permissionValue: item.permissionValue, + }) + .then(() => { + Message.success(t("delete_success")!); + setPermission(permission.filter((i) => i.id !== item.id)); + }) + .catch(() => { + Message.error(t("delete_failed")!); + }); + }} + > + + { + scriptCtrl.resetExclude(script.id, undefined).then(() => {}); + }} + > + + + + +
+ + ); +}; + +export default PermissionManager; diff --git a/src/pages/components/ScriptSetting/index.tsx b/src/pages/components/ScriptSetting/index.tsx index 33493358..51cfabbc 100644 --- a/src/pages/components/ScriptSetting/index.tsx +++ b/src/pages/components/ScriptSetting/index.tsx @@ -1,104 +1,36 @@ import IoC from "@App/app/ioc"; -import { Permission } from "@App/app/repo/permission"; import { Script } from "@App/app/repo/scripts"; -import PermissionController from "@App/app/service/permission/controller"; import { formatUnixTime } from "@App/pkg/utils/utils"; import { - Button, Descriptions, Divider, Drawer, Empty, Input, Message, - Popconfirm, - Space, - Table, - Typography, } from "@arco-design/web-react"; -import { ColumnProps } from "@arco-design/web-react/es/Table"; -import { IconDelete } from "@arco-design/web-react/icon"; import React, { useEffect, useState } from "react"; import ScriptController from "@App/app/service/script/controller"; import { useTranslation } from "react-i18next"; import Match from "./Match"; +import PermissionManager from "./Permission"; const ScriptSetting: React.FC<{ - // eslint-disable-next-line react/require-default-props - script?: Script; + script: Script; visible: boolean; onOk: () => void; onCancel: () => void; }> = ({ script, visible, onCancel, onOk }) => { - const permissionCtrl = IoC.instance( - PermissionController - ) as PermissionController; const scriptCtrl = IoC.instance(ScriptController) as ScriptController; - const [permission, setPermission] = useState([]); const [checkUpdateUrl, setCheckUpdateUrl] = useState(""); - const { t } = useTranslation(); - const columns: ColumnProps[] = [ - { - title: t("type"), - dataIndex: "permission", - key: "permission", - width: 100, - }, - { - title: t("permission_value"), - dataIndex: "permissionValue", - key: "permissionValue", - }, - { - title: t("allow"), - dataIndex: "allow", - key: "allow", - render(col) { - if (col) { - return {t("yes")}; - } - return {t("no")}; - }, - }, - { - title: t("action"), - render(_, item: Permission) { - return ( - - { - permissionCtrl - .deletePermission(script!.id, { - permission: item.permission, - permissionValue: item.permissionValue, - }) - .then(() => { - Message.success(t("delete_success")!); - setPermission(permission.filter((i) => i.id !== item.id)); - }) - .catch(() => { - Message.error(t("delete_failed")!); - }); - }} - > -
+ {script && } ); diff --git a/src/pages/options/routes/script/ScriptEditor.tsx b/src/pages/options/routes/script/ScriptEditor.tsx index 380f991e..e98504e2 100644 --- a/src/pages/options/routes/script/ScriptEditor.tsx +++ b/src/pages/options/routes/script/ScriptEditor.tsx @@ -539,7 +539,7 @@ function ScriptEditor() { /> { setShow("scriptSetting", false); }} diff --git a/src/runtime/background/permission_verify.ts b/src/runtime/background/permission_verify.ts index 3f3ed1e5..a93d9d06 100644 --- a/src/runtime/background/permission_verify.ts +++ b/src/runtime/background/permission_verify.ts @@ -1,6 +1,6 @@ // gm api 权限验证 import Cache from "@App/app/cache"; -import { PermissionDAO } from "@App/app/repo/permission"; +import { Permission, PermissionDAO } from "@App/app/repo/permission"; import { Script } from "@App/app/repo/scripts"; import CacheKey from "@App/pkg/utils/cache_key"; import { v4 as uuidv4 } from "uuid"; @@ -175,6 +175,35 @@ export default class PermissionVerify { return Promise.resolve(true); } ); + // 监听添加权限 + message.setHandler( + "addPermission", + async (_action, data: { scriptId: number; permission: Permission }) => { + // 先删除缓存 + const cacheKey = CacheKey.permissionConfirm( + data.scriptId, + data.permission + ); + await Cache.getInstance().del(cacheKey); + // 从数据库中查询是否有此权限 + const m = await this.permissionDAO.findOne({ + scriptId: data.scriptId, + permission: data.permission.permission, + permissionValue: data.permission.permissionValue || "", + }); + if (!m) { + // 没有添加 + await this.permissionDAO.save(data.permission); + return Promise.resolve(true); + } + // 有则更新 + data.permission.id = m.id; + data.permission.createtime = m.createtime; + data.permission.updatetime = new Date().getTime(); + this.permissionDAO.update(m.id, data.permission); + return Promise.resolve(true); + } + ); this.dealConfirmQueue(); }