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"` SecretKey string `json:"secretKey"`
Bucket string `json:"bucket"` Bucket string `json:"bucket"`
URLPrefix string `json:"urlPrefix"` URLPrefix string `json:"urlPrefix"`
URLSuffix string `json:"urlSuffix"`
} }
type Storage struct { type Storage struct {

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

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

@ -25,6 +25,7 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
path: "", path: "",
bucket: "", bucket: "",
urlPrefix: "", urlPrefix: "",
urlSuffix: "",
}); });
const isCreating = storage === undefined; const isCreating = storage === undefined;
@ -221,6 +222,17 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
onChange={(e) => setPartialS3Config({ urlPrefix: e.target.value })} onChange={(e) => setPartialS3Config({ urlPrefix: e.target.value })}
fullWidth 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"> <div className="mt-2 w-full flex flex-row justify-end items-center space-x-1">
<Button variant="plain" color="neutral" onClick={handleCloseBtnClick}> <Button variant="plain" color="neutral" onClick={handleCloseBtnClick}>
Cancel Cancel

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

Loading…
Cancel
Save