v1

package
v0.25.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 57 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The upload memory buffer is 32 MiB.
	// It should be kept low, so RAM usage doesn't get out of control.
	// This is unrelated to maximum upload size limit, which is now set through system setting.
	MaxUploadBufferSizeBytes = 32 << 20
	MebiByte                 = 1024 * 1024
	// ThumbnailCacheFolder is the folder name where the thumbnail images are stored.
	ThumbnailCacheFolder = ".thumbnail_cache"
)
View Source
const (
	// issuer is the issuer of the jwt token.
	Issuer = "memos"
	// Signing key section. For now, this is only used for signing, not for verifying since we only
	// have 1 version. But it will be used to maintain backward compatibility if we change the signing mechanism.
	KeyID = "v1"
	// AccessTokenAudienceName is the audience name of the access token.
	AccessTokenAudienceName = "user.access-token"
	// SessionSlidingDuration is the sliding expiration duration for user sessions (2 weeks).
	// Sessions are considered valid if last_accessed_time + SessionSlidingDuration > current_time.
	SessionSlidingDuration = 14 * 24 * time.Hour

	// SessionCookieName is the cookie name of user session ID.
	SessionCookieName = "user_session"
)
View Source
const (
	// DefaultPageSize is the default page size for requests.
	DefaultPageSize = 10
	// MaxPageSize is the maximum page size for requests.
	MaxPageSize = 1000
)
View Source
const (
	WorkspaceSettingNamePrefix = "workspace/settings/"
	UserNamePrefix             = "users/"
	MemoNamePrefix             = "memos/"
	AttachmentNamePrefix       = "attachments/"
	ReactionNamePrefix         = "reactions/"
	InboxNamePrefix            = "inboxes/"
	IdentityProviderNamePrefix = "identityProviders/"
	ActivityNamePrefix         = "activities/"
	WebhookNamePrefix          = "webhooks/"
)

Variables

View Source
var SupportedThumbnailMimeTypes = []string{
	"image/png",
	"image/jpeg",
}

Functions

func BuildSessionCookieValue added in v0.25.0

func BuildSessionCookieValue(userID int32, sessionID string) string

BuildSessionCookieValue builds the session cookie value in format {userID}-{sessionID}.

func CreateTestUserContext added in v0.25.0

func CreateTestUserContext(ctx context.Context, userID int32) context.Context

CreateTestUserContext creates a context with user's ID for testing purposes. This function is only intended for use in tests.

func CreateTestUserContextWithUser added in v0.25.0

func CreateTestUserContextWithUser(ctx context.Context, _ *APIV1Service, user *store.User) context.Context

CreateTestUserContextWithUser creates a context and ensures the user exists for testing. This function is only intended for use in tests.

func ExtractActivityIDFromName added in v0.22.5

func ExtractActivityIDFromName(name string) (int32, error)

func ExtractAttachmentUIDFromName added in v0.25.0

func ExtractAttachmentUIDFromName(name string) (string, error)

ExtractAttachmentUIDFromName returns the attachment UID from a resource name.

func ExtractIdentityProviderIDFromName

func ExtractIdentityProviderIDFromName(name string) (int32, error)

func ExtractInboxIDFromName

func ExtractInboxIDFromName(name string) (int32, error)

ExtractInboxIDFromName returns the inbox ID from a resource name.

func ExtractMemoUIDFromName added in v0.24.0

func ExtractMemoUIDFromName(name string) (string, error)

ExtractMemoUIDFromName returns the memo UID from a resource name. e.g., "memos/uuid" -> "uuid".

func ExtractReactionIDFromName added in v0.25.0

func ExtractReactionIDFromName(name string) (int32, error)

ExtractReactionIDFromName returns the reaction ID from a resource name. e.g., "reactions/123" -> 123.

func ExtractUserIDAndSettingKeyFromName added in v0.25.1

func ExtractUserIDAndSettingKeyFromName(name string) (int32, string, error)

ExtractUserIDAndSettingKeyFromName extracts user ID and setting key from resource name. e.g., "users/123/settings/general" -> 123, "general".

func ExtractUserIDFromName

func ExtractUserIDFromName(name string) (int32, error)

ExtractUserIDFromName returns the uid from a resource name.

func ExtractWorkspaceSettingKeyFromName

func ExtractWorkspaceSettingKeyFromName(name string) (string, error)

func GenerateAccessToken

func GenerateAccessToken(username string, userID int32, expirationTime time.Time, secret []byte) (string, error)

GenerateAccessToken generates an access token.

func GenerateSessionID added in v0.25.0

func GenerateSessionID() (string, error)

GenerateSessionID generates a unique session ID using UUIDv4.

func GetNameParentTokens

func GetNameParentTokens(name string, tokenPrefixes ...string) ([]string, error)

