v1

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const UnknownID = -1

UnknownID is the ID for unknowns.

Variables

View Source
var (
	UserSettingLocaleValue = []string{
		"de",
		"en",
		"es",
		"fr",
		"hr",
		"it",
		"ja",
		"ko",
		"nl",
		"pl",
		"pt-BR",
		"ru",
		"sl",
		"sv",
		"tr",
		"uk",
		"vi",
		"zh-Hans",
		"zh-Hant",
	}
	UserSettingAppearanceValue     = []string{"system", "light", "dark"}
	UserSettingMemoVisibilityValue = []Visibility{Private, Protected, Public}
)

Functions

func JWTMiddleware

func JWTMiddleware(server *APIV1Service, next echo.HandlerFunc, secret string) echo.HandlerFunc

JWTMiddleware validates the access token. If the access token is about to expire or has expired and the request has a valid refresh token, it will try to generate new access token and refresh token.

Types

type APIV1Service

type APIV1Service struct {
	Secret  string
	Profile *profile.Profile
	Store   *store.Store
}

func NewAPIV1Service

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

func (*APIV1Service) Register

func (s *APIV1Service) Register(rootGroup *echo.Group)

type Activity

type Activity struct {
	ID int `json:"id"`

	// Standard fields
	CreatorID int   `json:"creatorId"`
	CreatedTs int64 `json:"createdTs"`

	// Domain specific fields
	Type    ActivityType  `json:"type"`
	Level   ActivityLevel `json:"level"`
	Payload string        `json:"payload"`
}

type ActivityCreate

type ActivityCreate struct {
	// Standard fields
	CreatorID int

	// Domain specific fields
	Type    ActivityType `json:"type"`
	Level   ActivityLevel
	Payload string `json:"payload"`
}

ActivityCreate is the API message for creating an activity.

type ActivityLevel

type ActivityLevel string

ActivityLevel is the level of activities.

const (
	// ActivityInfo is the INFO level of activities.
	ActivityInfo ActivityLevel = "INFO"
	// ActivityWarn is the WARN level of activities.
	ActivityWarn ActivityLevel = "WARN"
	// ActivityError is the ERROR level of activities.
	ActivityError ActivityLevel = "ERROR"
)

type ActivityMemoCreatePayload

type ActivityMemoCreatePayload struct {
	Content    string `json:"content"`
	Visibility string `json:"visibility"`
}

type ActivityResourceCreatePayload

type ActivityResourceCreatePayload struct {
	Filename string `json:"filename"`
	Type     string `json:"type"`
	Size     int64  `json:"size"`
}

type ActivityServerStartPayload

type ActivityServerStartPayload struct {
	ServerID string           `json:"serverId"`
	Profile  *profile.Profile `json:"profile"`
}

type ActivityShortcutCreatePayload

type ActivityShortcutCreatePayload struct {
	Title   string `json:"title"`
	Payload string `json:"payload"`
}

type ActivityTagCreatePayload

type ActivityTagCreatePayload struct {
	TagName string `json:"tagName"`
}

type ActivityType

type ActivityType string

ActivityType is the type for an activity.

const (

	// ActivityUserCreate is the type for creating users.
	ActivityUserCreate ActivityType = "user.create"
	// ActivityUserUpdate is the type for updating users.
	ActivityUserUpdate ActivityType = "user.update"
	// ActivityUserDelete is the type for deleting users.
	ActivityUserDelete ActivityType = "user.delete"
	// ActivityUserAuthSignIn is the type for user signin.
	ActivityUserAuthSignIn ActivityType = "user.auth.signin"
	// ActivityUserAuthSignUp is the type for user signup.
	ActivityUserAuthSignUp ActivityType = "user.auth.signup"
	// ActivityUserSettingUpdate is the type for updating user settings.
	ActivityUserSettingUpdate ActivityType = "user.setting.update"

	// ActivityMemoCreate is the type for creating memos.
	ActivityMemoCreate ActivityType = "memo.create"
	// ActivityMemoUpdate is the type for updating memos.
	ActivityMemoUpdate ActivityType = "memo.update"
	// ActivityMemoDelete is the type for deleting memos.
	ActivityMemoDelete ActivityType = "memo.delete"

	// ActivityShortcutCreate is the type for creating shortcuts.
	ActivityShortcutCreate ActivityType = "shortcut.create"
	// ActivityShortcutUpdate is the type for updating shortcuts.
	ActivityShortcutUpdate ActivityType = "shortcut.update"
	// ActivityShortcutDelete is the type for deleting shortcuts.
	ActivityShortcutDelete ActivityType = "shortcut.delete"

	// ActivityResourceCreate is the type for creating resources.
	ActivityResourceCreate ActivityType = "resource.create"
	// ActivityResourceDelete is the type for deleting resources.
	ActivityResourceDelete ActivityType = "resource.delete"

	// ActivityTagCreate is the type for creating tags.
	ActivityTagCreate ActivityType = "tag.create"
	// ActivityTagDelete is the type for deleting tags.
	ActivityTagDelete ActivityType = "tag.delete"

	// ActivityServerStart is the type for starting server.
	ActivityServerStart ActivityType = "server.start"
)

