Enable object store for self-hosted instance (#1739)

This commit is contained in:
Luke Vella 2025-05-28 17:33:41 +01:00
parent 294ab49e9f
commit fbccc4f98b
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C
7 changed files with 98 additions and 54 deletions

View file

@ -0,0 +1,37 @@
"use client";
import React from "react";
interface Features {
storage: boolean;
}
const FeatureFlagsContext = React.createContext<Features | undefined>(
undefined,
);
interface FeatureFlagsProviderProps {
value: Features;
children: React.ReactNode;
}
export function FeatureFlagsProvider({
value,
children,
}: FeatureFlagsProviderProps) {
return (
<FeatureFlagsContext.Provider value={value}>
{children}
</FeatureFlagsContext.Provider>
);
}
export function useFeatureFlag(featureName: keyof Features): boolean {
const context = React.useContext(FeatureFlagsContext);
if (context === undefined) {
throw new Error(
"useFeatureFlag must be used within a FeatureFlagsProvider",
);
}
return context[featureName] ?? false;
}

View file

@ -0,0 +1,4 @@
export const isStorageEnabled =
!!process.env.S3_BUCKET_NAME &&
!!process.env.S3_ACCESS_KEY_ID &&
!!process.env.S3_SECRET_ACCESS_KEY;

View file

@ -0,0 +1,26 @@
import { S3Client } from "@aws-sdk/client-s3";
import { env } from "@/env";
export function getS3Client() {
if (
!env.S3_BUCKET_NAME ||
!env.S3_ACCESS_KEY_ID ||
!env.S3_SECRET_ACCESS_KEY
) {
return null;
}
const s3Client = new S3Client({
region: env.S3_REGION,
endpoint: env.S3_ENDPOINT,
credentials: {
accessKeyId: env.S3_ACCESS_KEY_ID,
secretAccessKey: env.S3_SECRET_ACCESS_KEY,
},
// S3 compatible storage requires path style
forcePathStyle: true,
});
return s3Client;
}