Skip to content

Commit

Permalink
refactor(web): cloud storage use ak/sk instead of sts (labring#1581)
Browse files Browse the repository at this point in the history
* refactor(web): cloud storage use ak/sk instead of sts

* refactor(web): direct update env & add appid when create bucket

* fix(web): fix create bucket need name message
  • Loading branch information
newfish-cmyk authored Oct 19, 2023
1 parent 91ad4aa commit 7f468fe
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 34 deletions.
8 changes: 4 additions & 4 deletions web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@
"parsing": "parsing",
"DomainUpdateSuccess": "Domain Update Success",
"DomainDeleteSuccess": "Domain Delete Success",
"CustomApplicationDomain": "Custom Application Domain"
"CustomApplicationDomain": "Custom Application Domain",
"BucketNameisRequired": "Bucket name is required"
},
"TriggerPanel": {
"AddTrigger": "Add Trigger",
Expand Down Expand Up @@ -658,6 +659,5 @@
"SavedSuccessfully": "Saved Successfully",
"Bind": "Bind",
"UnBind": "Unbind",
"UnBindSuccess": "Unbind Successfully",
"SavedSuccessfully": "Saved Successfully"
}
"UnBindSuccess": "Unbind Successfully"
}
5 changes: 3 additions & 2 deletions web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@
"RemoveHost": "取消静态托管",
"DomainUpdateSuccess": "域名修改成功",
"DomainDeleteSuccess": "域名删除成功",
"CustomApplicationDomain": "自定义应用域名"
"CustomApplicationDomain": "自定义应用域名",
"BucketNameisRequired": "请输入 Bucket 名称"
},
"TriggerPanel": {
"AddTrigger": "新建触发器",
Expand Down Expand Up @@ -659,4 +660,4 @@
"UnBind": "解绑",
"UnBindSuccess": "解绑成功",
"SavedSuccessfully": "保存成功"
}
}
5 changes: 3 additions & 2 deletions web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@
"RemoveHost": "取消静态托管",
"DomainUpdateSuccess": "域名修改成功",
"DomainDeleteSuccess": "域名删除成功",
"CustomApplicationDomain": "自定义应用域名"
"CustomApplicationDomain": "自定义应用域名",
"BucketNameisRequired": "请输入 Bucket 名称"
},
"TriggerPanel": {
"AddTrigger": "新建触发器",
Expand Down Expand Up @@ -659,4 +660,4 @@
"UnBind": "解绑",
"UnBindSuccess": "解绑成功",
"SavedSuccessfully": "保存成功"
}
}
9 changes: 4 additions & 5 deletions web/src/hooks/useAwsS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import useGlobalStore from "@/pages/globalStore";

function useAwsS3() {
const currentApp = useGlobalStore((state) => state.currentApp);
const credentials = currentApp?.storage?.credentials;
const storage = currentApp?.storage;

const s3 = new (window as any).AWS.S3({
accessKeyId: credentials?.accessKeyId,
secretAccessKey: credentials?.secretAccessKey,
sessionToken: credentials?.sessionToken,
endpoint: credentials?.endpoint,
accessKeyId: storage.accessKey,
secretAccessKey: storage.secretKey,
endpoint: storage.endpoint,
s3ForcePathStyle: true,
signatureVersion: "v4",
});
Expand Down
13 changes: 5 additions & 8 deletions web/src/pages/app/setting/SysSetting/AppEnvList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import clsx from "clsx";
import dotenv from "dotenv";
import { t } from "i18next";

import ConfirmButton from "@/components/ConfirmButton";
import ENVEditor from "@/components/Editor/ENVEditor";
import { COLOR_MODE } from "@/constants";

Expand Down Expand Up @@ -42,8 +41,9 @@ const AppEnvList = (props: { onClose?: () => {} }) => {
}}
/>
</div>
<ConfirmButton
onSuccessAction={async () => {
<Button
className="mt-4 h-8 w-28 self-end"
onClick={async () => {
const obj = dotenv.parse(envValue.current || "");
// convert obj to [{ name: '', value: ''}]
const arr = Object.keys(obj).map((key) => {
Expand All @@ -54,12 +54,9 @@ const AppEnvList = (props: { onClose?: () => {} }) => {
props.onClose && props.onClose();
}
}}
headerText={String(t("Update"))}
bodyText={String(t("SettingPanel.UpdateConfirm"))}
confirmButtonText={String(t("Confirm"))}
>
<Button className="mt-4 h-8 w-28 self-end">{t("Update")}</Button>
</ConfirmButton>
{t("Update")}
</Button>
</div>
</>
);
Expand Down
41 changes: 28 additions & 13 deletions web/src/pages/app/storages/mods/CreateBucketModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
FormErrorMessage,
FormLabel,
Input,
InputAddon,
InputGroup,
Modal,
ModalBody,
ModalCloseButton,
Expand All @@ -14,9 +16,11 @@ import {
ModalHeader,
ModalOverlay,
Select,
useColorMode,
useDisclosure,
VStack,
} from "@chakra-ui/react";
import clsx from "clsx";
import { t } from "i18next";

import { BUCKET_POLICY_TYPE } from "@/constants";
Expand All @@ -35,6 +39,8 @@ function CreateBucketModal(props: { storage?: TBucket; children: React.ReactElem
const bucketCreateMutation = useBucketCreateMutation();
const bucketUpdateMutation = useBucketUpdateMutation();

const darkMode = useColorMode().colorMode === "dark";

const defaultValues = {
name: storage?.name,
policy: storage?.policy,
Expand All @@ -53,7 +59,7 @@ function CreateBucketModal(props: { storage?: TBucket; children: React.ReactElem
defaultValues,
});

const { showSuccess } = useGlobalStore();
const { showSuccess, currentApp } = useGlobalStore();

const isEdit = !!storage;

Expand Down Expand Up @@ -102,18 +108,27 @@ function CreateBucketModal(props: { storage?: TBucket; children: React.ReactElem
<VStack spacing={6} align="flex-start">
<FormControl isInvalid={!!errors?.name}>
<FormLabel htmlFor="name"> {t("StoragePanel.BucketName")}</FormLabel>
<Input
{...register("name", {
required: true,
pattern: {
value: /^[a-z0-9][a-z0-9-]{1,30}[a-z0-9]$/,
message: t("StoragePanel.BucketNameRule"),
},
})}
placeholder={String(t("StoragePanel.BucketNamePlaceholder"))}
variant="filled"
disabled={isEdit}
/>
<InputGroup>
<InputAddon className="!mr-0 !rounded-r-none !pr-0">
{currentApp.appid + "-"}
</InputAddon>
<Input
{...register("name", {
required: t("StoragePanel.BucketNameisRequired").toString(),
pattern: {
value: /^[a-z0-9][a-z0-9-]{1,30}[a-z0-9]$/,
message: t("StoragePanel.BucketNameRule"),
},
})}
variant="filled"
placeholder={String(t("StoragePanel.BucketNamePlaceholder"))}
disabled={isEdit}
className={clsx(
"!ml-0 !rounded-l-none !border-none !pl-0",
darkMode ? "!bg-[#FFFFFF0A]" : "!bg-lafWhite-600",
)}
/>
</InputGroup>
<FormErrorMessage>{errors.name && errors.name.message}</FormErrorMessage>
</FormControl>

Expand Down

0 comments on commit 7f468fe

Please sign in to comment.