Skip to content

Commit

Permalink
feat: add refresh accelerate uploading cache on confirm popup
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 committed Nov 19, 2024
1 parent 60ef446 commit a0eb959
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/renderer/modules/qiniu-client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ export async function isAccelerateUploadingAvailable(
user: AkItem,
bucket: string,
opt: GetAdapterOptionParam,
withoutCache = false,
refreshCache = false,
): Promise<boolean> {
if (user.specialType === AkSpecialType.STS) {
return false;
}

return await getDefaultClient(opt).enter("isAccelerateUploadingAvailable", async client => {
if (withoutCache) {
if (refreshCache) {
client.client.clearCache();
}
const accUrls = await client.client.getServiceUrls({
Expand Down
20 changes: 13 additions & 7 deletions src/renderer/pages/browse/files/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ const Files: React.FC<FilesProps> = (props) => {
const [fetchingAccelerateUploading, setFetchingAccelerateUploading] = useState<boolean>(false);
const fetchAccelerateUploading = ({
needFeedback,
withoutCache,
refreshCache,
}: {
needFeedback?: boolean,
withoutCache?: boolean,
refreshCache?: boolean,
} = {}) => {
if (!currentUser || !props.bucket || fetchingAccelerateUploading) {
return;
Expand All @@ -203,7 +203,7 @@ const Files: React.FC<FilesProps> = (props) => {
currentUser,
props.bucket?.name,
opt,
withoutCache,
refreshCache,
);
if (needFeedback) {
p = toast.promise(p, {
Expand All @@ -216,14 +216,11 @@ const Files: React.FC<FilesProps> = (props) => {
.catch(err => LocalLogger.error(err))
.finally(() => setFetchingAccelerateUploading(false));
};
useEffect(() => {
fetchAccelerateUploading();
}, [currentUser?.accessKey, props.bucket]);
const refreshCanAccelerateUploading = () => {
ipcUploadManager.clearRegionsCache();
fetchAccelerateUploading({
needFeedback: true,
withoutCache: true,
refreshCache: true,
});
};

Expand Down Expand Up @@ -285,6 +282,15 @@ const Files: React.FC<FilesProps> = (props) => {
] = useDisplayModal<{filePaths: string[]}>({
filePaths: []
});
useEffect(() => {
if (!isShowUploadFilesConfirm) {
return;
}
ipcUploadManager.clearRegionsCache();
fetchAccelerateUploading({
refreshCache: true,
});
}, [isShowUploadFilesConfirm]);

// handle upload and download
const handleUploadFiles = async (filePaths: string[]) => {
Expand Down

0 comments on commit a0eb959

Please sign in to comment.