mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: add support for s3 path (#1233)
* add support for path * fix typo and switch positions with Path and Bucket * using path method instead of string concatenation
This commit is contained in:
@ -12,6 +12,7 @@ type StorageConfig struct {
|
|||||||
|
|
||||||
type StorageS3Config struct {
|
type StorageS3Config struct {
|
||||||
EndPoint string `json:"endPoint"`
|
EndPoint string `json:"endPoint"`
|
||||||
|
Path string `json:"path"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region"`
|
||||||
AccessKey string `json:"accessKey"`
|
AccessKey string `json:"accessKey"`
|
||||||
SecretKey string `json:"secretKey"`
|
SecretKey string `json:"secretKey"`
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
s3config "github.com/aws/aws-sdk-go-v2/config"
|
s3config "github.com/aws/aws-sdk-go-v2/config"
|
||||||
@ -18,6 +19,7 @@ type Config struct {
|
|||||||
SecretKey string
|
SecretKey string
|
||||||
Bucket string
|
Bucket string
|
||||||
EndPoint string
|
EndPoint string
|
||||||
|
Path string
|
||||||
Region string
|
Region string
|
||||||
URLPrefix string
|
URLPrefix string
|
||||||
}
|
}
|
||||||
@ -55,7 +57,7 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
|
|||||||
uploader := manager.NewUploader(client.Client)
|
uploader := manager.NewUploader(client.Client)
|
||||||
uploadOutput, err := uploader.Upload(ctx, &awss3.PutObjectInput{
|
uploadOutput, err := uploader.Upload(ctx, &awss3.PutObjectInput{
|
||||||
Bucket: aws.String(client.Config.Bucket),
|
Bucket: aws.String(client.Config.Bucket),
|
||||||
Key: aws.String(filename),
|
Key: aws.String(path.Join(client.Config.Path, filename)),
|
||||||
Body: src,
|
Body: src,
|
||||||
ContentType: aws.String(fileType),
|
ContentType: aws.String(fileType),
|
||||||
ACL: types.ObjectCannedACL(*aws.String("public-read")),
|
ACL: types.ObjectCannedACL(*aws.String("public-read")),
|
||||||
|
@ -139,6 +139,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
|
|||||||
AccessKey: s3Config.AccessKey,
|
AccessKey: s3Config.AccessKey,
|
||||||
SecretKey: s3Config.SecretKey,
|
SecretKey: s3Config.SecretKey,
|
||||||
EndPoint: s3Config.EndPoint,
|
EndPoint: s3Config.EndPoint,
|
||||||
|
Path: s3Config.Path,
|
||||||
Region: s3Config.Region,
|
Region: s3Config.Region,
|
||||||
Bucket: s3Config.Bucket,
|
Bucket: s3Config.Bucket,
|
||||||
URLPrefix: s3Config.URLPrefix,
|
URLPrefix: s3Config.URLPrefix,
|
||||||
|
@ -21,6 +21,7 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
|
|||||||
region: "",
|
region: "",
|
||||||
accessKey: "",
|
accessKey: "",
|
||||||
secretKey: "",
|
secretKey: "",
|
||||||
|
path: "",
|
||||||
bucket: "",
|
bucket: "",
|
||||||
urlPrefix: "",
|
urlPrefix: "",
|
||||||
});
|
});
|
||||||
@ -181,6 +182,17 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
|
|||||||
onChange={(e) => setPartialS3Config({ bucket: e.target.value })}
|
onChange={(e) => setPartialS3Config({ bucket: e.target.value })}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
|
<Typography className="!mb-1" level="body2">
|
||||||
|
Path
|
||||||
|
<span className="text-sm text-gray-400 ml-1">(Storage Path)</span>
|
||||||
|
</Typography>
|
||||||
|
<Input
|
||||||
|
className="mb-2"
|
||||||
|
placeholder="Path"
|
||||||
|
value={s3Config.path}
|
||||||
|
onChange={(e) => setPartialS3Config({ path: e.target.value })}
|
||||||
|
fullWidth
|
||||||
|
/>
|
||||||
<Typography className="!mb-1" level="body2">
|
<Typography className="!mb-1" level="body2">
|
||||||
URLPrefix
|
URLPrefix
|
||||||
<span className="text-sm text-gray-400 ml-1">(Custom URL prefix; Optional)</span>
|
<span className="text-sm text-gray-400 ml-1">(Custom URL prefix; Optional)</span>
|
||||||
|
1
web/src/types/modules/storage.d.ts
vendored
1
web/src/types/modules/storage.d.ts
vendored
@ -7,6 +7,7 @@ interface StorageS3Config {
|
|||||||
region: string;
|
region: string;
|
||||||
accessKey: string;
|
accessKey: string;
|
||||||
secretKey: string;
|
secretKey: string;
|
||||||
|
path: string;
|
||||||
bucket: string;
|
bucket: string;
|
||||||
urlPrefix: string;
|
urlPrefix: string;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user