GetNameParentTokens returns the tokens from a resource name.

func ParseSessionCookieValue added in v0.25.0

func ParseSessionCookieValue(cookieValue string) (int32, string, error)

ParseSessionCookieValue parses the session cookie value to extract userID and sessionID.

func SaveAttachmentBlob added in v0.25.0

func SaveAttachmentBlob(ctx context.Context, profile *profile.Profile, stores *store.Store, create *store.Attachment) error

SaveAttachmentBlob save the blob of attachment based on the storage config.

Types

type APIV1Service

func NewAPIV1Service

func NewAPIV1Service(secret string, profile *profile.Profile, store *store.Store, grpcServer *grpc.Server) *APIV1Service

func (*APIV1Service) Check added in v0.24.2

func (*APIV1Service) CreateAttachment added in v0.25.0

func (s *APIV1Service) CreateAttachment(ctx context.Context, request *v1pb.CreateAttachmentRequest) (*v1pb.Attachment, error)

func (*APIV1Service) CreateIdentityProvider

func (s *APIV1Service) CreateIdentityProvider(ctx context.Context, request *v1pb.CreateIdentityProviderRequest) (*v1pb.IdentityProvider, error)

func (*APIV1Service) CreateMemo

func (s *APIV1Service) CreateMemo(ctx context.Context, request *v1pb.CreateMemoRequest) (*v1pb.Memo, error)

func (*APIV1Service) CreateMemoComment

func (s *APIV1Service) CreateMemoComment(ctx context.Context, request *v1pb.CreateMemoCommentRequest) (*v1pb.Memo, error)

func (*APIV1Service) CreateSession added in v0.25.0

func (*APIV1Service) CreateShortcut added in v0.24.0

func (s *APIV1Service) CreateShortcut(ctx context.Context, request *v1pb.CreateShortcutRequest) (*v1pb.Shortcut, error)

func (*APIV1Service) CreateUser

func (s *APIV1Service) CreateUser(ctx context.Context, request *v1pb.CreateUserRequest) (*v1pb.User, error)

func (*APIV1Service) CreateUserAccessToken

func (s *APIV1Service) CreateUserAccessToken(ctx context.Context, request *v1pb.CreateUserAccessTokenRequest) (*v1pb.UserAccessToken, error)

func (*APIV1Service) CreateUserWebhook added in v0.25.1

func (s *APIV1Service) CreateUserWebhook(ctx context.Context, request *v1pb.CreateUserWebhookRequest) (*v1pb.UserWebhook, error)

func (*APIV1Service) DeleteAttachment added in v0.25.0

