Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/filesystem/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { ExtServer, ExtServerApi } from "@App/app/const";
import { WarpTokenError } from "./error";
import { LocalStorageDAO } from "@App/app/repo/localStorage";
import { sleep } from "@App/pkg/utils/utils";
import type { FileSystemType } from "./factory";

type NetDiskType = "baidu" | "onedrive" | "googledrive" | "dropbox";
export type NetDiskType = "baidu" | "onedrive" | "googledrive" | "dropbox";

export function GetNetDiskToken(netDiskType: NetDiskType): Promise<{
code: number;
Expand Down Expand Up @@ -127,3 +128,21 @@ export async function AuthVerify(netDiskType: NetDiskType, invalid?: boolean) {
}
return token.accessToken;
}

export const netDiskTypeMap: Partial<Record<FileSystemType, NetDiskType>> = {
"baidu-netdsik": "baidu",
onedrive: "onedrive",
googledrive: "googledrive",
dropbox: "dropbox",
};

export async function ClearNetDiskToken(netDiskType: NetDiskType) {
const localStorageDAO = new LocalStorageDAO();
const key = `netdisk:token:${netDiskType}`;
try {
await localStorageDAO.delete(key);
} catch (error) {
// ignore
console.error("ClearNetDiskToken error:", error);
}
}
6 changes: 5 additions & 1 deletion src/locales/ach-UG/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@
"confirm_leave_page": "crwdns8634:0crwdne8634:0",
"page_in_blacklist": "crwdns8636:0crwdne8636:0",
"baidu_netdisk": "crwdns8638:0crwdne8638:0",
"netdisk_unbind": "Unbind {{provider}}",
"netdisk_unbind_confirm": "Unbind the {{provider}} account?",
"netdisk_unbind_success": "{{provider}} account unbound",
"netdisk_unbind_error": "Failed to unbind {{provider}} account",
"save_only_current_group": "crwdns8640:0crwdne8640:0",
"script_import_result": "crwdns8642:0crwdne8642:0",
"failure_info": "crwdns8644:0crwdne8644:0",
Expand Down Expand Up @@ -537,4 +541,4 @@
"subscribe_update_desc": "crwdns12856:0{{newScripts}}crwdnd12856:0{{deletedScripts}}crwdne12856:0"
},
"loading": "crwdns12870:0crwdne12870:0"
}
}
6 changes: 5 additions & 1 deletion src/locales/de-DE/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@
"confirm_leave_page": "Derzeit im Bearbeitungsstatus. Das Navigieren zu anderen Seiten führt zum Verlust des aktuellen Inhalts. Navigieren?",
"page_in_blacklist": "Die aktuelle Seite ist auf der Blacklist und kann keine Skripte verwenden",
"baidu_netdisk": "Baidu Netdisk",
"netdisk_unbind": "{{provider}} trennen",
"netdisk_unbind_confirm": "Das {{provider}}-Konto trennen?",
"netdisk_unbind_success": "{{provider}}-Konto getrennt",
"netdisk_unbind_error": "{{provider}}-Konto konnte nicht getrennt werden",
"save_only_current_group": "Speichern ist nur für die aktuelle Gruppe wirksam",
"script_import_result": "Skript-Import-Ergebnis",
"failure_info": "Fehlerinformationen",
Expand Down Expand Up @@ -551,4 +555,4 @@
"maybe_later": "Vielleicht später",
"settings_hint": "Sie können diese Option jederzeit in den Einstellungen ändern."
}
}
}
6 changes: 5 additions & 1 deletion src/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@
"confirm_leave_page": "Currently editing status. Leaving this page will lose the current content. Do you want to leave?",
"page_in_blacklist": "The current page is blacklisted, cannot use script",
"baidu_netdisk": "BaiduNetdisk",
"netdisk_unbind": "Unbind {{provider}}",
"netdisk_unbind_confirm": "Unbind the {{provider}} account?",
"netdisk_unbind_success": "{{provider}} account unbound",
"netdisk_unbind_error": "Failed to unbind {{provider}} account",
"save_only_current_group": "Save only for current group",
"script_import_result": "Script Import Results",
"failure_info": "Failure Information",
Expand Down Expand Up @@ -551,4 +555,4 @@
"maybe_later": "Maybe Later",
"settings_hint": "You can change this option in settings at any time."
}
}
}
6 changes: 5 additions & 1 deletion src/locales/ja-JP/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@
"confirm_leave_page": "現在編集中です。他のページに移動すると現在の内容が失われます。移動しますか?",
"page_in_blacklist": "現在のページはブラックリストにあり、スクリプトを使用できません",
"baidu_netdisk": "百度ネットディスク",
"netdisk_unbind": "{{provider}} の連携を解除",
"netdisk_unbind_confirm": "{{provider}} のアカウント連携を解除しますか?",
"netdisk_unbind_success": "{{provider}} のアカウント連携を解除しました",
"netdisk_unbind_error": "{{provider}} のアカウント解除に失敗しました",
"save_only_current_group": "保存は現在のグループにのみ有効です",
"script_import_result": "スクリプトインポート結果",
"failure_info": "失敗情報",
Expand Down Expand Up @@ -551,4 +555,4 @@
"maybe_later": "後で",
"settings_hint": "設定ページでいつでも変更できます。"
}
}
}
6 changes: 5 additions & 1 deletion src/locales/ru-RU/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@
"confirm_leave_page": "В настоящее время идет редактирование. Переход на другую страницу приведет к потере текущего содержимого. Продолжить переход?",
"page_in_blacklist": "Текущая страница находится в черном списке, невозможно использовать скрипты",
"baidu_netdisk": "Baidu Netdisk",
"netdisk_unbind": "Отвязать {{provider}}",
"netdisk_unbind_confirm": "Отвязать аккаунт {{provider}}?",
"netdisk_unbind_success": "Аккаунт {{provider}} отвязан",
"netdisk_unbind_error": "Не удалось отвязать аккаунт {{provider}}",
"save_only_current_group": "Сохранение действует только для текущей группы",
"script_import_result": "Результат импорта скрипта",
"failure_info": "Информация об ошибке",
Expand Down Expand Up @@ -551,4 +555,4 @@
"maybe_later": "Может быть позже",
"settings_hint": "Вы можете изменить эту опцию в настройках в любое время."
}
}
}
6 changes: 5 additions & 1 deletion src/locales/vi-VN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@
"confirm_leave_page": "Hiện đang ở trạng thái chỉnh sửa. Rời khỏi trang này sẽ làm mất nội dung hiện tại. Bạn có muốn rời đi không?",
"page_in_blacklist": "Trang hiện tại nằm trong danh sách đen, không thể sử dụng script",
"baidu_netdisk": "Baidunetdisk",
"netdisk_unbind": "Hủy liên kết {{provider}}",
"netdisk_unbind_confirm": "Hủy liên kết tài khoản {{provider}}?",
"netdisk_unbind_success": "Đã hủy liên kết tài khoản {{provider}}",
"netdisk_unbind_error": "Không thể hủy liên kết tài khoản {{provider}}",
"save_only_current_group": "Chỉ lưu cho nhóm hiện tại",
"script_import_result": "Kết quả nhập script",
"failure_info": "Thông tin thất bại",
Expand Down Expand Up @@ -551,4 +555,4 @@
"maybe_later": "Để sau",
"settings_hint": "Bạn có thể thay đổi tùy chọn này trong cài đặt bất kỳ lúc nào."
}
}
}
6 changes: 5 additions & 1 deletion src/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@
"confirm_leave_page": "当前正在编辑状态,跳转其它页面将会丢失当前内容,是否跳转?",
"page_in_blacklist": "当前页面在黑名单中,无法使用脚本",
"baidu_netdisk": "百度网盘",
"netdisk_unbind": "解除绑定 {{provider}}",
"netdisk_unbind_confirm": "确定解除 {{provider}} 账号绑定吗?",
"netdisk_unbind_success": "已解除 {{provider}} 账号绑定",
"netdisk_unbind_error": "解除 {{provider}} 账号失败",
"save_only_current_group": "保存只对当前组有效",
"script_import_result": "脚本导入结果",
"failure_info": "失败信息",
Expand Down Expand Up @@ -551,4 +555,4 @@
"maybe_later": "暂不启用",
"settings_hint": "你可以随时在设置中修改此选项。"
}
}
}
6 changes: 5 additions & 1 deletion src/locales/zh-TW/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@
"confirm_leave_page": "目前正在編輯狀態,跳轉其他頁面將會遺失目前內容,是否跳轉?",
"page_in_blacklist": "目前頁面在黑名單中,無法使用腳本",
"baidu_netdisk": "百度網盤",
"netdisk_unbind": "解除綁定 {{provider}}",
"netdisk_unbind_confirm": "確定解除 {{provider}} 帳號綁定嗎?",
"netdisk_unbind_success": "已解除 {{provider}} 帳號綁定",
"netdisk_unbind_error": "解除 {{provider}} 帳號失敗",
"save_only_current_group": "儲存僅對目前群組有效",
"script_import_result": "腳本匯入結果",
"failure_info": "失敗資訊",
Expand Down Expand Up @@ -551,4 +555,4 @@
"maybe_later": "暫不啟用",
"settings_hint": "你可以隨時在設定中修改此選項。"
}
}
}
31 changes: 29 additions & 2 deletions src/pages/components/FileSystemParams/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import { Input, Select, Space } from "@arco-design/web-react";
import { Button, Input, Message, Popconfirm, Select, Space } from "@arco-design/web-react";
import type { FileSystemType } from "@Packages/filesystem/factory";
import FileSystemFactory from "@Packages/filesystem/factory";
import { useTranslation } from "react-i18next";
import { ClearNetDiskToken, netDiskTypeMap } from "@Packages/filesystem/auth";

