Skip to content

Commit

Permalink
feat: s3 secret key id and access key generator (#160)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Hsu <[email protected]>
  • Loading branch information
itsHenry35 and xhofe authored Mar 25, 2024
1 parent e25e0cc commit 02f440f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lang/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@
"qbittorrent_seedtime": "Qbittorrent seedtime",
"qbittorrent_url": "Qbittorrent url",
"robots_txt": "Robots txt",
"s3_buckets_empty": "Bucket name or Path empty",
"s3_buckets_duplicate_name": "Bucket name duplicated",
"s3_generate": "Generate access key and id",
"s3_access_key_id": "S3 access key id",
"s3_buckets": "S3 buckets",
"s3_restart_to_apply": "Restart Alist to apply the settings above",
"s3_secret_access_key": "S3 secret access key",
"search_index": "Search index",
"search_indexs": {
Expand Down
25 changes: 25 additions & 0 deletions src/pages/manage/settings/S3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createSignal, Index, Show } from "solid-js"
import { Item } from "./SettingItem"
import { ResponsiveGrid } from "../common/ResponsiveGrid"
import S3Buckets from "./S3Buckets"
import crypto from "crypto-js"

const bucket_parse = (settings: SettingItem[]) => {
const string = { ...settings.find((i) => i.key === "s3_buckets")! }
Expand Down Expand Up @@ -56,6 +57,30 @@ const S3Settings = () => {
</Show>
)}
</Index>
<Button
onClick={() => {
const awsAccessKeyId = crypto.lib.WordArray.random(120 / 8)
const awsSecretAccessKey = crypto.lib.WordArray.random(240 / 8)
const accessKeyId = crypto.enc.Base64.stringify(
awsAccessKeyId,
).replace(/[\r\n]/g, "")
const secretAccessKey = crypto.enc.Base64.stringify(
awsSecretAccessKey,
).replace(/[\r\n]/g, "")
setSettings(
(i) => i.key === "s3_access_key_id",
"value",
accessKeyId,
)
setSettings(
(i) => i.key === "s3_secret_access_key",
"value",
secretAccessKey,
)
}}
>
{t("settings.s3_generate")}
</Button>
<Heading>{t("settings.s3_restart_to_apply")}</Heading>
<S3Buckets buckets={bucket_parse(settings)} setSettings={setSettings} />
</ResponsiveGrid>
Expand Down

0 comments on commit 02f440f

Please sign in to comment.