mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 20:27:23 +00:00
add domain parameter to createS3Storage and update related components
This commit is contained in:
@@ -448,8 +448,14 @@ class Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createS3Storage(name: string, endPoint: string, accessKeyID: string,
|
async createS3Storage(
|
||||||
secretAccessKey: string, bucketName: string, maxSizeInMB: number): Promise<Response<any>> {
|
name: string,
|
||||||
|
endPoint: string,
|
||||||
|
accessKeyID: string,
|
||||||
|
secretAccessKey: string,
|
||||||
|
bucketName: string,
|
||||||
|
maxSizeInMB: number,
|
||||||
|
domain: string): Promise<Response<any>> {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(`${this.apiBaseUrl}/storage/s3`, {
|
const response = await axios.post(`${this.apiBaseUrl}/storage/s3`, {
|
||||||
name,
|
name,
|
||||||
@@ -457,7 +463,8 @@ class Network {
|
|||||||
accessKeyID,
|
accessKeyID,
|
||||||
secretAccessKey,
|
secretAccessKey,
|
||||||
bucketName,
|
bucketName,
|
||||||
maxSizeInMB
|
maxSizeInMB,
|
||||||
|
domain
|
||||||
});
|
});
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@@ -163,6 +163,7 @@ function NewStorageDialog({onAdded}: { onAdded: () => void }) {
|
|||||||
secretAccessKey: "",
|
secretAccessKey: "",
|
||||||
bucketName: "",
|
bucketName: "",
|
||||||
maxSizeInMB: 0,
|
maxSizeInMB: 0,
|
||||||
|
domain: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
@@ -189,7 +190,7 @@ function NewStorageDialog({onAdded}: { onAdded: () => void }) {
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
response = await network.createS3Storage(params.name, params.endPoint, params.accessKeyID, params.secretAccessKey, params.bucketName, params.maxSizeInMB);
|
response = await network.createS3Storage(params.name, params.endPoint, params.accessKeyID, params.secretAccessKey, params.bucketName, params.maxSizeInMB, params.domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response!.success) {
|
if (response!.success) {
|
||||||
@@ -316,6 +317,15 @@ function NewStorageDialog({onAdded}: { onAdded: () => void }) {
|
|||||||
})
|
})
|
||||||
}} />
|
}} />
|
||||||
</label>
|
</label>
|
||||||
|
<label className="input w-full my-2">
|
||||||
|
{t("Domain")}
|
||||||
|
<input type="text" placeholder={t("Optional")} className="w-full" value={params.domain} onChange={(e) => {
|
||||||
|
setParams({
|
||||||
|
...params,
|
||||||
|
domain: e.target.value,
|
||||||
|
})
|
||||||
|
}} />
|
||||||
|
</label>
|
||||||
<label className="input w-full my-2">
|
<label className="input w-full my-2">
|
||||||
{t("Max Size (MB)")}
|
{t("Max Size (MB)")}
|
||||||
<input
|
<input
|
||||||
|
@@ -14,6 +14,7 @@ type CreateS3StorageParams struct {
|
|||||||
EndPoint string `json:"endPoint"`
|
EndPoint string `json:"endPoint"`
|
||||||
AccessKeyID string `json:"accessKeyID"`
|
AccessKeyID string `json:"accessKeyID"`
|
||||||
SecretAccessKey string `json:"secretAccessKey"`
|
SecretAccessKey string `json:"secretAccessKey"`
|
||||||
|
Domain string `json:"domain"`
|
||||||
BucketName string `json:"bucketName"`
|
BucketName string `json:"bucketName"`
|
||||||
MaxSizeInMB uint `json:"maxSizeInMB"`
|
MaxSizeInMB uint `json:"maxSizeInMB"`
|
||||||
}
|
}
|
||||||
@@ -32,6 +33,7 @@ func CreateS3Storage(uid uint, params CreateS3StorageParams) error {
|
|||||||
AccessKeyID: params.AccessKeyID,
|
AccessKeyID: params.AccessKeyID,
|
||||||
SecretAccessKey: params.SecretAccessKey,
|
SecretAccessKey: params.SecretAccessKey,
|
||||||
BucketName: params.BucketName,
|
BucketName: params.BucketName,
|
||||||
|
Domain: params.Domain,
|
||||||
}
|
}
|
||||||
s := model.Storage{
|
s := model.Storage{
|
||||||
Name: params.Name,
|
Name: params.Name,
|
||||||
|
@@ -5,12 +5,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3/log"
|
"github.com/gofiber/fiber/v3/log"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
"net/url"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type S3Storage struct {
|
type S3Storage struct {
|
||||||
@@ -18,6 +19,7 @@ type S3Storage struct {
|
|||||||
AccessKeyID string
|
AccessKeyID string
|
||||||
SecretAccessKey string
|
SecretAccessKey string
|
||||||
BucketName string
|
BucketName string
|
||||||
|
Domain string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *S3Storage) Upload(filePath string, fileName string) (string, error) {
|
func (s *S3Storage) Upload(filePath string, fileName string) (string, error) {
|
||||||
@@ -43,6 +45,10 @@ func (s *S3Storage) Upload(filePath string, fileName string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *S3Storage) Download(storageKey string, fileName string) (string, error) {
|
func (s *S3Storage) Download(storageKey string, fileName string) (string, error) {
|
||||||
|
if s.Domain != "" {
|
||||||
|
return s.Domain + "/" + storageKey, nil
|
||||||
|
}
|
||||||
|
|
||||||
minioClient, err := minio.New(s.EndPoint, &minio.Options{
|
minioClient, err := minio.New(s.EndPoint, &minio.Options{
|
||||||
Creds: credentials.NewStaticV4(s.AccessKeyID, s.SecretAccessKey, ""),
|
Creds: credentials.NewStaticV4(s.AccessKeyID, s.SecretAccessKey, ""),
|
||||||
Secure: true,
|
Secure: true,
|
||||||
@@ -80,6 +86,7 @@ func (s *S3Storage) FromString(config string) error {
|
|||||||
s.AccessKeyID = s3Config.AccessKeyID
|
s.AccessKeyID = s3Config.AccessKeyID
|
||||||
s.SecretAccessKey = s3Config.SecretAccessKey
|
s.SecretAccessKey = s3Config.SecretAccessKey
|
||||||
s.BucketName = s3Config.BucketName
|
s.BucketName = s3Config.BucketName
|
||||||
|
s.Domain = s3Config.Domain
|
||||||
if s.EndPoint == "" || s.AccessKeyID == "" || s.SecretAccessKey == "" || s.BucketName == "" {
|
if s.EndPoint == "" || s.AccessKeyID == "" || s.SecretAccessKey == "" || s.BucketName == "" {
|
||||||
return errors.New("invalid S3 configuration")
|
return errors.New("invalid S3 configuration")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user