func (s *APIV1Service) DeleteAttachment(ctx context.Context, request *v1pb.DeleteAttachmentRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteIdentityProvider

func (s *APIV1Service) DeleteIdentityProvider(ctx context.Context, request *v1pb.DeleteIdentityProviderRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteInbox

func (s *APIV1Service) DeleteInbox(ctx context.Context, request *v1pb.DeleteInboxRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteMemo

func (s *APIV1Service) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteMemoReaction

func (s *APIV1Service) DeleteMemoReaction(ctx context.Context, request *v1pb.DeleteMemoReactionRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteMemoTag

func (s *APIV1Service) DeleteMemoTag(ctx context.Context, request *v1pb.DeleteMemoTagRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteSession added in v0.25.0

func (s *APIV1Service) DeleteSession(ctx context.Context, _ *v1pb.DeleteSessionRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteShortcut added in v0.24.0

func (s *APIV1Service) DeleteShortcut(ctx context.Context, request *v1pb.DeleteShortcutRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteUser

func (s *APIV1Service) DeleteUser(ctx context.Context, request *v1pb.DeleteUserRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteUserAccessToken

func (s *APIV1Service) DeleteUserAccessToken(ctx context.Context, request *v1pb.DeleteUserAccessTokenRequest) (*emptypb.Empty, error)

func (*APIV1Service) DeleteUserWebhook added in v0.25.1

func (s *APIV1Service) DeleteUserWebhook(ctx context.Context, request *v1pb.DeleteUserWebhookRequest) (*emptypb.Empty, error)

func (*APIV1Service) DispatchMemoCreatedWebhook

func (s *APIV1Service) DispatchMemoCreatedWebhook(ctx context.Context, memo *v1pb.Memo) error

DispatchMemoCreatedWebhook dispatches webhook when memo is created.

func (*APIV1Service) DispatchMemoDeletedWebhook

func (s *APIV1Service) DispatchMemoDeletedWebhook(ctx context.Context, memo *v1pb.Memo) error

DispatchMemoDeletedWebhook dispatches webhook when memo is deleted.

func (*APIV1Service) DispatchMemoUpdatedWebhook

func (s *APIV1Service) DispatchMemoUpdatedWebhook(ctx context.Context, memo *v1pb.Memo) error

DispatchMemoUpdatedWebhook dispatches webhook when memo is updated.

func (*APIV1Service) GetActivity

func (s *APIV1Service) GetActivity(ctx context.Context, request *v1pb.GetActivityRequest) (*v1pb.Activity, error)

func (*APIV1Service) GetAttachment added in v0.25.0

func (s *APIV1Service) GetAttachment(ctx context.Context, request *v1pb.GetAttachmentRequest) (*v1pb.Attachment, error)

func (*APIV1Service) GetAttachmentBinary added in v0.25.0

func (s *APIV1Service) GetAttachmentBinary(ctx context.Context, request *v1pb.GetAttachmentBinaryRequest) (*httpbody.HttpBody, error)

func (*APIV1Service) GetAttachmentBlob added in v0.25.0

func (s *APIV1Service) GetAttachmentBlob(attachment *store.Attachment) ([]byte, error)

func (*APIV1Service) GetCurrentSession added in v0.25.0

func (*APIV1Service) GetCurrentUser added in v0.22.1

func (s *APIV1Service) GetCurrentUser(ctx context.Context) (*store.User, error)

func (*APIV1Service) GetIdentityProvider

func (s *APIV1Service) GetIdentityProvider(ctx context.Context, request *v1pb.GetIdentityProviderRequest) (*v1pb.IdentityProvider, error)

func (*APIV1Service) GetInstanceOwner

func (s *APIV1Service) GetInstanceOwner(ctx context.Context) (*v1pb.User, error)

func (*APIV1Service) GetLinkMetadata

func (*APIV1Service) GetLinkMetadata(_ context.Context, request *v1pb.GetLinkMetadataRequest) (*v1pb.LinkMetadata, error)

func (*APIV1Service) GetMemo

func (s *APIV1Service) GetMemo(ctx context.Context, request *v1pb.GetMemoRequest) (*v1pb.Memo, error)

func (*APIV1Service) GetShortcut added in v0.25.0

func (s *APIV1Service) GetShortcut(ctx context.Context, request *v1pb.GetShortcutRequest) (*v1pb.Shortcut, error)

func (*APIV1Service) GetUser

func (s *APIV1Service) GetUser(ctx context.Context, request *v1pb.GetUserRequest) (*v1pb.User, error)

func (*APIV1Service) GetUserAvatar added in v0.25.0

func (s *APIV1Service) GetUserAvatar(ctx context.Context, request *v1pb.GetUserAvatarRequest) (*httpbody.HttpBody, error)

func (*APIV1Service) GetUserSetting

func (s *APIV1Service) GetUserSetting(ctx context.Context, request *v1pb.GetUserSettingRequest) (*v1pb.UserSetting, error)

func (*APIV1Service) GetUserStats added in v0.23.1

func (s *APIV1Service) GetUserStats(ctx context.Context, request *v1pb.GetUserStatsRequest) (*v1pb.UserStats, error)

func (*APIV1Service) GetWorkspaceProfile

GetWorkspaceProfile returns the workspace profile.

func (*APIV1Service) GetWorkspaceSetting

func (s *APIV1Service) GetWorkspaceSetting(ctx context.Context, request *v1pb.GetWorkspaceSettingRequest) (*v1pb.WorkspaceSetting, error)

func (*APIV1Service) ListActivities added in v0.25.0

func (*APIV1Service) ListAllUserStats added in v0.23.1

func (*APIV1Service) ListAttachments added in v0.25.0

func (*APIV1Service) ListInboxes

func (*APIV1Service) ListMemoAttachments added in v0.25.0

func (*APIV1Service) ListMemoComments

func (*APIV1Service) ListMemoReactions

func (*APIV1Service) ListMemoRelations

func (*APIV1Service) ListMemos

func (s *APIV1Service) ListMemos(ctx context.Context, request *v1pb.ListMemosRequest) (*v1pb.ListMemosResponse, error)

func (*APIV1Service) ListShortcuts added in v0.24.0

func (*APIV1Service) ListUserAccessTokens

func (*APIV1Service) ListUserSessions added in v0.25.0

func (*APIV1Service) ListUserSettings added in v0.25.1

func (*APIV1Service) ListUserWebhooks added in v0.25.1

func (*APIV1Service) ListUsers

func (s *APIV1Service) ListUsers(ctx context.Context, request *v1pb.ListUsersRequest) (*v1pb.ListUsersResponse, error)

func (*APIV1Service) ParseMarkdown

func (*APIV1Service) RegisterGateway

func (s *APIV1Service) RegisterGateway(ctx context.Context, echoServer *echo.Echo) error

RegisterGateway registers the gRPC-Gateway with the given Echo instance.

func (*APIV1Service) RenameMemoTag

func (s *APIV1Service) RenameMemoTag(ctx context.Context, request *v1pb.RenameMemoTagRequest) (*emptypb.Empty, error)

func (*APIV1Service) RestoreMarkdownNodes added in v0.22.3

func (*APIV1Service) RevokeUserSession added in v0.25.0

func (s *APIV1Service) RevokeUserSession(ctx context.Context, request *v1pb.RevokeUserSessionRequest) (*emptypb.Empty, error)

func (*APIV1Service) SetMemoAttachments added in v0.25.0

func (s *APIV1Service) SetMemoAttachments(ctx context.Context, request *v1pb.SetMemoAttachmentsRequest) (*emptypb.Empty, error)

func (*APIV1Service) SetMemoRelations

func (s *APIV1Service) SetMemoRelations(ctx context.Context, request *v1pb.SetMemoRelationsRequest) (*emptypb.Empty, error)

func (*APIV1Service) StringifyMarkdownNodes added in v0.22.3

func (*APIV1Service) UpdateAttachment added in v0.25.0

func (s *APIV1Service) UpdateAttachment(ctx context.Context, request *v1pb.UpdateAttachmentRequest) (*v1pb.Attachment, error)

func (*APIV1Service) UpdateIdentityProvider

func (s *APIV1Service) UpdateIdentityProvider(ctx context.Context, request *v1pb.UpdateIdentityProviderRequest) (*v1pb.IdentityProvider, error)

func (*APIV1Service) UpdateInbox

func (s *APIV1Service) UpdateInbox(ctx context.Context, request *v1pb.UpdateInboxRequest) (*v1pb.Inbox, error)

func (*APIV1Service) UpdateMemo

func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoRequest) (*v1pb.Memo, error)

func (*APIV1Service) UpdateShortcut added in v0.24.0

func (s *APIV1Service) UpdateShortcut(ctx context.Context, request *v1pb.UpdateShortcutRequest) (*v1pb.Shortcut, error)

func (*APIV1Service) UpdateUser

func (s *APIV1Service) UpdateUser(ctx context.Context, request *v1pb.UpdateUserRequest) (*v1pb.User, error)

func (*APIV1Service) UpdateUserSetting

func (s *APIV1Service) UpdateUserSetting(ctx context.Context, request *v1pb.UpdateUserSettingRequest) (*v1pb.UserSetting, error)

func (*APIV1Service) UpdateUserWebhook added in v0.25.1

func (s *APIV1Service) UpdateUserWebhook(ctx context.Context, request *v1pb.UpdateUserWebhookRequest) (*v1pb.UserWebhook, error)

func (*APIV1Service) UpdateWorkspaceSetting added in v0.25.0

func (s *APIV1Service) UpdateWorkspaceSetting(ctx context.Context, request *v1pb.UpdateWorkspaceSettingRequest) (*v1pb.WorkspaceSetting, error)

func (*APIV1Service) UpsertAccessTokenToStore

func (s *APIV1Service) UpsertAccessTokenToStore(ctx context.Context, user *store.User, accessToken, description string) error

func (*APIV1Service) UpsertMemoReaction

func (s *APIV1Service) UpsertMemoReaction(ctx context.Context, request *v1pb.UpsertMemoReactionRequest) (*v1pb.Reaction, error)

func (*APIV1Service) UpsertUserSession added in v0.25.0

func (s *APIV1Service) UpsertUserSession(ctx context.Context, userID int32, sessionID string, clientInfo *storepb.SessionsUserSetting_ClientInfo) error

UpsertUserSession adds or updates a user session.

type ClaimsMessage

type ClaimsMessage struct {
	Name string `json:"name"`
	jwt.RegisteredClaims
}

type ContextKey

type ContextKey int

ContextKey is the key type of context value.

type GRPCAuthInterceptor

type GRPCAuthInterceptor struct {
	Store *store.Store
	// contains filtered or unexported fields
}

GRPCAuthInterceptor is the auth interceptor for gRPC server.

func NewGRPCAuthInterceptor

func NewGRPCAuthInterceptor(store *store.Store, secret string) *GRPCAuthInterceptor

NewGRPCAuthInterceptor returns a new API auth interceptor.

func (*GRPCAuthInterceptor) AuthenticationInterceptor

func (in *GRPCAuthInterceptor) AuthenticationInterceptor(ctx context.Context, request any, serverInfo *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)

AuthenticationInterceptor is the unary interceptor for gRPC API.

type LoggerInterceptor

type LoggerInterceptor struct {
	// contains filtered or unexported fields
}

func NewLoggerInterceptor

func NewLoggerInterceptor(logStacktrace bool) *LoggerInterceptor

func (*LoggerInterceptor) LoggerInterceptor

func (in *LoggerInterceptor) LoggerInterceptor(ctx context.Context, request any, serverInfo *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL