Skip to content

Commit

Permalink
fix(web): replace aws client sdk v3 with v2 (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeezQ authored Dec 15, 2022
1 parent 7c712e8 commit 3282894
Show file tree
Hide file tree
Showing 12 changed files with 9,700 additions and 6,653 deletions.
2 changes: 1 addition & 1 deletion web/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
["^react", "^@?\\w"],
["^(@chakra-ui)/(/.*|$/)"],
// Internal packages.
["^(@/components|@/constants|@/utils|/@/services)(/.*|$)"],
["^(@/components|@/constants|@/utils|/@/services|/@/pages)(/.*|$)"],
// Side effect imports.
["^\\u0000"],
// Parent imports. Put `..` last.
Expand Down
1 change: 1 addition & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<body>
<div id="root"></div>
<script src="/js/aws-sdk-2.1275.0.min.js"></script>
<script type="module" src="/src/main.tsx"></script>
</body>

Expand Down
16,114 changes: 9,571 additions & 6,543 deletions web/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"@monaco-editor/react": "^4.4.6",
"@tanstack/react-query": "^4.20.2",
"aws-sdk": "^2.1274.0",
"@aws-sdk/client-s3": "^3.231.0",
"axios": "^1.2.1",
"clsx": "^1.2.1",
"dayjs": "^1.11.7",
"laf-client-sdk": "^0.8.13",
"framer-motion": "^7.8.1",
"i18next": "^22.4.5",
"i18next-browser-languagedetector": "7.0.1",
"i18next-http-backend": "2.1.0",
"immer": "^9.0.16",
"laf-client-sdk": "^0.8.13",
"lodash": "^4.17.21",
"make-plural": "^7.2.0",
"react": "18.2.0",
Expand Down
100 changes: 100 additions & 0 deletions web/public/js/aws-sdk-2.1275.0.min.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions web/src/components/Editor/JsonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ export default function JsonEditor(props: {
height?: string;
onChange?: (value: string | undefined) => void;
}) {
const { value } = props;
let value = "{\n\t\n}";
let objValue = {};
try {
objValue = JSON.parse(props.value || "{}");
} catch (error) {}

value = Object.keys(objValue).length ? JSON.stringify(objValue, null, 2) : value;

function handleEditorWillMount(monaco: any) {
monaco?.editor.defineTheme("jsonEditorTheme", {
Expand All @@ -26,7 +32,7 @@ export default function JsonEditor(props: {
return (
<Editor
defaultLanguage="json"
value={JSON.stringify(JSON.parse(value), null, 2) || ""}
value={value}
height={props.height || "100%"}
onChange={(value, event) => {
props.onChange && props.onChange(value);
Expand Down
4 changes: 2 additions & 2 deletions web/src/hooks/useAwsS3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from "aws-sdk";
// import { S3Client } from '@aws-sdk/client-s3';

import useGlobalStore from "@/pages/globalStore";

Expand All @@ -7,7 +7,7 @@ function useAwsS3() {
const credentials = currentApp?.oss.credentials!;
const region = currentApp?.oss.spec.region;

const s3 = new AWS.S3({
const s3 = new (window as any).AWS.S3({
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
sessionToken: credentials.sessionToken,
Expand Down
33 changes: 0 additions & 33 deletions web/src/hooks/useOss.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export default function DataPannel() {
px="4"
onClick={async () => {
const params = JSON.parse(record);
debugger;
const r = await db.collection(currentDB?.name!).add({ ...params });
if (!r.error) {
showSuccess("保存成功");
Expand All @@ -113,7 +112,7 @@ export default function DataPannel() {
</div>
<div className=" flex-1" style={{}}>
<JsonEditor
value={currentData}
value={JSON.stringify(currentData || {}, null, 2)}
onChange={(values) => {
setRecord(values!);
}}
Expand Down
54 changes: 0 additions & 54 deletions web/src/pages/app/storages/FileList/index.tsx

This file was deleted.

14 changes: 4 additions & 10 deletions web/src/pages/app/storages/mods/FileList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import IconWrap from "@/components/IconWrap";
import PanelHeader from "@/components/Panel/Header";
import { formatDate } from "@/utils/format";

import useStorageStore from "../../store";
import useStorageStore, { TFile } from "../../store";
import CreateFolderModal from "../CreateFolderModal";
import HostingDrawer from "../HostingDrawer";
import UploadButton from "../UploadButton";
Expand Down Expand Up @@ -57,16 +57,10 @@ export default function FileList() {
</Tr>
</Thead>
<Tbody>
{(query?.data || []).map((file: any) => {
{(query?.data || []).map((file: TFile) => {
return (
<Tr _hover={{ bgColor: "#efefef" }} key={file.key}>
<Td>
{file.prefix ? (
<span className="text-blue-600 underline cursor-pointer">{file.name}</span>
) : (
<span>{file.name}</span>
)}
</Td>
<Tr _hover={{ bgColor: "#efefef" }} key={file.Key}>
<Td>jpg</Td>
<Td style={{ maxWidth: 200 }}>{file.Key}</Td>
<Td isNumeric>{file.Size}</Td>
<Td isNumeric>{formatDate(file.LastModified)}</Td>
Expand Down
15 changes: 10 additions & 5 deletions web/src/pages/app/storages/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import { immer } from "zustand/middleware/immer";
import { TBucket } from "@/apis/typing";

export type TFile = {
name: string;
path: string;
size: number;
updateTime: string;
prefix: string;
Key: string;
LastModified: string;
ETag: string;
ChecksumAlgorithm: any[];
Size: number;
StorageClass: string;
Owner: {
DisplayName: string;
ID: string;
};
};

type State = {
Expand Down

0 comments on commit 3282894

Please sign in to comment.