Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
7e8011ba
Unverified
Commit
7e8011ba
authored
Feb 15, 2023
by
boojack
Committed by
GitHub
Feb 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: support deleting storage (#1095)
parent
e46f7768
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
86 additions
and
55 deletions
+86
-55
system_setting.go
api/system_setting.go
+10
-5
go.mod
go.mod
+2
-2
go.sum
go.sum
+4
-2
s3.go
plugin/storage/s3/s3.go
+3
-3
auth.go
server/auth.go
+1
-2
memo.go
server/memo.go
+4
-5
resource.go
server/resource.go
+9
-21
storage.go
server/storage.go
+15
-0
system.go
server/system.go
+6
-8
system_setting.go
store/system_setting.go
+1
-4
CreateStorageServiceDialog.tsx
web/src/components/CreateStorageServiceDialog.tsx
+31
-3
No files found.
api/system_setting.go
View file @
7e8011ba
...
@@ -25,8 +25,8 @@ const (
...
@@ -25,8 +25,8 @@ const (
SystemSettingAdditionalScriptName
SystemSettingName
=
"additionalScript"
SystemSettingAdditionalScriptName
SystemSettingName
=
"additionalScript"
// SystemSettingCustomizedProfileName is the key type of customized server profile.
// SystemSettingCustomizedProfileName is the key type of customized server profile.
SystemSettingCustomizedProfileName
SystemSettingName
=
"customizedProfile"
SystemSettingCustomizedProfileName
SystemSettingName
=
"customizedProfile"
// SystemSettingStorageServiceID
is the key type of sot
rage service ID.
// SystemSettingStorageServiceID
Name is the key type of sto
rage service ID.
SystemSettingStorageServiceID
SystemSettingName
=
"storageServiceId"
SystemSettingStorageServiceID
Name
SystemSettingName
=
"storageServiceId"
)
)
// CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item.
// CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item.
...
@@ -61,7 +61,7 @@ func (key SystemSettingName) String() string {
...
@@ -61,7 +61,7 @@ func (key SystemSettingName) String() string {
return
"additionalScript"
return
"additionalScript"
case
SystemSettingCustomizedProfileName
:
case
SystemSettingCustomizedProfileName
:
return
"customizedProfile"
return
"customizedProfile"
case
SystemSettingStorageServiceID
:
case
SystemSettingStorageServiceID
Name
:
return
"storageServiceId"
return
"storageServiceId"
}
}
return
""
return
""
...
@@ -154,7 +154,12 @@ func (upsert SystemSettingUpsert) Validate() error {
...
@@ -154,7 +154,12 @@ func (upsert SystemSettingUpsert) Validate() error {
if
!
slices
.
Contains
(
UserSettingAppearanceValue
,
customizedProfile
.
Appearance
)
{
if
!
slices
.
Contains
(
UserSettingAppearanceValue
,
customizedProfile
.
Appearance
)
{
return
fmt
.
Errorf
(
"invalid appearance value"
)
return
fmt
.
Errorf
(
"invalid appearance value"
)
}
}
}
else
if
upsert
.
Name
==
SystemSettingStorageServiceID
{
}
else
if
upsert
.
Name
==
SystemSettingStorageServiceIDName
{
value
:=
0
err
:=
json
.
Unmarshal
([]
byte
(
upsert
.
Value
),
&
value
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to unmarshal system setting storage service id value"
)
}
return
nil
return
nil
}
else
{
}
else
{
return
fmt
.
Errorf
(
"invalid system setting name"
)
return
fmt
.
Errorf
(
"invalid system setting name"
)
...
@@ -164,5 +169,5 @@ func (upsert SystemSettingUpsert) Validate() error {
...
@@ -164,5 +169,5 @@ func (upsert SystemSettingUpsert) Validate() error {
}
}
type
SystemSettingFind
struct
{
type
SystemSettingFind
struct
{
Name
*
SystemSettingName
`json:"name"`
Name
SystemSettingName
`json:"name"`
}
}
go.mod
View file @
7e8011ba
...
@@ -25,7 +25,7 @@ require (
...
@@ -25,7 +25,7 @@ require (
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.28 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.28 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.22 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.
19
// indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.
20
// indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.23 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.23 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.22 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.22 // indirect
...
@@ -63,7 +63,7 @@ require (
...
@@ -63,7 +63,7 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.18.12
github.com/aws/aws-sdk-go-v2/config v1.18.12
github.com/aws/aws-sdk-go-v2/credentials v1.13.12
github.com/aws/aws-sdk-go-v2/credentials v1.13.12
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.51
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.51
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.
2
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.
3
github.com/pkg/errors v0.9.1
github.com/pkg/errors v0.9.1
github.com/segmentio/analytics-go v3.1.0+incompatible
github.com/segmentio/analytics-go v3.1.0+incompatible
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.0
...
...
go.sum
View file @
7e8011ba
...
@@ -16,8 +16,9 @@ github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.22 h1:7AwGYXDdqRQYsluvKF
...
@@ -16,8 +16,9 @@ github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.22 h1:7AwGYXDdqRQYsluvKF
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.22/go.mod h1:EqK7gVrIGAHyZItrD1D8B0ilgwMD1GiWAmbU4u/JHNk=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.22/go.mod h1:EqK7gVrIGAHyZItrD1D8B0ilgwMD1GiWAmbU4u/JHNk=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.29 h1:J4xhFd6zHhdF9jPP0FQJ6WknzBboGMBNjKOv4iTuw4A=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.29 h1:J4xhFd6zHhdF9jPP0FQJ6WknzBboGMBNjKOv4iTuw4A=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.29/go.mod h1:TwuqRBGzxjQJIwH16/fOZodwXt2Zxa9/cwJC5ke4j7s=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.29/go.mod h1:TwuqRBGzxjQJIwH16/fOZodwXt2Zxa9/cwJC5ke4j7s=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.19 h1:FGvpyTg2LKEmMrLlpjOgkoNp9XF5CGeyAyo33LdqZW8=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.19/go.mod h1:8W88sW3PjamQpKFUQvHWWKay6ARsNvZnzU7+a4apubw=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.19/go.mod h1:8W88sW3PjamQpKFUQvHWWKay6ARsNvZnzU7+a4apubw=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.20 h1:YIvKIfPXQVp0EhXUV644kmQo6cQPPSRmC44A1HSoJeg=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.20/go.mod h1:8W88sW3PjamQpKFUQvHWWKay6ARsNvZnzU7+a4apubw=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 h1:y2+VQzC6Zh2ojtV2LoC0MNwHWc6qXv/j2vrQtlftkdA=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 h1:y2+VQzC6Zh2ojtV2LoC0MNwHWc6qXv/j2vrQtlftkdA=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11/go.mod h1:iV4q2hsqtNECrfmlXyord9u4zyuFEJX9eLgLpSPzWA8=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11/go.mod h1:iV4q2hsqtNECrfmlXyord9u4zyuFEJX9eLgLpSPzWA8=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.23 h1:c5+bNdV8E4fIPteWx4HZSkqI07oY9exbfQ7JH7Yx4PI=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.23 h1:c5+bNdV8E4fIPteWx4HZSkqI07oY9exbfQ7JH7Yx4PI=
...
@@ -26,8 +27,9 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.22 h1:LjFQf8hFu
...
@@ -26,8 +27,9 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.22 h1:LjFQf8hFu
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.22/go.mod h1:xt0Au8yPIwYXf/GYPy/vl4K3CgwhfQMYbrH7DlUUIws=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.22/go.mod h1:xt0Au8yPIwYXf/GYPy/vl4K3CgwhfQMYbrH7DlUUIws=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.22 h1:ISLJ2BKXe4zzyZ7mp5ewKECiw0U7KpLgS3S6OxY9Cm0=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.22 h1:ISLJ2BKXe4zzyZ7mp5ewKECiw0U7KpLgS3S6OxY9Cm0=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.22/go.mod h1:QFVbqK54XArazLvn2wvWMRBi/jGrWii46qbr5DyPGjc=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.13.22/go.mod h1:QFVbqK54XArazLvn2wvWMRBi/jGrWii46qbr5DyPGjc=
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.2 h1:5EQWIFO+Hc8E2hFcXQJ1vm6ufl/PMt/6RVRDZRju2vM=
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.2/go.mod h1:SXDHd6fI2RhqB7vmAzyYQCTQnpZrIprVJvYxpzW3JAM=
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.2/go.mod h1:SXDHd6fI2RhqB7vmAzyYQCTQnpZrIprVJvYxpzW3JAM=
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.3 h1:PVieHTwugdlHedlxLpYLQsOZAq736RScuEb/m4zhzc4=
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.3/go.mod h1:XN3YcdmnWYZ3Hrnojvo5p2mc/wfF973nkq3ClXPDMHk=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.1 h1:lQKN/LNa3qqu2cDOQZybP7oL4nMGGiFqob0jZJaR8/4=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.1 h1:lQKN/LNa3qqu2cDOQZybP7oL4nMGGiFqob0jZJaR8/4=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.1/go.mod h1:IgV8l3sj22nQDd5qcAGY0WenwCzCphqdbFOpfktZPrI=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.1/go.mod h1:IgV8l3sj22nQDd5qcAGY0WenwCzCphqdbFOpfktZPrI=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.1 h1:0bLhH6DRAqox+g0LatcjGKjjhU6Eudyys6HB6DJVPj8=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.1 h1:0bLhH6DRAqox+g0LatcjGKjjhU6Eudyys6HB6DJVPj8=
...
...
plugin/storage/s3/s3.go
View file @
7e8011ba
...
@@ -45,7 +45,7 @@ func NewClient(ctx context.Context, storage *api.Storage) (*Client, error) {
...
@@ -45,7 +45,7 @@ func NewClient(ctx context.Context, storage *api.Storage) (*Client, error) {
},
nil
},
nil
}
}
func
(
client
*
Client
)
UploadFile
(
ctx
context
.
Context
,
filename
string
,
fileType
string
,
src
io
.
Reader
,
storage
*
api
.
Storage
)
(
*
string
,
error
)
{
func
(
client
*
Client
)
UploadFile
(
ctx
context
.
Context
,
filename
string
,
fileType
string
,
src
io
.
Reader
,
storage
*
api
.
Storage
)
(
string
,
error
)
{
uploader
:=
manager
.
NewUploader
(
client
.
Client
)
uploader
:=
manager
.
NewUploader
(
client
.
Client
)
resp
,
err
:=
uploader
.
Upload
(
ctx
,
&
awss3
.
PutObjectInput
{
resp
,
err
:=
uploader
.
Upload
(
ctx
,
&
awss3
.
PutObjectInput
{
Bucket
:
aws
.
String
(
client
.
BucketName
),
Bucket
:
aws
.
String
(
client
.
BucketName
),
...
@@ -55,7 +55,7 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
...
@@ -55,7 +55,7 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
ACL
:
types
.
ObjectCannedACL
(
*
aws
.
String
(
"public-read"
)),
ACL
:
types
.
ObjectCannedACL
(
*
aws
.
String
(
"public-read"
)),
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
""
,
err
}
}
var
link
string
var
link
string
if
storage
.
URLPrefix
==
""
{
if
storage
.
URLPrefix
==
""
{
...
@@ -63,5 +63,5 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
...
@@ -63,5 +63,5 @@ func (client *Client) UploadFile(ctx context.Context, filename string, fileType
}
else
{
}
else
{
link
=
fmt
.
Sprintf
(
"%s/%s"
,
storage
.
URLPrefix
,
filename
)
link
=
fmt
.
Sprintf
(
"%s/%s"
,
storage
.
URLPrefix
,
filename
)
}
}
return
&
link
,
nil
return
link
,
nil
}
}
server/auth.go
View file @
7e8011ba
...
@@ -81,9 +81,8 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
...
@@ -81,9 +81,8 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
// Change the default role to host if there is no host user.
// Change the default role to host if there is no host user.
userCreate
.
Role
=
api
.
Host
userCreate
.
Role
=
api
.
Host
}
else
{
}
else
{
systemSettingAllowSignUpName
:=
api
.
SystemSettingAllowSignUpName
allowSignUpSetting
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
allowSignUpSetting
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
Name
:
&
s
ystemSettingAllowSignUpName
,
Name
:
api
.
S
ystemSettingAllowSignUpName
,
})
})
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find system setting"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find system setting"
)
.
SetInternal
(
err
)
...
...
server/memo.go
View file @
7e8011ba
...
@@ -54,20 +54,19 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -54,20 +54,19 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
}
// Find system settings
// Find system settings
disablePublicMemosSystemSettingKey
:=
api
.
SystemSettingDisablePublicMemosName
disablePublicMemosSystemSetting
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
disablePublicMemosSystemSetting
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
Name
:
&
disablePublicMemosSystemSettingKey
,
Name
:
api
.
SystemSettingDisablePublicMemosName
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find system setting"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find system setting"
)
.
SetInternal
(
err
)
}
}
if
disablePublicMemosSystemSetting
!=
nil
{
if
disablePublicMemosSystemSetting
!=
nil
{
disablePublicMemos
Value
:=
false
disablePublicMemos
:=
false
err
=
json
.
Unmarshal
([]
byte
(
disablePublicMemosSystemSetting
.
Value
),
&
disablePublicMemos
Value
)
err
=
json
.
Unmarshal
([]
byte
(
disablePublicMemosSystemSetting
.
Value
),
&
disablePublicMemos
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to unmarshal system setting"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to unmarshal system setting"
)
.
SetInternal
(
err
)
}
}
if
disablePublicMemos
Value
{
if
disablePublicMemos
{
memoCreate
.
Visibility
=
api
.
Private
memoCreate
.
Visibility
=
api
.
Private
}
}
}
}
...
...
server/resource.go
View file @
7e8011ba
...
@@ -85,26 +85,20 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -85,26 +85,20 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
}
}
defer
src
.
Close
()
defer
src
.
Close
()
var
resourceCreate
*
api
.
ResourceCreate
systemSetting
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
Name
:
api
.
SystemSettingStorageServiceIDName
})
systemSettingStorageServiceName
:=
api
.
SystemSettingStorageServiceID
systemSetting
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
Name
:
&
systemSettingStorageServiceName
})
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find storage"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find storage"
)
.
SetInternal
(
err
)
}
}
storeLocal
:=
false
storageServiceID
:=
0
if
common
.
ErrorCode
(
err
)
==
common
.
NotFound
{
if
systemSetting
!=
nil
{
storeLocal
=
true
err
=
json
.
Unmarshal
([]
byte
(
systemSetting
.
Value
),
&
storageServiceID
)
}
else
{
var
value
int
err
=
json
.
Unmarshal
([]
byte
(
systemSetting
.
Value
),
&
value
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to unmarshal storage service id"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to unmarshal storage service id"
)
.
SetInternal
(
err
)
}
}
if
value
==
0
{
storeLocal
=
true
}
}
}
if
storeLocal
{
var
resourceCreate
*
api
.
ResourceCreate
if
storageServiceID
==
0
{
fileBytes
,
err
:=
io
.
ReadAll
(
src
)
fileBytes
,
err
:=
io
.
ReadAll
(
src
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to read file"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to read file"
)
.
SetInternal
(
err
)
...
@@ -117,12 +111,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -117,12 +111,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
Blob
:
fileBytes
,
Blob
:
fileBytes
,
}
}
}
else
{
}
else
{
storageID
,
err
:=
strconv
.
Atoi
(
systemSetting
.
Value
)
storage
,
err
:=
s
.
Store
.
FindStorage
(
ctx
,
&
api
.
StorageFind
{
ID
:
&
storageServiceID
})
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to convert storageID"
)
.
SetInternal
(
err
)
}
storage
,
err
:=
s
.
Store
.
FindStorage
(
ctx
,
&
api
.
StorageFind
{
ID
:
&
storageID
})
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find storage"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find storage"
)
.
SetInternal
(
err
)
}
}
...
@@ -136,12 +125,11 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -136,12 +125,11 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to upload via s3 client"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to upload via s3 client"
)
.
SetInternal
(
err
)
}
}
resourceCreate
=
&
api
.
ResourceCreate
{
resourceCreate
=
&
api
.
ResourceCreate
{
CreatorID
:
userID
,
CreatorID
:
userID
,
Filename
:
filename
,
Filename
:
filename
,
Type
:
filetype
,
Type
:
filetype
,
ExternalLink
:
*
link
,
ExternalLink
:
link
,
}
}
}
}
...
...
server/storage.go
View file @
7e8011ba
...
@@ -117,6 +117,21 @@ func (s *Server) registerStorageRoutes(g *echo.Group) {
...
@@ -117,6 +117,21 @@ func (s *Server) registerStorageRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"storageId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"storageId"
)))
.
SetInternal
(
err
)
}
}
systemSetting
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
Name
:
api
.
SystemSettingStorageServiceIDName
})
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find storage"
)
.
SetInternal
(
err
)
}
if
systemSetting
!=
nil
{
storageServiceID
:=
0
err
=
json
.
Unmarshal
([]
byte
(
systemSetting
.
Value
),
&
storageServiceID
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to unmarshal storage service id"
)
.
SetInternal
(
err
)
}
if
storageServiceID
==
storageID
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"Storage service %d is using"
,
storageID
))
}
}
storage
,
err
:=
s
.
Store
.
FindStorage
(
ctx
,
&
api
.
StorageFind
{
storage
,
err
:=
s
.
Store
.
FindStorage
(
ctx
,
&
api
.
StorageFind
{
ID
:
&
storageID
,
ID
:
&
storageID
,
})
})
...
...
server/system.go
View file @
7e8011ba
...
@@ -104,8 +104,8 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
...
@@ -104,8 +104,8 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
if
v
:=
valueMap
[
"externalUrl"
];
v
!=
nil
{
if
v
:=
valueMap
[
"externalUrl"
];
v
!=
nil
{
systemStatus
.
CustomizedProfile
.
ExternalURL
=
v
.
(
string
)
systemStatus
.
CustomizedProfile
.
ExternalURL
=
v
.
(
string
)
}
}
}
else
if
systemSetting
.
Name
==
api
.
SystemSettingStorageServiceID
{
}
else
if
systemSetting
.
Name
==
api
.
SystemSettingStorageServiceID
Name
{
systemStatus
.
StorageServiceID
=
int
(
value
.
(
float64
)
)
systemStatus
.
StorageServiceID
=
value
.
(
int
)
}
}
}
}
...
@@ -209,16 +209,15 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
...
@@ -209,16 +209,15 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
}
}
func
(
s
*
Server
)
getSystemServerID
(
ctx
context
.
Context
)
(
string
,
error
)
{
func
(
s
*
Server
)
getSystemServerID
(
ctx
context
.
Context
)
(
string
,
error
)
{
serverIDKey
:=
api
.
SystemSettingServerID
serverIDValue
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
serverIDValue
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
Name
:
&
serverIDKey
,
Name
:
api
.
SystemSettingServerID
,
})
})
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
return
""
,
err
return
""
,
err
}
}
if
serverIDValue
==
nil
||
serverIDValue
.
Value
==
""
{
if
serverIDValue
==
nil
||
serverIDValue
.
Value
==
""
{
serverIDValue
,
err
=
s
.
Store
.
UpsertSystemSetting
(
ctx
,
&
api
.
SystemSettingUpsert
{
serverIDValue
,
err
=
s
.
Store
.
UpsertSystemSetting
(
ctx
,
&
api
.
SystemSettingUpsert
{
Name
:
serverIDKey
,
Name
:
api
.
SystemSettingServerID
,
Value
:
uuid
.
NewString
(),
Value
:
uuid
.
NewString
(),
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -229,16 +228,15 @@ func (s *Server) getSystemServerID(ctx context.Context) (string, error) {
...
@@ -229,16 +228,15 @@ func (s *Server) getSystemServerID(ctx context.Context) (string, error) {
}
}
func
(
s
*
Server
)
getSystemSecretSessionName
(
ctx
context
.
Context
)
(
string
,
error
)
{
func
(
s
*
Server
)
getSystemSecretSessionName
(
ctx
context
.
Context
)
(
string
,
error
)
{
secretSessionNameKey
:=
api
.
SystemSettingSecretSessionName
secretSessionNameValue
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
secretSessionNameValue
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
Name
:
&
secretSessionNameKey
,
Name
:
api
.
SystemSettingSecretSessionName
,
})
})
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
if
err
!=
nil
&&
common
.
ErrorCode
(
err
)
!=
common
.
NotFound
{
return
""
,
err
return
""
,
err
}
}
if
secretSessionNameValue
==
nil
||
secretSessionNameValue
.
Value
==
""
{
if
secretSessionNameValue
==
nil
||
secretSessionNameValue
.
Value
==
""
{
secretSessionNameValue
,
err
=
s
.
Store
.
UpsertSystemSetting
(
ctx
,
&
api
.
SystemSettingUpsert
{
secretSessionNameValue
,
err
=
s
.
Store
.
UpsertSystemSetting
(
ctx
,
&
api
.
SystemSettingUpsert
{
Name
:
secretSessionNameKey
,
Name
:
api
.
SystemSettingSecretSessionName
,
Value
:
uuid
.
NewString
(),
Value
:
uuid
.
NewString
(),
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
store/system_setting.go
View file @
7e8011ba
...
@@ -114,10 +114,7 @@ func upsertSystemSetting(ctx context.Context, tx *sql.Tx, upsert *api.SystemSett
...
@@ -114,10 +114,7 @@ func upsertSystemSetting(ctx context.Context, tx *sql.Tx, upsert *api.SystemSett
func
findSystemSettingList
(
ctx
context
.
Context
,
tx
*
sql
.
Tx
,
find
*
api
.
SystemSettingFind
)
([]
*
systemSettingRaw
,
error
)
{
func
findSystemSettingList
(
ctx
context
.
Context
,
tx
*
sql
.
Tx
,
find
*
api
.
SystemSettingFind
)
([]
*
systemSettingRaw
,
error
)
{
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
interface
{}{}
where
,
args
=
append
(
where
,
"name = ?"
),
append
(
args
,
find
.
Name
.
String
())
if
v
:=
find
.
Name
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"name = ?"
),
append
(
args
,
v
.
String
())
}
query
:=
`
query
:=
`
SELECT
SELECT
...
...
web/src/components/CreateStorageServiceDialog.tsx
View file @
7e8011ba
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
Icon
from
"./Icon"
;
import
{
generateDialog
}
from
"./Dialog"
;
import
{
Button
,
Input
,
Typography
}
from
"@mui/joy"
;
import
{
Button
,
Input
,
Typography
}
from
"@mui/joy"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useStorageStore
}
from
"../store/module"
;
import
{
useStorageStore
}
from
"../store/module"
;
import
{
generateDialog
}
from
"./Dialog"
;
import
Icon
from
"./Icon"
;
import
toastHelper
from
"./Toast"
;
import
toastHelper
from
"./Toast"
;
import
{
showCommonDialog
}
from
"./Dialog/CommonDialog"
;
interface
Props
extends
DialogProps
{
interface
Props
extends
DialogProps
{
storage
?:
Storage
;
storage
?:
Storage
;
...
@@ -66,6 +67,28 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
...
@@ -66,6 +67,28 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
destroy
();
destroy
();
};
};
const
handleDeleteBtnClick
=
async
()
=>
{
if
(
isCreating
)
{
return
;
}
showCommonDialog
({
title
:
t
(
"setting.storage-section.delete-storage"
),
content
:
t
(
"setting.storage-section.warning-text"
),
style
:
"warning"
,
dialogName
:
"delete-storage-dialog"
,
onConfirm
:
async
()
=>
{
try
{
await
storageStore
.
deleteStorageById
(
storage
.
id
);
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toastHelper
.
error
(
error
.
response
.
data
.
message
);
}
destroy
();
},
});
};
const
handleNameChange
=
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
handleNameChange
=
(
event
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
name
=
event
.
target
.
value
;
const
name
=
event
.
target
.
value
;
setStorageCreate
({
setStorageCreate
({
...
@@ -165,6 +188,11 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
...
@@ -165,6 +188,11 @@ const CreateStorageServiceDialog: React.FC<Props> = (props: Props) => {
<
Button
variant=
"plain"
color=
"neutral"
onClick=
{
handleCloseBtnClick
}
>
<
Button
variant=
"plain"
color=
"neutral"
onClick=
{
handleCloseBtnClick
}
>
Cancel
Cancel
</
Button
>
</
Button
>
{
!
isCreating
&&
(
<
Button
color=
"danger"
onClick=
{
handleDeleteBtnClick
}
>
Delete
</
Button
>
)
}
<
Button
onClick=
{
handleConfirmBtnClick
}
disabled=
{
!
allowConfirmAction
()
}
>
<
Button
onClick=
{
handleConfirmBtnClick
}
disabled=
{
!
allowConfirmAction
()
}
>
{
isCreating
?
"Create"
:
"Update"
}
{
isCreating
?
"Create"
:
"Update"
}
</
Button
>
</
Button
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment