mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update workspace setting service
This commit is contained in:
@@ -876,7 +876,12 @@ paths:
|
||||
properties:
|
||||
generalSetting:
|
||||
$ref: '#/definitions/apiv2WorkspaceGeneralSetting'
|
||||
description: general_setting is the general setting of workspace.
|
||||
storageSetting:
|
||||
$ref: '#/definitions/apiv2WorkspaceStorageSetting'
|
||||
memoRelatedSetting:
|
||||
$ref: '#/definitions/apiv2WorkspaceMemoRelatedSetting'
|
||||
telegramIntegrationSetting:
|
||||
$ref: '#/definitions/apiv2WorkspaceTelegramIntegrationSetting'
|
||||
title: setting is the setting to update.
|
||||
tags:
|
||||
- WorkspaceSettingService
|
||||
@@ -1954,6 +1959,15 @@ definitions:
|
||||
additionalStyle:
|
||||
type: string
|
||||
description: additional_style is the additional style.
|
||||
apiv2WorkspaceMemoRelatedSetting:
|
||||
type: object
|
||||
properties:
|
||||
disallowPublicVisible:
|
||||
type: boolean
|
||||
description: disallow_public_share disallows set memo as public visible.
|
||||
displayWithUpdateTime:
|
||||
type: boolean
|
||||
description: display_with_update_time orders and displays memo with update time.
|
||||
apiv2WorkspaceSetting:
|
||||
type: object
|
||||
properties:
|
||||
@@ -1964,7 +1978,45 @@ definitions:
|
||||
Format: settings/{setting}
|
||||
generalSetting:
|
||||
$ref: '#/definitions/apiv2WorkspaceGeneralSetting'
|
||||
description: general_setting is the general setting of workspace.
|
||||
storageSetting:
|
||||
$ref: '#/definitions/apiv2WorkspaceStorageSetting'
|
||||
memoRelatedSetting:
|
||||
$ref: '#/definitions/apiv2WorkspaceMemoRelatedSetting'
|
||||
telegramIntegrationSetting:
|
||||
$ref: '#/definitions/apiv2WorkspaceTelegramIntegrationSetting'
|
||||
apiv2WorkspaceStorageSetting:
|
||||
type: object
|
||||
properties:
|
||||
storageType:
|
||||
$ref: '#/definitions/apiv2WorkspaceStorageSettingStorageType'
|
||||
description: storage_type is the storage type.
|
||||
localStoragePath:
|
||||
type: string
|
||||
title: |-
|
||||
The local storage path for STORAGE_TYPE_LOCAL.
|
||||
e.g. assets/{timestamp}_{filename}
|
||||
uploadSizeLimitMb:
|
||||
type: string
|
||||
format: int64
|
||||
description: The max upload size in megabytes.
|
||||
apiv2WorkspaceStorageSettingStorageType:
|
||||
type: string
|
||||
enum:
|
||||
- STORAGE_TYPE_UNSPECIFIED
|
||||
- STORAGE_TYPE_DATABASE
|
||||
- STORAGE_TYPE_LOCAL
|
||||
- STORAGE_TYPE_EXTERNAL
|
||||
default: STORAGE_TYPE_UNSPECIFIED
|
||||
description: |2-
|
||||
- STORAGE_TYPE_DATABASE: STORAGE_TYPE_DATABASE is the database storage type.
|
||||
- STORAGE_TYPE_LOCAL: STORAGE_TYPE_LOCAL is the local storage type.
|
||||
- STORAGE_TYPE_EXTERNAL: STORAGE_TYPE_EXTERNAL is the external storage type.
|
||||
apiv2WorkspaceTelegramIntegrationSetting:
|
||||
type: object
|
||||
properties:
|
||||
botToken:
|
||||
type: string
|
||||
description: bot_token is the telegram bot token.
|
||||
googlerpcStatus:
|
||||
type: object
|
||||
properties:
|
||||
|
@@ -54,22 +54,57 @@ func (s *APIV2Service) SetWorkspaceSetting(ctx context.Context, request *apiv2pb
|
||||
}
|
||||
|
||||
func convertWorkspaceSettingFromStore(setting *storepb.WorkspaceSetting) *apiv2pb.WorkspaceSetting {
|
||||
return &apiv2pb.WorkspaceSetting{
|
||||
workspaceSetting := &apiv2pb.WorkspaceSetting{
|
||||
Name: fmt.Sprintf("%s%s", WorkspaceSettingNamePrefix, setting.Key.String()),
|
||||
Value: &apiv2pb.WorkspaceSetting_GeneralSetting{
|
||||
GeneralSetting: convertWorkspaceGeneralSettingFromStore(setting.GetGeneralSetting()),
|
||||
},
|
||||
}
|
||||
switch setting.Value.(type) {
|
||||
case *storepb.WorkspaceSetting_GeneralSetting:
|
||||
workspaceSetting.Value = &apiv2pb.WorkspaceSetting_GeneralSetting{
|
||||
GeneralSetting: convertWorkspaceGeneralSettingFromStore(setting.GetGeneralSetting()),
|
||||
}
|
||||
case *storepb.WorkspaceSetting_StorageSetting:
|
||||
workspaceSetting.Value = &apiv2pb.WorkspaceSetting_StorageSetting{
|
||||
StorageSetting: convertWorkspaceStorageSettingFromStore(setting.GetStorageSetting()),
|
||||
}
|
||||
case *storepb.WorkspaceSetting_MemoRelatedSetting:
|
||||
workspaceSetting.Value = &apiv2pb.WorkspaceSetting_MemoRelatedSetting{
|
||||
MemoRelatedSetting: convertWorkspaceMemoRelatedSettingFromStore(setting.GetMemoRelatedSetting()),
|
||||
}
|
||||
case *storepb.WorkspaceSetting_TelegramIntegrationSetting:
|
||||
workspaceSetting.Value = &apiv2pb.WorkspaceSetting_TelegramIntegrationSetting{
|
||||
TelegramIntegrationSetting: convertWorkspaceTelegramIntegrationSettingFromStore(setting.GetTelegramIntegrationSetting()),
|
||||
}
|
||||
}
|
||||
return workspaceSetting
|
||||
}
|
||||
|
||||
func convertWorkspaceSettingToStore(setting *apiv2pb.WorkspaceSetting) *storepb.WorkspaceSetting {
|
||||
settingKeyString, _ := ExtractWorkspaceSettingKeyFromName(setting.Name)
|
||||
return &storepb.WorkspaceSetting{
|
||||
workspaceSetting := &storepb.WorkspaceSetting{
|
||||
Key: storepb.WorkspaceSettingKey(storepb.WorkspaceSettingKey_value[settingKeyString]),
|
||||
Value: &storepb.WorkspaceSetting_GeneralSetting{
|
||||
GeneralSetting: convertWorkspaceGeneralSettingToStore(setting.GetGeneralSetting()),
|
||||
},
|
||||
}
|
||||
switch workspaceSetting.Key {
|
||||
case storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL:
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_GeneralSetting{
|
||||
GeneralSetting: convertWorkspaceGeneralSettingToStore(setting.GetGeneralSetting()),
|
||||
}
|
||||
case storepb.WorkspaceSettingKey_WORKSPACE_SETTING_STORAGE:
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_StorageSetting{
|
||||
StorageSetting: convertWorkspaceStorageSettingToStore(setting.GetStorageSetting()),
|
||||
}
|
||||
case storepb.WorkspaceSettingKey_WORKSPACE_SETTING_MEMO_RELATED:
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_MemoRelatedSetting{
|
||||
MemoRelatedSetting: convertWorkspaceMemoRelatedSettingToStore(setting.GetMemoRelatedSetting()),
|
||||
}
|
||||
case storepb.WorkspaceSettingKey_WORKSPACE_SETTING_TELEGRAM_INTEGRATION:
|
||||
workspaceSetting.Value = &storepb.WorkspaceSetting_TelegramIntegrationSetting{
|
||||
TelegramIntegrationSetting: convertWorkspaceTelegramIntegrationSettingToStore(setting.GetTelegramIntegrationSetting()),
|
||||
}
|
||||
}
|
||||
return workspaceSetting
|
||||
}
|
||||
|
||||
func convertWorkspaceGeneralSettingFromStore(setting *storepb.WorkspaceGeneralSetting) *apiv2pb.WorkspaceGeneralSetting {
|
||||
@@ -97,3 +132,63 @@ func convertWorkspaceGeneralSettingToStore(setting *apiv2pb.WorkspaceGeneralSett
|
||||
AdditionalStyle: setting.AdditionalStyle,
|
||||
}
|
||||
}
|
||||
|
||||
func convertWorkspaceStorageSettingFromStore(setting *storepb.WorkspaceStorageSetting) *apiv2pb.WorkspaceStorageSetting {
|
||||
if setting == nil {
|
||||
return nil
|
||||
}
|
||||
return &apiv2pb.WorkspaceStorageSetting{
|
||||
StorageType: apiv2pb.WorkspaceStorageSetting_StorageType(setting.StorageType),
|
||||
LocalStoragePath: setting.LocalStoragePath,
|
||||
UploadSizeLimitMb: setting.UploadSizeLimitMb,
|
||||
}
|
||||
}
|
||||
|
||||
func convertWorkspaceStorageSettingToStore(setting *apiv2pb.WorkspaceStorageSetting) *storepb.WorkspaceStorageSetting {
|
||||
if setting == nil {
|
||||
return nil
|
||||
}
|
||||
return &storepb.WorkspaceStorageSetting{
|
||||
StorageType: storepb.WorkspaceStorageSetting_StorageType(setting.StorageType),
|
||||
LocalStoragePath: setting.LocalStoragePath,
|
||||
UploadSizeLimitMb: setting.UploadSizeLimitMb,
|
||||
}
|
||||
}
|
||||
|
||||
func convertWorkspaceMemoRelatedSettingFromStore(setting *storepb.WorkspaceMemoRelatedSetting) *apiv2pb.WorkspaceMemoRelatedSetting {
|
||||
if setting == nil {
|
||||
return nil
|
||||
}
|
||||
return &apiv2pb.WorkspaceMemoRelatedSetting{
|
||||
DisallowPublicVisible: setting.DisallowPublicVisible,
|
||||
DisplayWithUpdateTime: setting.DisplayWithUpdateTime,
|
||||
}
|
||||
}
|
||||
|
||||
func convertWorkspaceMemoRelatedSettingToStore(setting *apiv2pb.WorkspaceMemoRelatedSetting) *storepb.WorkspaceMemoRelatedSetting {
|
||||
if setting == nil {
|
||||
return nil
|
||||
}
|
||||
return &storepb.WorkspaceMemoRelatedSetting{
|
||||
DisallowPublicVisible: setting.DisallowPublicVisible,
|
||||
DisplayWithUpdateTime: setting.DisplayWithUpdateTime,
|
||||
}
|
||||
}
|
||||
|
||||
func convertWorkspaceTelegramIntegrationSettingFromStore(setting *storepb.WorkspaceTelegramIntegrationSetting) *apiv2pb.WorkspaceTelegramIntegrationSetting {
|
||||
if setting == nil {
|
||||
return nil
|
||||
}
|
||||
return &apiv2pb.WorkspaceTelegramIntegrationSetting{
|
||||
BotToken: setting.BotToken,
|
||||
}
|
||||
}
|
||||
|
||||
func convertWorkspaceTelegramIntegrationSettingToStore(setting *apiv2pb.WorkspaceTelegramIntegrationSetting) *storepb.WorkspaceTelegramIntegrationSetting {
|
||||
if setting == nil {
|
||||
return nil
|
||||
}
|
||||
return &storepb.WorkspaceTelegramIntegrationSetting{
|
||||
BotToken: setting.BotToken,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user