diff --git a/components/object/info.tsx b/components/object/info.tsx index 3a63bc1..1fe6437 100644 --- a/components/object/info.tsx +++ b/components/object/info.tsx @@ -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 | null>(null) const [tags, setTags] = React.useState>([]) @@ -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({ )} -
+
+ {signedUrl && ( +
+ {t("This link will expire when your session ends or at the specified time.")} +
+ )}
diff --git a/contexts/auth-context.tsx b/contexts/auth-context.tsx index c0b8f49..2810da1 100644 --- a/contexts/auth-context.tsx +++ b/contexts/auth-context.tsx @@ -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("auth.credentials", undefined) const [isAdminStore, setIsAdminStore] = useLocalStorage("auth.isAdmin", undefined) - const [permanentStore, setPermanentStore] = useLocalStorage("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, ], diff --git a/i18n/locales/en-US.json b/i18n/locales/en-US.json index 4a95a90..806a324 100644 --- a/i18n/locales/en-US.json +++ b/i18n/locales/en-US.json @@ -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", diff --git a/i18n/locales/zh-CN.json b/i18n/locales/zh-CN.json index e8ca103..b034e2b 100644 --- a/i18n/locales/zh-CN.json +++ b/i18n/locales/zh-CN.json @@ -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": "存储层类型",