Skip to content

Commit

Permalink
add s3 for backup
Browse files Browse the repository at this point in the history
  • Loading branch information
troyeguo committed Jan 5, 2024
1 parent c61257d commit cfe6c03
Show file tree
Hide file tree
Showing 16 changed files with 1,274 additions and 21 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
"react-error-overlay": "6.0.9"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.485.0",
"@aws-sdk/s3-request-presigner": "^3.485.0",
"@vitalets/google-translate-api": "^8.0.0",
"adm-zip": "^0.5.2",
"axios": "^0.19.2",
"buffer": "^6.0.3",
"concat-stream": "^2.0.0",
"copy-text-to-clipboard": "^2.2.0",
"dompurify": "^3.0.1",
"electron-is-dev": "^1.1.0",
"electron-store": "^8.0.1",
"end-of-stream": "^1.4.4",
"epub-cfi-resolver": "^1.0.2",
"font-list": "^1.4.5",
"fs-extra": "^9.1.0",
Expand Down
Binary file modified src/assets/styles/fonts/icomoon.eot
Binary file not shown.
1 change: 1 addition & 0 deletions src/assets/styles/fonts/icomoon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/styles/fonts/icomoon.ttf
Binary file not shown.
Binary file modified src/assets/styles/fonts/icomoon.woff
Binary file not shown.
13 changes: 8 additions & 5 deletions src/assets/styles/style.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?36ewm1');
src: url('fonts/icomoon.eot?36ewm1#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?36ewm1') format('truetype'),
url('fonts/icomoon.woff?36ewm1') format('woff'),
url('fonts/icomoon.svg?36ewm1#icomoon') format('svg');
src: url('fonts/icomoon.eot?dhgwex');
src: url('fonts/icomoon.eot?dhgwex#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?dhgwex') format('truetype'),
url('fonts/icomoon.woff?dhgwex') format('woff'),
url('fonts/icomoon.svg?dhgwex#icomoon') format('svg');
font-weight: normal;
font-style: normal;
font-display: block;
Expand All @@ -25,6 +25,9 @@
-moz-osx-font-smoothing: grayscale;
}

.icon-s3compatible:before {
content: "\e958";
}
.icon-feedback:before {
content: "\e957";
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/dialogs/backupDialog/backupDialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
}
.backup-page-list-title {
width: 150px !important;
font-size: 15px;
font-size: 14px;
line-height: 30px;
opacity: 1;
width: 100%;
Expand All @@ -94,6 +94,9 @@
.icon-googledrive {
font-size: 45px;
}
.icon-s3compatible {
font-size: 60px;
}
.icon-ftp {
font-size: 65px;
position: relative;
Expand Down
5 changes: 5 additions & 0 deletions src/components/dialogs/backupDialog/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import GoogleDriveUtil from "../../../utils/syncUtils/googledrive";
import WebdavUtil from "../../../utils/syncUtils/webdav";
import FtpUtil from "../../../utils/syncUtils/ftp";
import SFtpUtil from "../../../utils/syncUtils/sftp";
import S3Util from "../../../utils/syncUtils/s3compatible";
import { BackupDialogProps, BackupDialogState } from "./interface";
import TokenDialog from "../tokenDialog";
import StorageUtil from "../../../utils/serviceUtils/storageUtil";
Expand Down Expand Up @@ -93,6 +94,7 @@ class BackupDialog extends React.Component<
case "googledrive":
case "ftp":
case "sftp":
case "s3compatible":
if (!StorageUtil.getReaderConfig(name + "_token")) {
this.props.handleTokenDialog(true);
break;
Expand All @@ -108,6 +110,8 @@ class BackupDialog extends React.Component<
? GoogleDriveUtil
: name === "sftp"
? SFtpUtil
: name === "s3compatible"
? S3Util
: WebdavUtil;
if (this.state.isBackup === "yes") {
this.showMessage("Uploading, please wait");
Expand Down Expand Up @@ -160,6 +164,7 @@ class BackupDialog extends React.Component<
if (
(item.icon === "webdav" ||
item.icon === "ftp" ||
item.icon === "s3compatible" ||
item.icon === "sftp") &&
!isElectron
) {
Expand Down
77 changes: 74 additions & 3 deletions src/components/dialogs/tokenDialog/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,37 @@ class TokenDialog extends Component<TokenDialogProps, TokenDialogState> {
this.props.handleTokenDialog(false);
toast.success(this.props.t("Add Successfully"));
};
handleS3Comfirm = () => {
let endpoint: string = (
document.querySelector(
"#token-dialog-endpoint-box"
) as HTMLTextAreaElement
).value;
let region: string = (
document.querySelector("#token-dialog-region-box") as HTMLTextAreaElement
).value;
let bucketName: string = (
document.querySelector("#token-dialog-bucket-box") as HTMLTextAreaElement
).value;
let accessKeyId: string = (
document.querySelector("#token-dialog-id-box") as HTMLTextAreaElement
).value;
let secretAccessKey: string = (
document.querySelector("#token-dialog-key-box") as HTMLTextAreaElement
).value;
StorageUtil.setReaderConfig(
`${this.props.driveName}_token`,
JSON.stringify({
endpoint,
region,
bucketName,
accessKeyId,
secretAccessKey,
})
);
this.props.handleTokenDialog(false);
toast.success(this.props.t("Add Successfully"));
};
handleSFTPComfirm = () => {
let url: string = (
document.querySelector("#token-dialog-url-box") as HTMLTextAreaElement
Expand Down Expand Up @@ -143,7 +174,7 @@ class TokenDialog extends Component<TokenDialogProps, TokenDialogState> {
{this.props.title}&nbsp;
<Trans>Token</Trans>
</div>
{this.props.driveName === "WebDAV" ? (
{this.props.driveName === "webdav" ? (
<>
<div
className="token-dialog-info-text"
Expand Down Expand Up @@ -177,7 +208,7 @@ class TokenDialog extends Component<TokenDialogProps, TokenDialogState> {
className="token-dialog-username-box"
/>
</>
) : this.props.driveName === "SFTP" ? (
) : this.props.driveName === "sftp" ? (
<>
<input
type="text"
Expand Down Expand Up @@ -215,7 +246,7 @@ class TokenDialog extends Component<TokenDialogProps, TokenDialogState> {
className="token-dialog-password-box"
/>
</>
) : this.props.driveName === "FTP" ? (
) : this.props.driveName === "ftp" ? (
<>
<input
type="text"
Expand Down Expand Up @@ -253,6 +284,44 @@ class TokenDialog extends Component<TokenDialogProps, TokenDialogState> {
className="token-dialog-password-box"
/>
</>
) : this.props.driveName === "s3compatible" ? (
<>
<input
type="text"
name="url"
placeholder={this.props.t("Endpoint")}
id="token-dialog-endpoint-box"
className="token-dialog-username-box"
/>
<input
type="text"
name="path"
placeholder={this.props.t("Region")}
id="token-dialog-region-box"
className="token-dialog-url-box"
/>
<input
type="text"
name="username"
placeholder={this.props.t("BucketName")}
id="token-dialog-bucket-box"
className="token-dialog-username-box"
/>
<input
type="text"
name="password"
placeholder={this.props.t("AccessKeyId")}
id="token-dialog-id-box"
className="token-dialog-password-box"
/>
<input
type="text"
name="ssl"
placeholder={this.props.t("SecretAccessKey")}
id="token-dialog-key-box"
className="token-dialog-password-box"
/>
</>
) : (
<>
<div
Expand Down Expand Up @@ -300,6 +369,8 @@ class TokenDialog extends Component<TokenDialogProps, TokenDialogState> {
this.handleFTPComfirm();
} else if (this.props.driveName === "sftp") {
this.handleSFTPComfirm();
} else if (this.props.driveName === "s3compatible") {
this.handleS3Comfirm();
} else if (this.props.driveName === "dropbox") {
this.handleDropboxComfirm();
} else if (this.props.driveName === "googledrive") {
Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogs/tokenDialog/tokenDialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
opacity: 1;
margin-left: 60px;
margin-top: 9px;
padding-left: 15px;
padding-left: 5px;
border-radius: 5px;
}
.token-dialog-cancel {
Expand Down
6 changes: 6 additions & 0 deletions src/constants/driveList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ export const driveList = [
icon: "googledrive",
url: `https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=${driveConfig.callbackUrl}&prompt=consent&response_type=code&client_id=${driveConfig.googleClientId}&scope=${driveConfig.googleScope}&access_type=offline`,
},
{
id: 8,
name: "S3 Compatible",
icon: "s3compatible",
url: "",
},
];
5 changes: 0 additions & 5 deletions src/containers/header/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ class Header extends React.Component<HeaderProps, HeaderState> {
};
}
async componentDidMount() {
// const { ipcRenderer } = window.require("electron");
// const html = await ipcRenderer.invoke("wiki-index", {
// text: "batman",
// });
// console.log(html);
if (isElectron) {
const fs = window.require("fs");
const path = window.require("path");
Expand Down
2 changes: 0 additions & 2 deletions src/utils/syncUtils/googledrive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class GoogleDriveUtil {
},
timeout: 60000,
});
console.log(res, "res");
console.log("File uploaded successfully.");
StorageUtil.setReaderConfig("googleFileId", res.data.id);
} catch (error) {
console.error("Error occurred during upload:", error);
Expand Down
1 change: 0 additions & 1 deletion src/utils/syncUtils/onedrive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class OneDriveUtil {
});
const accessToken = res.data.access_token; // 替换为实际的访问令牌
const downloadUrl = `https://graph.microsoft.com/v1.0/me/drive/special/approot:/${filename}:/content`;
console.log(accessToken);
try {
const response = await axios.get(downloadUrl, {
responseType: "blob",
Expand Down
Loading

0 comments on commit cfe6c03

Please sign in to comment.