mirror of
https://github.com/usememos/memos.git
synced 2024-12-25 12:23:09 +03: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:
parent
e062c9b4a7
commit
9d4bb5b3af
@ -12,6 +12,7 @@ type StorageConfig struct {
|
||||
|
||||
type StorageS3Config struct {
|
||||
EndPoint string `json:"endPoint"`
|
||||
Path string `json:"path"`
|
||||
Region string `json:"region"`
|
||||
AccessKey string `json:"accessKey"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
s3config "github.com/aws/aws-sdk-go-v2/config"
|
||||
@ -18,6 +19,7 @@ type Config struct {
|
||||
SecretKey string
|
||||
Bucket string
|
||||
EndPoint string
|
||||
Path string
|
||||
Region string
|
||||
URLPrefix string
|
||||
}
|
||||
@ -55,7 +57,7 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
|
||||
uploader := manager.NewUploader(client.Client)
|
||||
uploadOutput, err := uploader.Upload(ctx, &awss3.PutObjectInput{
|
||||
Bucket: aws.String(client.Config.Bucket),
|
||||
Key: aws.String(filename),
|
||||
Key: aws.String(path.Join(client.Config.Path, filename)),
|
||||
Body: src,
|
||||
ContentType: aws.String(fileType),
|
||||
ACL: types.ObjectCannedACL(*aws.String("public-read")),
|
||||
|
@ -139,6 +139,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
|
||||
AccessKey: s3Config.AccessKey,
|
||||
SecretKey: s3Config.SecretKey,
|
||||
EndPoint: s3Config.EndPoint,
|
||||
Path: s3Config.Path,
|
||||
Region: s3Config.Region,
|
||||
Bucket: s3Config.Bucket,
|
||||
URLPrefix: s3Config.URLPrefix,
|
||||
|
@ -21,6 +21,7 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
|
||||
region: "",
|
||||
accessKey: "",
|
||||
secretKey: "",
|
||||
path: "",
|
||||
bucket: "",
|
||||
urlPrefix: "",
|
||||
});
|
||||
@ -181,6 +182,17 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
|
||||
onChange={(e) => setPartialS3Config({ bucket: e.target.value })}
|
||||
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">
|
||||
URLPrefix
|
||||
<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;
|
||||
accessKey: string;
|
||||
secretKey: string;
|
||||
path: string;
|
||||
bucket: string;
|
||||
urlPrefix: string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user