type ActivityUserAuthSignInPayload

type ActivityUserAuthSignInPayload struct {
	UserID int    `json:"userId"`
	IP     string `json:"ip"`
}

type ActivityUserAuthSignUpPayload

type ActivityUserAuthSignUpPayload struct {
	Username string `json:"username"`
	IP       string `json:"ip"`
}

type ActivityUserCreatePayload

type ActivityUserCreatePayload struct {
	UserID   int    `json:"userId"`
	Username string `json:"username"`
	Role     Role   `json:"role"`
}

type Claims

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

Claims creates a struct that will be encoded to a JWT. We add jwt.RegisteredClaims as an embedded type, to provide fields such as name.

type CreateIdentityProviderRequest

type CreateIdentityProviderRequest struct {
	Name             string                  `json:"name"`
	Type             IdentityProviderType    `json:"type"`
	IdentifierFilter string                  `json:"identifierFilter"`
	Config           *IdentityProviderConfig `json:"config"`
}

type CustomizedProfile

type CustomizedProfile struct {
	// Name is the server name, default is `memos`
	Name string `json:"name"`
	// LogoURL is the url of logo image.
	LogoURL string `json:"logoUrl"`
	// Description is the server description.
	Description string `json:"description"`
	// Locale is the server default locale.
	Locale string `json:"locale"`
	// Appearance is the server default appearance.
	Appearance string `json:"appearance"`
	// ExternalURL is the external url of server. e.g. https://usermemos.com
	ExternalURL string `json:"externalUrl"`
}

CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item.

type FieldMapping

type FieldMapping struct {
	Identifier  string `json:"identifier"`
	DisplayName string `json:"displayName"`
	Email       string `json:"email"`
}

type IdentityProvider

type IdentityProvider struct {
	ID               int                     `json:"id"`
	Name             string                  `json:"name"`
	Type             IdentityProviderType    `json:"type"`
	IdentifierFilter string                  `json:"identifierFilter"`
	Config           *IdentityProviderConfig `json:"config"`
}

type IdentityProviderConfig

type IdentityProviderConfig struct {
	OAuth2Config *IdentityProviderOAuth2Config `json:"oauth2Config"`
}

type IdentityProviderOAuth2Config

type IdentityProviderOAuth2Config struct {
	ClientID     string        `json:"clientId"`
	ClientSecret string        `json:"clientSecret"`
	AuthURL      string        `json:"authUrl"`
	TokenURL     string        `json:"tokenUrl"`
	UserInfoURL  string        `json:"userInfoUrl"`
	Scopes       []string      `json:"scopes"`
	FieldMapping *FieldMapping `json:"fieldMapping"`
}

type IdentityProviderType

type IdentityProviderType string
const (
	IdentityProviderOAuth2 IdentityProviderType = "OAUTH2"
)

type OpenAIConfig

type OpenAIConfig struct {
	Key  string `json:"key"`
	Host string `json:"host"`
}

type Role

type Role string

Role is the type of a role.

const (
	// Host is the HOST role.
	Host Role = "HOST"
	// Admin is the ADMIN role.
	Admin Role = "ADMIN"
	// NormalUser is the USER role.
	NormalUser Role = "USER"
)

func (Role) String

func (e Role) String() string

type RowStatus

type RowStatus string

RowStatus is the status for a row.

const (
	// Normal is the status for a normal row.
	Normal RowStatus = "NORMAL"
	// Archived is the status for an archived row.
	Archived RowStatus = "ARCHIVED"
)

func (RowStatus) String

func (e RowStatus) String() string

type SSOSignIn

type SSOSignIn struct {
	IdentityProviderID int    `json:"identityProviderId"`
	Code               string `json:"code"`
	RedirectURI        string `json:"redirectUri"`
}

type SignIn

type SignIn struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type SignUp

type SignUp struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type SystemSetting

type SystemSetting struct {
	Name SystemSettingName `json:"name"`
	// Value is a JSON string with basic value.
	Value       string `json:"value"`
	Description string `json:"description"`
}