const FileSystemParams: React.FC<{
preNode: React.ReactNode | string;
Expand All @@ -21,6 +22,7 @@ const FileSystemParams: React.FC<{
}) => {
const fsParams = FileSystemFactory.params();
const { t } = useTranslation();
const actionButtons = [...actionButton];

const fileSystemList: {
key: FileSystemType;
Expand Down Expand Up @@ -48,6 +50,31 @@ const FileSystemParams: React.FC<{
},
];

const netDiskType = netDiskTypeMap[fileSystemType];

if (netDiskType) {
const netDiskName = fileSystemList.find((item) => item.key === fileSystemType)?.name;

actionButtons.push(
<Popconfirm
key="netdisk-unbind"
title={t("netdisk_unbind_confirm", { provider: netDiskName })}
onOk={async () => {
try {
await ClearNetDiskToken(netDiskType);
Message.success(t("netdisk_unbind_success", { provider: netDiskName })!);
} catch (error) {
Message.error(`${t("netdisk_unbind_error", { provider: netDiskName })}: ${String(error)}`);
}
}}
>
<Button type="primary" status="danger">
{t("netdisk_unbind", { provider: netDiskName })}
</Button>
</Popconfirm>
);
}

return (
<>
<Space>
Expand All @@ -65,7 +92,7 @@ const FileSystemParams: React.FC<{
</Select.Option>
))}
</Select>
{actionButton.map((item) => item)}
{actionButtons.map((item) => item)}
</Space>
<Space
style={{
Expand Down
Loading