Skip to content

Commit

Permalink
feat: add default storage classes and hide accelerate uploading if pr…
Browse files Browse the repository at this point in the history
…ivate
  • Loading branch information
lihsai0 committed Nov 20, 2024
1 parent 026f436 commit 972dce9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ const UploadFilesConfirm: React.FC<ModalProps & UploadFilesConfirmProps> = ({
</Modal.Body>
<Modal.Footer>
{
currentUser?.endpointType === EndpointType.Public &&
onClickRefreshCanAccelerateUploading &&
<TipPopover
className="me-auto"
Expand Down
24 changes: 22 additions & 2 deletions src/renderer/modules/qiniu-client-hooks/use-load-regions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {useEffect, useState} from "react";
import {Region} from "kodo-s3-adapter-sdk";
import {RegionStorageClass} from "kodo-s3-adapter-sdk/dist/region";
import {toast} from "react-hot-toast";

import * as LocalLogger from "@renderer/modules/local-logger";
Expand All @@ -12,6 +13,20 @@ interface LoadRegionsState {
regions: Region[],
}

const DEFAULT_REGION_STORAGE_CLASSES: RegionStorageClass[] = [
{
fileType: 0,
kodoName: "Standard",
s3Name: "STANDARD",
billingI18n: {},
nameI18n: {
en_US: "Standard",
ja_JP: "標準",
zh_CN: "标准存储",
},
},
];

export default function useLoadRegions({
user,
shouldAutoReload,
Expand Down Expand Up @@ -63,8 +78,7 @@ export default function useLoadRegions({
} else {
try {
regions = regionsFromEndpointConfig.map(r => {
const storageClasses = regionsFromFetch
.find(i => i.s3Id === r.identifier)?.storageClasses ?? []
const storageClasses = regionsFromFetch.find(i => i.s3Id === r.identifier)?.storageClasses;
const result = new Region(
r.identifier,
r.identifier,
Expand All @@ -90,6 +104,12 @@ export default function useLoadRegions({
}
}
} finally {
// set default storage classes
regions?.forEach(r => {
if (!r.storageClasses.length) {
r.storageClasses.push(...DEFAULT_REGION_STORAGE_CLASSES.map(sc => ({...sc})));
}
});
setLoadRegionsState({
loading: false,
regions: regions || [],
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/modules/qiniu-client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Path as QiniuPath } from "qiniu-path/dist/src/path";

import * as AppConfig from "@common/const/app-config";
import * as KodoNav from "@renderer/const/kodo-nav";
import {AkItem, AkSpecialType} from "@renderer/modules/auth";
import {AkItem, EndpointType} from "@renderer/modules/auth";

import {debugRequest, debugResponse, GetAdapterOptionParam, getDefaultClient} from './common'
import {checkFileExists, checkFolderExists} from "./files";
Expand Down Expand Up @@ -99,7 +99,9 @@ export async function isAccelerateUploadingAvailable(
opt: GetAdapterOptionParam,
refreshCache = false,
): Promise<boolean> {
if (user.specialType === AkSpecialType.STS) {
if (
user.endpointType !== EndpointType.Public
) {
return false;
}

Expand Down

0 comments on commit 972dce9

Please sign in to comment.