Skip to content

Commit

Permalink
feat: improve region cache and accelerate uploading ui
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 committed Nov 1, 2024
1 parent 003e5d4 commit 3c76d9c
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 32 deletions.
15 changes: 15 additions & 0 deletions src/common/ipc-actions/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export enum UploadAction {
StopJobsByOffline = "StopJobsByOffline",
StartJobsByOnline = "StartJobsByOnline",
RemoveAllJobs = "RemoveAllJobs",
ClearRegionsCache = "ClearRegionsCache",

// common
UpdateUiData = "UpdateUiData",
Expand Down Expand Up @@ -178,6 +179,11 @@ export interface RemoveAllJobsMessage {
data?: {},
}

export interface ClearRegionsCacheMessage {
action: UploadAction.ClearRegionsCache,
data?: {},
}

export interface JobCompletedReplyMessage {
action: UploadAction.JobCompleted,
data: {
Expand Down Expand Up @@ -208,6 +214,7 @@ export type UploadMessage = UpdateConfigMessage
| StopJobsByOfflineMessage
| StartJobsByOnlineMessage
| RemoveAllJobsMessage
| ClearRegionsCacheMessage

export type UploadReplyMessage = UpdateUiDataReplyMessage
| AddedJobsReplyMessage
Expand Down Expand Up @@ -319,4 +326,12 @@ export class UploadActionFns {
data: {},
});
}

clearRegionsCache() {
// if only ucUrl and s3RegionId are provided,
// it will clear all regions cache
this.sender.send(this.channel, {
action: UploadAction.ClearRegionsCache,
});
}
}
1 change: 1 addition & 0 deletions src/common/models/job/upload-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export default class UploadJob extends TransferJob {
...super.uiData,
from: this.options.from,
to: this.options.to,
accelerateUploading: this.accelerateUploading,
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/kv-store/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export class DataStore<T> {

constructor({
workingDirectory,
thresholdDuration,
thresholdSize,
thresholdChangesSize,
thresholdDuration, // ms, trigger compact when thresholdDuration elapsed after last compact
thresholdSize, // trigger compact when memTable size exceeds thresholdSize
thresholdChangesSize, // trigger compact when memTable changes size exceeds thresholdChangesSize

memTable,
memTableReadOnly,
Expand Down
5 changes: 5 additions & 0 deletions src/main/upload-worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Region} from "kodo-s3-adapter-sdk";
import {KodoHttpClient} from "kodo-s3-adapter-sdk/dist/kodo-http-client";

import {
AddedJobsReplyMessage,
Expand Down Expand Up @@ -139,6 +140,10 @@ process.on("message", (message: UploadMessage) => {
uploadManager.removeAllJobs();
break;
}
case UploadAction.ClearRegionsCache: {
KodoHttpClient.clearCache();
break;
}
default: {
console.warn("Upload Manager received unknown action, message:", message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {promises as fsPromises} from "fs";
import path from "path";

import React, {Fragment, useEffect, useMemo, useState} from "react";
import {Button, Form, Modal, ModalProps, Spinner} from "react-bootstrap";
import {Button, Form, Modal, ModalProps, OverlayTrigger, Popover, Spinner} from "react-bootstrap";
import {SubmitHandler, useForm} from "react-hook-form";
import {toast} from "react-hot-toast";

Expand All @@ -18,6 +18,60 @@ import {useEndpointConfig} from "@renderer/modules/user-config-store";

import LoadingHolder from "@renderer/components/loading-holder";

interface TipPopoverProps {
className: string,
onClickRefresh: () => void,
}

const TipPopover: React.FC<TipPopoverProps> = ({
className,
onClickRefresh,
}) => {
const [show, setShow] = useState(false);
const handleToggle = (nextShow: boolean) => {
if (!show) {
setShow(nextShow);
}
};
const handleMouseEnter = () => {
setShow(true);
};
const handleMouseLeave = () => {
setShow(false);
};
return (
<div className={className}>
<OverlayTrigger
placement="right"
show={show}
onToggle={handleToggle}
overlay={
<Popover
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<Popover.Body>
已经开通加速域名,但没有显示使用加速域名的开关?
<br />
<span
tabIndex={0}
className="text-link"
onClick={() => onClickRefresh()}
onKeyUp={e => e.code === "Space" && onClickRefresh()}
>
点击这里
</span>
刷新试试。
</Popover.Body>
</Popover>
}
>
<i className="bi bi-question-circle-fill"/>
</OverlayTrigger>
</div>
);
};

interface UploadFilesConfirmProps {
filePaths: string[],
maxShowFiles?: number,
Expand All @@ -26,6 +80,7 @@ interface UploadFilesConfirmProps {
bucketName: string,
destPath: string,
canAccelerateUploading?: boolean,
onClickRefreshCanAccelerateUploading?: () => void,
}

interface FileShowItem {
Expand Down Expand Up @@ -63,6 +118,7 @@ const UploadFilesConfirm: React.FC<ModalProps & UploadFilesConfirmProps> = ({
bucketName,
destPath,
canAccelerateUploading = false,
onClickRefreshCanAccelerateUploading,
...modalProps
}) => {
const {currentLanguage, translate} = useI18n();
Expand Down Expand Up @@ -324,6 +380,13 @@ const UploadFilesConfirm: React.FC<ModalProps & UploadFilesConfirmProps> = ({
</Form>
</Modal.Body>
<Modal.Footer>
{
onClickRefreshCanAccelerateUploading &&
<TipPopover
className="me-auto"
onClickRefresh={onClickRefreshCanAccelerateUploading}
/>
}
{
!memoFilePaths.length
? null
Expand Down
36 changes: 26 additions & 10 deletions src/renderer/components/transfer-panel/job-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import TransferJob from "@common/models/job/transfer-job";

import {ADDR_KODO_PROTOCOL} from "@renderer/const/kodo-nav";
import TooltipText from "@renderer/components/tooltip-text";
import {translate} from "@renderer/modules/i18n";
import {useI18n} from "@renderer/modules/i18n";
import {Status2I18nKey} from "@renderer/modules/i18n/extra";

interface JobItemProps {
namePrefix?: string,
data: TransferJob["uiData"],
data: TransferJob["uiData"] & {accelerateUploading?: boolean},
operationButtons?: React.ReactNode,
}

Expand All @@ -22,6 +22,8 @@ const JobItem: React.FC<JobItemProps> = ({
data,
operationButtons,
}) => {
const {translate} = useI18n();

const {
status,
from,
Expand Down Expand Up @@ -72,14 +74,28 @@ const JobItem: React.FC<JobItemProps> = ({
}
</div>
</TooltipText>
<ProgressBar
animated={[Status.Running, Status.Verifying].includes(status)}
now={
Status.Finished === status
? 100
: progressLoaded * 100 / progressTotal
}
/>
<div className="d-flex align-items-center">
<ProgressBar
className="flex-fill"
animated={[Status.Running, Status.Verifying].includes(status)}
now={
Status.Finished === status
? 100
: progressLoaded * 100 / progressTotal
}
/>
<TooltipText
tooltipContent={translate("transfer.jobItem.accelerateUploading")}
tooltipPlacement="bottom"
>
<i
className="bi bi-lightning-fill acc-uploading-icon"
style={{
visibility: data.accelerateUploading ? "visible" : "hidden",
}}
/>
</TooltipText>
</div>
</div>
<div className="job-item-status">
{
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/components/transfer-panel/transfer-panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
--bs-progress-height: 0.5rem;
}

& .acc-uploading-icon {
min-width: 0.75rem;
font-size: 0.75rem;
color: var(--bs-yellow);
}

& .job-item-name {
flex: 0 0 30%;
min-width: 30%;
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/modules/i18n/lang/dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export default interface Dictionary {
removeConfirmOk: string,
unknownError: string,
fileDuplicated: string,
accelerateUploading: string,
},
upload: {
dropZone: {
Expand Down Expand Up @@ -793,6 +794,11 @@ export default interface Dictionary {
label: string,
},
},
popupHint: {
question: string,
clickHere: string,
refreshIt: string,
}
},

preview: {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/modules/i18n/lang/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ const dict: Dictionary = {
removeConfirmOk: "Remove",
unknownError: "unknown error",
fileDuplicated: "File duplicated",
accelerateUploading: "Accelerate uploading",
},
upload: {
dropZone: {
Expand Down Expand Up @@ -798,6 +799,11 @@ const dict: Dictionary = {
label: "Storage Class:",
},
},
popupHint: {
question: "Already enabled accelerate uploading for this bucket, but not see the switch?",
clickHere: "Click here",
refreshIt: " refresh it."
}
},

preview: {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/modules/i18n/lang/ja-jp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ const dict: Dictionary = {
removeConfirmOk: "削除",
unknownError: "不明なエラーです",
fileDuplicated: "ファイルは既に存在",
accelerateUploading: "アップロードを加速する",
},
upload: {
dropZone: {
Expand Down Expand Up @@ -797,6 +798,11 @@ const dict: Dictionary = {
label: "保管タイプ:",
},
},
popupHint: {
question: "すでにアクセラレーションドメインを有効にしましたが、アクセラレーションドメインを使用するスイッチが表示されませんか?",
clickHere: "こちらをクリック",
refreshIt: "リフレッシュしてみてください",
}
},

preview: {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/modules/i18n/lang/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ const dict: Dictionary = {
removeConfirmOk: "移除",
unknownError: "未知错误",
fileDuplicated: "文件已存在",
accelerateUploading: "加速上传",
},
upload: {
dropZone: {
Expand Down Expand Up @@ -797,6 +798,11 @@ const dict: Dictionary = {
label: "存储类型:",
},
},
popupHint: {
question: "已经开通加速域名,但没有显示使用加速域名的开关?",
clickHere: "点击这里",
refreshIt: "刷新试试",
}
},

preview: {
Expand Down
24 changes: 15 additions & 9 deletions src/renderer/modules/qiniu-client/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { KODO_MODE, Region } from "kodo-s3-adapter-sdk";
import { Domain } from "kodo-s3-adapter-sdk/dist/adapter";
import { ServiceName } from "kodo-s3-adapter-sdk/dist/kodo-http-client";
import { Path as QiniuPath } from "qiniu-path/dist/src/path";

import * as AppConfig from "@common/const/app-config";
Expand Down Expand Up @@ -94,18 +95,23 @@ export function checkFileOrDirectoryExists(

export async function isAccelerateUploadingAvailable(
user: AkItem,
bucketName: string,
bucket: string,
opt: GetAdapterOptionParam,
withoutCache = false,
): Promise<boolean> {
if (user.specialType === AkSpecialType.STS) {
return false;
}
const result = await Region.query({
accessKey: user.accessKey,
bucketName: bucketName,
appName: 'kodo-browser',
appVersion: AppConfig.app.version,
requestCallback: debugRequest(KODO_MODE),
responseCallback: debugResponse(KODO_MODE),

return await getDefaultClient(opt).enter("isAccelerateUploadingAvailable", async client => {
if (withoutCache) {
client.client.clearCache();
}
const accUrls = await client.client.getServiceUrls({
serviceName: ServiceName.UpAcc,
bucketName: bucket,
withFallback: false,
});
return accUrls && accUrls.length > 0;
});
return result.upAccUrls.length > 0;
}
Loading

0 comments on commit 3c76d9c

Please sign in to comment.