type SystemSettingFind

type SystemSettingFind struct {
	Name SystemSettingName `json:"name"`
}

type SystemSettingName

type SystemSettingName string
const (
	// SystemSettingServerIDName is the name of server id.
	SystemSettingServerIDName SystemSettingName = "server-id"
	// SystemSettingSecretSessionName is the name of secret session.
	SystemSettingSecretSessionName SystemSettingName = "secret-session"
	// SystemSettingAllowSignUpName is the name of allow signup setting.
	SystemSettingAllowSignUpName SystemSettingName = "allow-signup"
	// SystemSettingDisablePublicMemosName is the name of disable public memos setting.
	SystemSettingDisablePublicMemosName SystemSettingName = "disable-public-memos"
	// SystemSettingMaxUploadSizeMiBName is the name of max upload size setting.
	SystemSettingMaxUploadSizeMiBName SystemSettingName = "max-upload-size-mib"
	// SystemSettingAdditionalStyleName is the name of additional style.
	SystemSettingAdditionalStyleName SystemSettingName = "additional-style"
	// SystemSettingAdditionalScriptName is the name of additional script.
	SystemSettingAdditionalScriptName SystemSettingName = "additional-script"
	// SystemSettingCustomizedProfileName is the name of customized server profile.
	SystemSettingCustomizedProfileName SystemSettingName = "customized-profile"
	// SystemSettingStorageServiceIDName is the name of storage service ID.
	SystemSettingStorageServiceIDName SystemSettingName = "storage-service-id"
	// SystemSettingLocalStoragePathName is the name of local storage path.
	SystemSettingLocalStoragePathName SystemSettingName = "local-storage-path"
	// SystemSettingOpenAIConfigName is the name of OpenAI config.
	SystemSettingOpenAIConfigName SystemSettingName = "openai-config"
	// SystemSettingTelegramBotToken is the name of Telegram Bot Token.
	SystemSettingTelegramBotTokenName         SystemSettingName = "telegram-bot-token"
	SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts"
)

func (SystemSettingName) String

func (key SystemSettingName) String() string

type SystemSettingUpsert

type SystemSettingUpsert struct {
	Name        SystemSettingName `json:"name"`
	Value       string            `json:"value"`
	Description string            `json:"description"`
}

func (SystemSettingUpsert) Validate

func (upsert SystemSettingUpsert) Validate() error

type UpdateIdentityProviderRequest

type UpdateIdentityProviderRequest struct {
	ID               int
	Type             IdentityProviderType    `json:"type"`
	Name             *string                 `json:"name"`
	IdentifierFilter *string                 `json:"identifierFilter"`
	Config           *IdentityProviderConfig `json:"config"`
}

type UserSetting

type UserSetting struct {
	UserID int
	Key    UserSettingKey `json:"key"`
	// Value is a JSON string with basic value
	Value string `json:"value"`
}

type UserSettingDelete

type UserSettingDelete struct {
	UserID int
}

type UserSettingFind

type UserSettingFind struct {
	UserID *int

	Key UserSettingKey `json:"key"`
}

type UserSettingKey

type UserSettingKey string
const (
	// UserSettingLocaleKey is the key type for user locale.
	UserSettingLocaleKey UserSettingKey = "locale"
	// UserSettingAppearanceKey is the key type for user appearance.
	UserSettingAppearanceKey UserSettingKey = "appearance"
	// UserSettingMemoVisibilityKey is the key type for user preference memo default visibility.
	UserSettingMemoVisibilityKey UserSettingKey = "memo-visibility"
	// UserSettingTelegramUserID is the key type for telegram UserID of memos user.
	UserSettingTelegramUserIDKey UserSettingKey = "telegram-user-id"
)

func (UserSettingKey) String

func (key UserSettingKey) String() string

String returns the string format of UserSettingKey type.

type UserSettingUpsert

type UserSettingUpsert struct {
	UserID int            `json:"-"`
	Key    UserSettingKey `json:"key"`
	Value  string         `json:"value"`
}

func (UserSettingUpsert) Validate

func (upsert UserSettingUpsert) Validate() error

type Visibility

type Visibility string

Visibility is the type of a visibility.

const (
	// Public is the PUBLIC visibility.
	Public Visibility = "PUBLIC"
	// Protected is the PROTECTED visibility.
	Protected Visibility = "PROTECTED"
	// Private is the PRIVATE visibility.
	Private Visibility = "PRIVATE"
)

func (Visibility) String

func (v Visibility) String() string

Jump to

Keyboard shortcuts

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