feat: add URLSuffix resource option with S3 (#1428)

* feat: add URLSuffix resource option with S3

* feat: add URLSuffix resource option with S3

* fix: eslint
pull/1433/head
Xudong Cai 2 years ago committed by GitHub
parent 8eed9c267c
commit d21abfc60c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,6 +18,7 @@ type StorageS3Config struct {
SecretKey string `json:"secretKey"`
Bucket string `json:"bucket"`
URLPrefix string `json:"urlPrefix"`
URLSuffix string `json:"urlSuffix"`
}
type Storage struct {

@ -20,6 +20,7 @@ type Config struct {
EndPoint string
Region string
URLPrefix string
URLSuffix string
}
type Client struct {
@ -67,7 +68,7 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
link := uploadOutput.Location
// If url prefix is set, use it as the file link.
if client.Config.URLPrefix != "" {
link = fmt.Sprintf("%s/%s", client.Config.URLPrefix, filename)
link = fmt.Sprintf("%s/%s%s", client.Config.URLPrefix, filename, client.Config.URLSuffix)
}
if link == "" {
return "", fmt.Errorf("failed to get file link")

@ -194,6 +194,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
Region: s3Config.Region,
Bucket: s3Config.Bucket,
URLPrefix: s3Config.URLPrefix,
URLSuffix: s3Config.URLSuffix,
})
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to new s3 client").SetInternal(err)

@ -25,6 +25,7 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
path: "",
bucket: "",
urlPrefix: "",
urlSuffix: "",
});
const isCreating = storage === undefined;
@ -221,6 +222,17 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
onChange={(e) => setPartialS3Config({ urlPrefix: e.target.value })}
fullWidth
/>
<Typography className="!mb-1" level="body2">
URLSuffix
<span className="text-sm text-gray-400 ml-1">(Custom URL suffix; Optional)</span>
</Typography>
<Input
className="mb-2"
placeholder="URLSuffix"
value={s3Config.urlSuffix}
onChange={(e) => setPartialS3Config({ urlSuffix: e.target.value })}
fullWidth
/>
<div className="mt-2 w-full flex flex-row justify-end items-center space-x-1">
<Button variant="plain" color="neutral" onClick={handleCloseBtnClick}>
Cancel

@ -10,6 +10,7 @@ interface StorageS3Config {
path: string;
bucket: string;
urlPrefix: string;
urlSuffix: string;
}
interface StorageConfig {

Loading…
Cancel
Save