Commit 21ef5a9b authored by Steven's avatar Steven

chore: tweak workspace service

parent 87b23940
......@@ -3,16 +3,15 @@ package v2
import "strings"
var authenticationAllowlistMethods = map[string]bool{
"/memos.api.v2.SystemService/GetSystemInfo": true,
"/memos.api.v2.AuthService/GetAuthStatus": true,
"/memos.api.v2.UserService/GetUser": true,
"/memos.api.v2.MemoService/ListMemos": true,
"/memos.api.v2.MemoService/GetMemo": true,
"/memos.api.v2.MemoService/GetMemoByName": true,
"/memos.api.v2.MemoService/ListMemoResources": true,
"/memos.api.v2.MemoService/ListMemoRelations": true,
"/memos.api.v2.MemoService/ListMemoComments": true,
"/memos.api.v2.MarkdownService/ParseMarkdown": true,
"/memos.api.v2.WorkspaceService/GetWorkspaceProfile": true,
"/memos.api.v2.AuthService/GetAuthStatus": true,
"/memos.api.v2.UserService/GetUser": true,
"/memos.api.v2.MemoService/ListMemos": true,
"/memos.api.v2.MemoService/GetMemo": true,
"/memos.api.v2.MemoService/GetMemoByName": true,
"/memos.api.v2.MemoService/ListMemoResources": true,
"/memos.api.v2.MemoService/ListMemoRelations": true,
"/memos.api.v2.MemoService/ListMemoComments": true,
}
// isUnauthorizeAllowedMethod returns whether the method is exempted from authentication.
......
......@@ -21,7 +21,7 @@ import (
)
type APIV2Service struct {
apiv2pb.UnimplementedSystemServiceServer
apiv2pb.UnimplementedWorkspaceServiceServer
apiv2pb.UnimplementedAuthServiceServer
apiv2pb.UnimplementedUserServiceServer
apiv2pb.UnimplementedMemoServiceServer
......@@ -56,7 +56,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
grpcServerPort: grpcServerPort,
}
apiv2pb.RegisterSystemServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterWorkspaceServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterAuthServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterUserServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterMemoServiceServer(grpcServer, apiv2Service)
......@@ -89,7 +89,7 @@ func (s *APIV2Service) RegisterGateway(ctx context.Context, e *echo.Echo) error
}
gwMux := runtime.NewServeMux()
if err := apiv2pb.RegisterSystemServiceHandler(context.Background(), gwMux, conn); err != nil {
if err := apiv2pb.RegisterWorkspaceServiceHandler(context.Background(), gwMux, conn); err != nil {
return err
}
if err := apiv2pb.RegisterAuthServiceHandler(context.Background(), gwMux, conn); err != nil {
......
......@@ -10,9 +10,9 @@ tags:
- name: MarkdownService
- name: ResourceService
- name: MemoService
- name: SystemService
- name: TagService
- name: WebhookService
- name: WorkspaceService
consumes:
- application/json
produces:
......@@ -546,40 +546,6 @@ paths:
format: int32
tags:
- ResourceService
/api/v2/system/info:
get:
operationId: SystemService_GetSystemInfo
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2GetSystemInfoResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
tags:
- SystemService
patch:
operationId: SystemService_UpdateSystemInfo
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2UpdateSystemInfoResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: systemInfo
description: System info is the updated data.
in: body
required: true
schema:
$ref: '#/definitions/v2SystemInfo'
tags:
- SystemService
/api/v2/tags:
get:
operationId: TagService_ListTags
......@@ -815,6 +781,40 @@ paths:
$ref: '#/definitions/WebhookServiceUpdateWebhookBody'
tags:
- WebhookService
/api/v2/workspace/profile:
get:
operationId: WorkspaceService_GetWorkspaceProfile
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2GetWorkspaceProfileResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
tags:
- WorkspaceService
patch:
operationId: WorkspaceService_UpdateWorkspaceProfile
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2UpdateWorkspaceProfileResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: workspaceProfile
description: System info is the updated data.
in: body
required: true
schema:
$ref: '#/definitions/v2WorkspaceProfile'
tags:
- WorkspaceService
/api/v2/{name}:
get:
summary: GetUser gets a user by name.
......@@ -1464,11 +1464,6 @@ definitions:
properties:
resource:
$ref: '#/definitions/v2Resource'
v2GetSystemInfoResponse:
type: object
properties:
systemInfo:
$ref: '#/definitions/v2SystemInfo'
v2GetTagSuggestionsResponse:
type: object
properties:
......@@ -1502,6 +1497,11 @@ definitions:
properties:
webhook:
$ref: '#/definitions/apiv2Webhook'
v2GetWorkspaceProfileResponse:
type: object
properties:
workspaceProfile:
$ref: '#/definitions/v2WorkspaceProfile'
v2HeadingNode:
type: object
properties:
......@@ -1937,24 +1937,6 @@ definitions:
properties:
content:
type: string
v2SystemInfo:
type: object
properties:
version:
type: string
mode:
type: string
allowRegistration:
type: boolean
disablePasswordLogin:
type: boolean
additionalScript:
type: string
additionalStyle:
type: string
dbSize:
type: string
format: int64
v2TableNode:
type: object
properties:
......@@ -2034,11 +2016,6 @@ definitions:
properties:
resource:
$ref: '#/definitions/v2Resource'
v2UpdateSystemInfoResponse:
type: object
properties:
systemInfo:
$ref: '#/definitions/v2SystemInfo'
v2UpdateUserResponse:
type: object
properties:
......@@ -2054,6 +2031,11 @@ definitions:
properties:
webhook:
$ref: '#/definitions/apiv2Webhook'
v2UpdateWorkspaceProfileResponse:
type: object
properties:
workspaceProfile:
$ref: '#/definitions/v2WorkspaceProfile'
v2UpsertTagResponse:
type: object
properties:
......@@ -2111,3 +2093,18 @@ definitions:
- PROTECTED
- PUBLIC
default: VISIBILITY_UNSPECIFIED
v2WorkspaceProfile:
type: object
properties:
version:
type: string
mode:
type: string
allowRegistration:
type: boolean
disablePasswordLogin:
type: boolean
additionalScript:
type: string
additionalStyle:
type: string
......@@ -11,29 +11,18 @@ import (
"github.com/usememos/memos/store"
)
func (s *APIV2Service) GetSystemInfo(ctx context.Context, _ *apiv2pb.GetSystemInfoRequest) (*apiv2pb.GetSystemInfoResponse, error) {
defaultSystemInfo := &apiv2pb.SystemInfo{}
// Get the database size if the user is a host.
currentUser, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get current user: %v", err)
func (s *APIV2Service) GetWorkspaceProfile(ctx context.Context, _ *apiv2pb.GetWorkspaceProfileRequest) (*apiv2pb.GetWorkspaceProfileResponse, error) {
workspaceProfile := &apiv2pb.WorkspaceProfile{
Version: s.Profile.Version,
Mode: s.Profile.Mode,
}
if currentUser != nil && currentUser.Role == store.RoleHost {
size, err := s.Store.GetCurrentDBSize(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get db size: %v", err)
}
defaultSystemInfo.DbSize = size
}
response := &apiv2pb.GetSystemInfoResponse{
SystemInfo: defaultSystemInfo,
response := &apiv2pb.GetWorkspaceProfileResponse{
WorkspaceProfile: workspaceProfile,
}
return response, nil
}
func (s *APIV2Service) UpdateSystemInfo(ctx context.Context, request *apiv2pb.UpdateSystemInfoRequest) (*apiv2pb.UpdateSystemInfoResponse, error) {
func (s *APIV2Service) UpdateWorkspaceProfile(ctx context.Context, request *apiv2pb.UpdateWorkspaceProfileRequest) (*apiv2pb.UpdateWorkspaceProfileResponse, error) {
user, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get current user: %v", err)
......@@ -50,7 +39,7 @@ func (s *APIV2Service) UpdateSystemInfo(ctx context.Context, request *apiv2pb.Up
if field == "allow_registration" {
_, err := s.Store.UpsertSystemSetting(ctx, &store.SystemSetting{
Name: "allow-signup",
Value: strconv.FormatBool(request.SystemInfo.AllowRegistration),
Value: strconv.FormatBool(request.WorkspaceProfile.AllowRegistration),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to update allow_registration system setting: %v", err)
......@@ -58,7 +47,7 @@ func (s *APIV2Service) UpdateSystemInfo(ctx context.Context, request *apiv2pb.Up
} else if field == "disable_password_login" {
_, err := s.Store.UpsertSystemSetting(ctx, &store.SystemSetting{
Name: "disable-password-login",
Value: strconv.FormatBool(request.SystemInfo.DisablePasswordLogin),
Value: strconv.FormatBool(request.WorkspaceProfile.DisablePasswordLogin),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to update disable_password_login system setting: %v", err)
......@@ -66,7 +55,7 @@ func (s *APIV2Service) UpdateSystemInfo(ctx context.Context, request *apiv2pb.Up
} else if field == "additional_script" {
_, err := s.Store.UpsertSystemSetting(ctx, &store.SystemSetting{
Name: "additional-script",
Value: request.SystemInfo.AdditionalScript,
Value: request.WorkspaceProfile.AdditionalScript,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to update additional_script system setting: %v", err)
......@@ -74,7 +63,7 @@ func (s *APIV2Service) UpdateSystemInfo(ctx context.Context, request *apiv2pb.Up
} else if field == "additional_style" {
_, err := s.Store.UpsertSystemSetting(ctx, &store.SystemSetting{
Name: "additional-style",
Value: request.SystemInfo.AdditionalStyle,
Value: request.WorkspaceProfile.AdditionalStyle,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to update additional_style system setting: %v", err)
......@@ -82,11 +71,11 @@ func (s *APIV2Service) UpdateSystemInfo(ctx context.Context, request *apiv2pb.Up
}
}
systemInfo, err := s.GetSystemInfo(ctx, &apiv2pb.GetSystemInfoRequest{})
workspaceProfileMessage, err := s.GetWorkspaceProfile(ctx, &apiv2pb.GetWorkspaceProfileRequest{})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get system info: %v", err)
}
return &apiv2pb.UpdateSystemInfoResponse{
SystemInfo: systemInfo.SystemInfo,
return &apiv2pb.UpdateWorkspaceProfileResponse{
WorkspaceProfile: workspaceProfileMessage.WorkspaceProfile,
}, nil
}
......@@ -8,41 +8,40 @@ import "google/protobuf/field_mask.proto";
option go_package = "gen/api/v2";
service SystemService {
rpc GetSystemInfo(GetSystemInfoRequest) returns (GetSystemInfoResponse) {
option (google.api.http) = {get: "/api/v2/system/info"};
service WorkspaceService {
rpc GetWorkspaceProfile(GetWorkspaceProfileRequest) returns (GetWorkspaceProfileResponse) {
option (google.api.http) = {get: "/api/v2/workspace/profile"};
}
rpc UpdateSystemInfo(UpdateSystemInfoRequest) returns (UpdateSystemInfoResponse) {
rpc UpdateWorkspaceProfile(UpdateWorkspaceProfileRequest) returns (UpdateWorkspaceProfileResponse) {
option (google.api.http) = {
patch: "/api/v2/system/info",
body: "system_info"
patch: "/api/v2/workspace/profile",
body: "workspace_profile"
};
option (google.api.method_signature) = "system_info,update_mask";
option (google.api.method_signature) = "workspace_profile,update_mask";
}
}
message SystemInfo {
message WorkspaceProfile {
string version = 1;
string mode = 2;
bool allow_registration = 3;
bool disable_password_login = 4;
string additional_script = 5;
string additional_style = 6;
int64 db_size = 7;
}
message GetSystemInfoRequest {}
message GetWorkspaceProfileRequest {}
message GetSystemInfoResponse {
SystemInfo system_info = 1;
message GetWorkspaceProfileResponse {
WorkspaceProfile workspace_profile = 1;
}
message UpdateSystemInfoRequest {
message UpdateWorkspaceProfileRequest {
// System info is the updated data.
SystemInfo system_info = 1;
WorkspaceProfile workspace_profile = 1;
google.protobuf.FieldMask update_mask = 2;
}
message UpdateSystemInfoResponse {
SystemInfo system_info = 1;
message UpdateWorkspaceProfileResponse {
WorkspaceProfile workspace_profile = 1;
}
......@@ -161,15 +161,6 @@
- [MemoService](#memos-api-v2-MemoService)
- [api/v2/system_service.proto](#api_v2_system_service-proto)
- [GetSystemInfoRequest](#memos-api-v2-GetSystemInfoRequest)
- [GetSystemInfoResponse](#memos-api-v2-GetSystemInfoResponse)
- [SystemInfo](#memos-api-v2-SystemInfo)
- [UpdateSystemInfoRequest](#memos-api-v2-UpdateSystemInfoRequest)
- [UpdateSystemInfoResponse](#memos-api-v2-UpdateSystemInfoResponse)
- [SystemService](#memos-api-v2-SystemService)
- [api/v2/tag_service.proto](#api_v2_tag_service-proto)
- [DeleteTagRequest](#memos-api-v2-DeleteTagRequest)
- [DeleteTagResponse](#memos-api-v2-DeleteTagResponse)
......@@ -200,6 +191,15 @@
- [WebhookService](#memos-api-v2-WebhookService)
- [api/v2/workspace_service.proto](#api_v2_workspace_service-proto)
- [GetWorkspaceProfileRequest](#memos-api-v2-GetWorkspaceProfileRequest)
- [GetWorkspaceProfileResponse](#memos-api-v2-GetWorkspaceProfileResponse)
- [UpdateWorkspaceProfileRequest](#memos-api-v2-UpdateWorkspaceProfileRequest)
- [UpdateWorkspaceProfileResponse](#memos-api-v2-UpdateWorkspaceProfileResponse)
- [WorkspaceProfile](#memos-api-v2-WorkspaceProfile)
- [WorkspaceService](#memos-api-v2-WorkspaceService)
- [Scalar Value Types](#scalar-value-types)
......@@ -2328,110 +2328,6 @@ Used internally for obfuscating the page token.
<a name="api_v2_system_service-proto"></a>
<p align="right"><a href="#top">Top</a></p>
## api/v2/system_service.proto
<a name="memos-api-v2-GetSystemInfoRequest"></a>
### GetSystemInfoRequest
<a name="memos-api-v2-GetSystemInfoResponse"></a>
### GetSystemInfoResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| system_info | [SystemInfo](#memos-api-v2-SystemInfo) | | |
<a name="memos-api-v2-SystemInfo"></a>
### SystemInfo
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| version | [string](#string) | | |
| mode | [string](#string) | | |
| allow_registration | [bool](#bool) | | |
| disable_password_login | [bool](#bool) | | |
| additional_script | [string](#string) | | |
| additional_style | [string](#string) | | |
| db_size | [int64](#int64) | | |
<a name="memos-api-v2-UpdateSystemInfoRequest"></a>
### UpdateSystemInfoRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| system_info | [SystemInfo](#memos-api-v2-SystemInfo) | | System info is the updated data. |
| update_mask | [google.protobuf.FieldMask](#google-protobuf-FieldMask) | | |
<a name="memos-api-v2-UpdateSystemInfoResponse"></a>
### UpdateSystemInfoResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| system_info | [SystemInfo](#memos-api-v2-SystemInfo) | | |
<a name="memos-api-v2-SystemService"></a>
### SystemService
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
| GetSystemInfo | [GetSystemInfoRequest](#memos-api-v2-GetSystemInfoRequest) | [GetSystemInfoResponse](#memos-api-v2-GetSystemInfoResponse) | |
| UpdateSystemInfo | [UpdateSystemInfoRequest](#memos-api-v2-UpdateSystemInfoRequest) | [UpdateSystemInfoResponse](#memos-api-v2-UpdateSystemInfoResponse) | |
<a name="api_v2_tag_service-proto"></a>
<p align="right"><a href="#top">Top</a></p>
......@@ -2823,6 +2719,109 @@ Used internally for obfuscating the page token.
<a name="api_v2_workspace_service-proto"></a>
<p align="right"><a href="#top">Top</a></p>
## api/v2/workspace_service.proto
<a name="memos-api-v2-GetWorkspaceProfileRequest"></a>
### GetWorkspaceProfileRequest
<a name="memos-api-v2-GetWorkspaceProfileResponse"></a>
### GetWorkspaceProfileResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| workspace_profile | [WorkspaceProfile](#memos-api-v2-WorkspaceProfile) | | |
<a name="memos-api-v2-UpdateWorkspaceProfileRequest"></a>
### UpdateWorkspaceProfileRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| workspace_profile | [WorkspaceProfile](#memos-api-v2-WorkspaceProfile) | | System info is the updated data. |
| update_mask | [google.protobuf.FieldMask](#google-protobuf-FieldMask) | | |
<a name="memos-api-v2-UpdateWorkspaceProfileResponse"></a>
### UpdateWorkspaceProfileResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| workspace_profile | [WorkspaceProfile](#memos-api-v2-WorkspaceProfile) | | |
<a name="memos-api-v2-WorkspaceProfile"></a>
### WorkspaceProfile
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| version | [string](#string) | | |
| mode | [string](#string) | | |
| allow_registration | [bool](#bool) | | |
| disable_password_login | [bool](#bool) | | |
| additional_script | [string](#string) | | |
| additional_style | [string](#string) | | |
<a name="memos-api-v2-WorkspaceService"></a>
### WorkspaceService
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
| GetWorkspaceProfile | [GetWorkspaceProfileRequest](#memos-api-v2-GetWorkspaceProfileRequest) | [GetWorkspaceProfileResponse](#memos-api-v2-GetWorkspaceProfileResponse) | |
| UpdateWorkspaceProfile | [UpdateWorkspaceProfileRequest](#memos-api-v2-UpdateWorkspaceProfileRequest) | [UpdateWorkspaceProfileResponse](#memos-api-v2-UpdateWorkspaceProfileResponse) | |
## Scalar Value Types
| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
......
This diff is collapsed.
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc (unknown)
// source: api/v2/system_service.proto
package apiv2
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
SystemService_GetSystemInfo_FullMethodName = "/memos.api.v2.SystemService/GetSystemInfo"
SystemService_UpdateSystemInfo_FullMethodName = "/memos.api.v2.SystemService/UpdateSystemInfo"
)
// SystemServiceClient is the client API for SystemService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type SystemServiceClient interface {
GetSystemInfo(ctx context.Context, in *GetSystemInfoRequest, opts ...grpc.CallOption) (*GetSystemInfoResponse, error)
UpdateSystemInfo(ctx context.Context, in *UpdateSystemInfoRequest, opts ...grpc.CallOption) (*UpdateSystemInfoResponse, error)
}
type systemServiceClient struct {
cc grpc.ClientConnInterface
}
func NewSystemServiceClient(cc grpc.ClientConnInterface) SystemServiceClient {
return &systemServiceClient{cc}
}
func (c *systemServiceClient) GetSystemInfo(ctx context.Context, in *GetSystemInfoRequest, opts ...grpc.CallOption) (*GetSystemInfoResponse, error) {
out := new(GetSystemInfoResponse)
err := c.cc.Invoke(ctx, SystemService_GetSystemInfo_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) UpdateSystemInfo(ctx context.Context, in *UpdateSystemInfoRequest, opts ...grpc.CallOption) (*UpdateSystemInfoResponse, error) {
out := new(UpdateSystemInfoResponse)
err := c.cc.Invoke(ctx, SystemService_UpdateSystemInfo_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// SystemServiceServer is the server API for SystemService service.
// All implementations must embed UnimplementedSystemServiceServer
// for forward compatibility
type SystemServiceServer interface {
GetSystemInfo(context.Context, *GetSystemInfoRequest) (*GetSystemInfoResponse, error)
UpdateSystemInfo(context.Context, *UpdateSystemInfoRequest) (*UpdateSystemInfoResponse, error)
mustEmbedUnimplementedSystemServiceServer()
}
// UnimplementedSystemServiceServer must be embedded to have forward compatible implementations.
type UnimplementedSystemServiceServer struct {
}
func (UnimplementedSystemServiceServer) GetSystemInfo(context.Context, *GetSystemInfoRequest) (*GetSystemInfoResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetSystemInfo not implemented")
}
func (UnimplementedSystemServiceServer) UpdateSystemInfo(context.Context, *UpdateSystemInfoRequest) (*UpdateSystemInfoResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateSystemInfo not implemented")
}
func (UnimplementedSystemServiceServer) mustEmbedUnimplementedSystemServiceServer() {}
// UnsafeSystemServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to SystemServiceServer will
// result in compilation errors.
type UnsafeSystemServiceServer interface {
mustEmbedUnimplementedSystemServiceServer()
}
func RegisterSystemServiceServer(s grpc.ServiceRegistrar, srv SystemServiceServer) {
s.RegisterService(&SystemService_ServiceDesc, srv)
}
func _SystemService_GetSystemInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetSystemInfoRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).GetSystemInfo(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_GetSystemInfo_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).GetSystemInfo(ctx, req.(*GetSystemInfoRequest))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_UpdateSystemInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateSystemInfoRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).UpdateSystemInfo(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_UpdateSystemInfo_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).UpdateSystemInfo(ctx, req.(*UpdateSystemInfoRequest))
}
return interceptor(ctx, in, info, handler)
}
// SystemService_ServiceDesc is the grpc.ServiceDesc for SystemService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var SystemService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "memos.api.v2.SystemService",
HandlerType: (*SystemServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetSystemInfo",
Handler: _SystemService_GetSystemInfo_Handler,
},
{
MethodName: "UpdateSystemInfo",
Handler: _SystemService_UpdateSystemInfo_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "api/v2/system_service.proto",
}
This diff is collapsed.
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc (unknown)
// source: api/v2/workspace_service.proto
package apiv2
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
WorkspaceService_GetWorkspaceProfile_FullMethodName = "/memos.api.v2.WorkspaceService/GetWorkspaceProfile"
WorkspaceService_UpdateWorkspaceProfile_FullMethodName = "/memos.api.v2.WorkspaceService/UpdateWorkspaceProfile"
)
// WorkspaceServiceClient is the client API for WorkspaceService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type WorkspaceServiceClient interface {
GetWorkspaceProfile(ctx context.Context, in *GetWorkspaceProfileRequest, opts ...grpc.CallOption) (*GetWorkspaceProfileResponse, error)
UpdateWorkspaceProfile(ctx context.Context, in *UpdateWorkspaceProfileRequest, opts ...grpc.CallOption) (*UpdateWorkspaceProfileResponse, error)
}
type workspaceServiceClient struct {
cc grpc.ClientConnInterface
}
func NewWorkspaceServiceClient(cc grpc.ClientConnInterface) WorkspaceServiceClient {
return &workspaceServiceClient{cc}
}
func (c *workspaceServiceClient) GetWorkspaceProfile(ctx context.Context, in *GetWorkspaceProfileRequest, opts ...grpc.CallOption) (*GetWorkspaceProfileResponse, error) {
out := new(GetWorkspaceProfileResponse)
err := c.cc.Invoke(ctx, WorkspaceService_GetWorkspaceProfile_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *workspaceServiceClient) UpdateWorkspaceProfile(ctx context.Context, in *UpdateWorkspaceProfileRequest, opts ...grpc.CallOption) (*UpdateWorkspaceProfileResponse, error) {
out := new(UpdateWorkspaceProfileResponse)
err := c.cc.Invoke(ctx, WorkspaceService_UpdateWorkspaceProfile_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// WorkspaceServiceServer is the server API for WorkspaceService service.
// All implementations must embed UnimplementedWorkspaceServiceServer
// for forward compatibility
type WorkspaceServiceServer interface {
GetWorkspaceProfile(context.Context, *GetWorkspaceProfileRequest) (*GetWorkspaceProfileResponse, error)
UpdateWorkspaceProfile(context.Context, *UpdateWorkspaceProfileRequest) (*UpdateWorkspaceProfileResponse, error)
mustEmbedUnimplementedWorkspaceServiceServer()
}
// UnimplementedWorkspaceServiceServer must be embedded to have forward compatible implementations.
type UnimplementedWorkspaceServiceServer struct {
}
func (UnimplementedWorkspaceServiceServer) GetWorkspaceProfile(context.Context, *GetWorkspaceProfileRequest) (*GetWorkspaceProfileResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetWorkspaceProfile not implemented")
}
func (UnimplementedWorkspaceServiceServer) UpdateWorkspaceProfile(context.Context, *UpdateWorkspaceProfileRequest) (*UpdateWorkspaceProfileResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateWorkspaceProfile not implemented")
}
func (UnimplementedWorkspaceServiceServer) mustEmbedUnimplementedWorkspaceServiceServer() {}
// UnsafeWorkspaceServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to WorkspaceServiceServer will
// result in compilation errors.
type UnsafeWorkspaceServiceServer interface {
mustEmbedUnimplementedWorkspaceServiceServer()
}
func RegisterWorkspaceServiceServer(s grpc.ServiceRegistrar, srv WorkspaceServiceServer) {
s.RegisterService(&WorkspaceService_ServiceDesc, srv)
}
func _WorkspaceService_GetWorkspaceProfile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetWorkspaceProfileRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(WorkspaceServiceServer).GetWorkspaceProfile(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: WorkspaceService_GetWorkspaceProfile_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WorkspaceServiceServer).GetWorkspaceProfile(ctx, req.(*GetWorkspaceProfileRequest))
}
return interceptor(ctx, in, info, handler)
}
func _WorkspaceService_UpdateWorkspaceProfile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateWorkspaceProfileRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(WorkspaceServiceServer).UpdateWorkspaceProfile(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: WorkspaceService_UpdateWorkspaceProfile_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(WorkspaceServiceServer).UpdateWorkspaceProfile(ctx, req.(*UpdateWorkspaceProfileRequest))
}
return interceptor(ctx, in, info, handler)
}
// WorkspaceService_ServiceDesc is the grpc.ServiceDesc for WorkspaceService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var WorkspaceService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "memos.api.v2.WorkspaceService",
HandlerType: (*WorkspaceServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetWorkspaceProfile",
Handler: _WorkspaceService_GetWorkspaceProfile_Handler,
},
{
MethodName: "UpdateWorkspaceProfile",
Handler: _WorkspaceService_UpdateWorkspaceProfile_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "api/v2/workspace_service.proto",
}
......@@ -16,13 +16,11 @@ const getCellAdditionalStyles = (count: number, maxCount: number) => {
const ratio = count / maxCount;
if (ratio > 0.7) {
return "bg-blue-600 text-gray-200";
} else if (ratio > 0.5) {
return "bg-blue-600 text-gray-100 dark:opacity-80";
} else if (ratio > 0.4) {
return "bg-blue-400 text-gray-200 dark:opacity-80";
} else if (ratio > 0.3) {
return "bg-blue-300 text-gray-200 dark:opacity-80";
} else {
return "bg-blue-200 text-gray-200 dark:opacity-80";
return "bg-blue-300 text-gray-600 dark:opacity-80";
}
};
......
......@@ -3,7 +3,6 @@ import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { Link } from "react-router-dom";
import * as api from "@/helpers/api";
import { formatBytes } from "@/helpers/utils";
import { useGlobalStore } from "@/store/module";
import { useTranslate } from "@/utils/i18n";
import { showCommonDialog } from "../Dialog/CommonDialog";
......@@ -12,7 +11,6 @@ import Icon from "../Icon";
import showUpdateCustomizedProfileDialog from "../UpdateCustomizedProfileDialog";
interface State {
dbSize: number;
allowSignUp: boolean;
disablePasswordLogin: boolean;
disablePublicMemos: boolean;
......@@ -27,7 +25,6 @@ const SystemSection = () => {
const globalStore = useGlobalStore();
const systemStatus = globalStore.state.systemStatus;
const [state, setState] = useState<State>({
dbSize: systemStatus.dbSize,
allowSignUp: systemStatus.allowSignUp,
disablePasswordLogin: systemStatus.disablePasswordLogin,
additionalStyle: systemStatus.additionalStyle,
......@@ -59,7 +56,6 @@ const SystemSection = () => {
useEffect(() => {
setState({
...state,
dbSize: systemStatus.dbSize,
allowSignUp: systemStatus.allowSignUp,
disablePasswordLogin: systemStatus.disablePasswordLogin,
additionalStyle: systemStatus.additionalStyle,
......@@ -107,17 +103,6 @@ const SystemSection = () => {
showUpdateCustomizedProfileDialog();
};
const handleVacuumBtnClick = async () => {
try {
await api.vacuumDatabase();
await globalStore.fetchSystemStatus();
} catch (error) {
console.error(error);
return;
}
toast.success(t("message.succeed-vacuum-database"));
};
const handleInstanceUrlChanged = (value: string) => {
setInstanceUrl(value);
};
......@@ -251,17 +236,6 @@ const SystemSection = () => {
</div>
<Button onClick={handleUpdateCustomizedProfileButtonClick}>{t("common.edit")}</Button>
</div>
<div className="w-full flex flex-row justify-between items-center">
<div className="flex flex-row items-center">
<span className="text-sm">
{t("setting.system-section.database-file-size")}: <span className="font-mono font-bold">{formatBytes(state.dbSize)}</span>
</span>
<Tooltip title={t("setting.system-section.vacuum-hint")} placement="top">
<Icon.HelpCircle className="w-4 h-auto" />
</Tooltip>
</div>
<Button onClick={handleVacuumBtnClick}>{t("common.vacuum")}</Button>
</div>
<p className="font-medium text-gray-700 dark:text-gray-500">{t("common.settings")}</p>
<div className="w-full flex flex-row justify-between items-center">
<span className="normal-text">{t("setting.system-section.allow-user-signup")}</span>
......
......@@ -5,10 +5,10 @@ import { InboxServiceDefinition } from "./types/proto/api/v2/inbox_service";
import { MarkdownServiceDefinition } from "./types/proto/api/v2/markdown_service";
import { MemoServiceDefinition } from "./types/proto/api/v2/memo_service";
import { ResourceServiceDefinition } from "./types/proto/api/v2/resource_service";
import { SystemServiceDefinition } from "./types/proto/api/v2/system_service";
import { TagServiceDefinition } from "./types/proto/api/v2/tag_service";
import { UserServiceDefinition } from "./types/proto/api/v2/user_service";
import { WebhookServiceDefinition } from "./types/proto/api/v2/webhook_service";
import { WorkspaceServiceDefinition } from "./types/proto/api/v2/workspace_service";
const channel = createChannel(
window.location.origin,
......@@ -19,6 +19,8 @@ const channel = createChannel(
const clientFactory = createClientFactory();
export const workspaceServiceClient = clientFactory.create(WorkspaceServiceDefinition, channel);
export const authServiceClient = clientFactory.create(AuthServiceDefinition, channel);
export const userServiceClient = clientFactory.create(UserServiceDefinition, channel);
......@@ -27,8 +29,6 @@ export const memoServiceClient = clientFactory.create(MemoServiceDefinition, cha
export const resourceServiceClient = clientFactory.create(ResourceServiceDefinition, channel);
export const systemServiceClient = clientFactory.create(SystemServiceDefinition, channel);
export const tagServiceClient = clientFactory.create(TagServiceDefinition, channel);
export const inboxServiceClient = clientFactory.create(InboxServiceDefinition, channel);
......
......@@ -13,10 +13,6 @@ export function upsertSystemSetting(systemSetting: SystemSetting) {
return axios.post<SystemSetting>("/api/v1/system/setting", systemSetting);
}
export function vacuumDatabase() {
return axios.post("/api/v1/system/vacuum");
}
export function signin(username: string, password: string, remember: boolean) {
return axios.post<User>("/api/v1/auth/signin", {
username,
......
import { systemServiceClient } from "@/grpcweb";
import * as api from "@/helpers/api";
import storage from "@/helpers/storage";
import i18n from "@/i18n";
......@@ -72,8 +71,6 @@ export const useGlobalStore = () => {
},
fetchSystemStatus: async () => {
const { data: systemStatus } = await api.getSystemStatus();
const { systemInfo } = await systemServiceClient.getSystemInfo({});
systemStatus.dbSize = systemInfo?.dbSize || 0;
store.dispatch(setGlobalState({ systemStatus: systemStatus }));
return systemStatus;
},
......
......@@ -17,7 +17,6 @@ const globalSlice = createSlice({
mode: "demo",
version: "",
},
dbSize: 0,
allowSignUp: false,
disablePasswordLogin: false,
disablePublicMemos: false,
......
......@@ -15,7 +15,6 @@ interface CustomizedProfile {
interface SystemStatus {
host?: User;
profile: Profile;
dbSize: number;
// System settings
allowSignUp: boolean;
disablePasswordLogin: boolean;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment