mirror of
https://github.com/rustfs/console.git
synced 2026-08-30 17:14:47 +08:00
fix: remove permanentStore ,generateTemporaryUrl use auth Credentials
This commit is contained in:
@@ -21,11 +21,9 @@ import { exportFile } from "@/lib/export-file"
|
||||
import { getContentType } from "@/lib/mime-types"
|
||||
import { ObjectVersions } from "@/components/object/versions"
|
||||
import { ObjectPreviewModal } from "@/components/object/preview-modal"
|
||||
import { GetObjectCommand, HeadObjectCommand, S3Client } from "@aws-sdk/client-s3"
|
||||
import { GetObjectCommand, HeadObjectCommand } from "@aws-sdk/client-s3"
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"
|
||||
import { useS3 } from "@/contexts/s3-context"
|
||||
import { useAuth } from "@/contexts/auth-context"
|
||||
import { configManager } from "@/lib/config"
|
||||
|
||||
const ONE_WEEK_SECONDS = 7 * 24 * 60 * 60
|
||||
|
||||
@@ -52,7 +50,6 @@ export function ObjectInfo({
|
||||
const dialog = useDialog()
|
||||
const objectApi = useObject(bucketName)
|
||||
const client = useS3()
|
||||
const { permanentCredentials } = useAuth()
|
||||
|
||||
const [object, setObject] = React.useState<Record<string, unknown> | null>(null)
|
||||
const [tags, setTags] = React.useState<Array<{ Key: string; Value: string }>>([])
|
||||
@@ -303,28 +300,7 @@ export function ObjectInfo({
|
||||
}
|
||||
setIsGeneratingUrl(true)
|
||||
try {
|
||||
let url: string
|
||||
const creds = permanentCredentials
|
||||
if (creds?.AccessKeyId && creds?.SecretAccessKey) {
|
||||
const siteConfig = await configManager.loadConfig()
|
||||
const tempClient = new S3Client({
|
||||
endpoint: String(siteConfig.s3.endpoint),
|
||||
region: String(siteConfig.s3.region || "us-east-1"),
|
||||
forcePathStyle: true,
|
||||
credentials: {
|
||||
accessKeyId: String(creds.AccessKeyId),
|
||||
secretAccessKey: String(creds.SecretAccessKey),
|
||||
sessionToken: typeof creds.SessionToken === "string" ? creds.SessionToken : undefined,
|
||||
},
|
||||
})
|
||||
const command = new GetObjectCommand({
|
||||
Bucket: bucketName,
|
||||
Key: object.Key as string,
|
||||
})
|
||||
url = await getSignedUrl(tempClient, command, { expiresIn: totalExpirationSeconds })
|
||||
} else {
|
||||
url = await objectApi.getSignedUrl(object.Key as string, totalExpirationSeconds)
|
||||
}
|
||||
const url = await objectApi.getSignedUrl(object.Key as string, totalExpirationSeconds)
|
||||
setSignedUrl(url)
|
||||
message.success(t("URL generated successfully"))
|
||||
} catch (err) {
|
||||
@@ -551,8 +527,13 @@ export function ObjectInfo({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 min-w-0 w-full">
|
||||
<div className="flex flex-col gap-2 min-w-0 w-full">
|
||||
<CopyInput value={signedUrl} readonly copyIcon className="min-w-0 flex-1" />
|
||||
{signedUrl && (
|
||||
<div className="text-xs text-amber-600 mt-1">
|
||||
{t("This link will expire when your session ends or at the specified time.")}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ItemContent>
|
||||
</Item>
|
||||
|
||||
@@ -25,7 +25,6 @@ interface AuthContextValue {
|
||||
setIsAdmin: (value: boolean) => void
|
||||
getIsAdmin: () => boolean
|
||||
credentials: Credentials | undefined
|
||||
permanentCredentials: Credentials | undefined
|
||||
isAuthenticated: boolean
|
||||
isAdmin: boolean
|
||||
}
|
||||
@@ -48,7 +47,6 @@ function isValidCredentials(credentials: Credentials | undefined): boolean {
|
||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [store, setStore] = useLocalStorage<Credentials | undefined>("auth.credentials", undefined)
|
||||
const [isAdminStore, setIsAdminStore] = useLocalStorage<boolean | undefined>("auth.isAdmin", undefined)
|
||||
const [permanentStore, setPermanentStore] = useLocalStorage<Credentials | undefined>("auth.permanent", undefined)
|
||||
|
||||
const setCredentials = useCallback(
|
||||
(credentials: Credentials) => {
|
||||
@@ -57,13 +55,6 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
[setStore],
|
||||
)
|
||||
|
||||
const setPermanentCredentials = useCallback(
|
||||
(credentials: Credentials) => {
|
||||
setPermanentStore(credentials)
|
||||
},
|
||||
[setPermanentStore],
|
||||
)
|
||||
|
||||
const getCredentials = useCallback(() => {
|
||||
if (!isValidCredentials(store)) return undefined
|
||||
return store
|
||||
@@ -97,18 +88,9 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
Expiration: credentialsResponse.Expiration?.toISOString(),
|
||||
})
|
||||
|
||||
if (typeof credentials === "object" && !("sessionToken" in credentials && credentials.sessionToken)) {
|
||||
setPermanentCredentials({
|
||||
AccessKeyId: credentials.accessKeyId,
|
||||
SecretAccessKey: credentials.secretAccessKey,
|
||||
})
|
||||
} else {
|
||||
setPermanentStore(undefined)
|
||||
}
|
||||
|
||||
return credentialsResponse
|
||||
},
|
||||
[setCredentials, setPermanentCredentials, setPermanentStore],
|
||||
[setCredentials],
|
||||
)
|
||||
|
||||
const loginWithStsCredentials = useCallback(
|
||||
@@ -119,16 +101,14 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
SessionToken: creds.SessionToken,
|
||||
Expiration: creds.Expiration,
|
||||
})
|
||||
setPermanentStore(undefined)
|
||||
},
|
||||
[setCredentials, setPermanentStore],
|
||||
[setCredentials],
|
||||
)
|
||||
|
||||
const logout = useCallback(() => {
|
||||
setStore(undefined)
|
||||
setPermanentStore(undefined)
|
||||
setIsAdminStore(undefined)
|
||||
}, [setStore, setPermanentStore, setIsAdminStore])
|
||||
}, [setStore, setIsAdminStore])
|
||||
|
||||
const logoutAndRedirect = useCallback(() => {
|
||||
logout()
|
||||
@@ -147,7 +127,6 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
setIsAdmin,
|
||||
getIsAdmin,
|
||||
credentials,
|
||||
permanentCredentials: permanentStore,
|
||||
isAuthenticated,
|
||||
isAdmin: !!isAdminStore,
|
||||
}),
|
||||
@@ -159,7 +138,6 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
setIsAdmin,
|
||||
getIsAdmin,
|
||||
credentials,
|
||||
permanentStore,
|
||||
isAuthenticated,
|
||||
isAdminStore,
|
||||
],
|
||||
|
||||
@@ -768,6 +768,7 @@
|
||||
"The two passwords are inconsistent": "The two passwords are inconsistent",
|
||||
"This action cannot be undone and will bypass the normal deletion process.": "This action cannot be undone and will bypass the normal deletion process.",
|
||||
"This action cannot be undone.": "This action cannot be undone.",
|
||||
"This link will expire when your session ends or at the specified time.": "This link will expire when your session ends or at the specified time.",
|
||||
"Thursday": "Thursday",
|
||||
"Tier": "Tier",
|
||||
"Tier Type": "Tier Type",
|
||||
|
||||
@@ -770,6 +770,8 @@
|
||||
"The two passwords are inconsistent": "两个密码不一致",
|
||||
"This action cannot be undone and will bypass the normal deletion process.": "此操作无法撤销,将绕过正常删除过程。",
|
||||
"This action cannot be undone.": "此操作无法撤销。",
|
||||
"This link will expire when your session ends or at the specified time.": "此链接将会在您的登录会话结束或达到指定时间后失效。",
|
||||
"This user already exists": "该用户已存在",
|
||||
"Thursday": "星期四",
|
||||
"Tier": "存储层",
|
||||
"Tier Type": "存储层类型",
|
||||
|
||||
Reference in New Issue
Block a user