v1

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LocalStorage means the storage service is local file system.
	LocalStorage int32 = -1
	// DatabaseStorage means the storage service is database.
	DatabaseStorage int32 = 0
)
View Source
const (
	MebiByte = 1024 * 1024
)
View Source
const UnknownID = -1

UnknownID is the ID for unknowns.

Variables

View Source
var (
	UserSettingLocaleValue = []string{
		"de",
		"en",
		"es",
		"fr",
		"hi",
		"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 GenerateAccessToken added in v0.14.3

func GenerateAccessToken(username string, userID int32, secret string) (string, error)

GenerateAccessToken generates an access token for web.

func GenerateTokensAndSetCookies added in v0.14.3

func GenerateTokensAndSetCookies(c echo.Context, user *store.User, secret string) error

GenerateTokensAndSetCookies generates jwt token and saves it to the http-only cookie.

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.

func RemoveTokensAndCookies added in v0.14.3

func RemoveTokensAndCookies(c echo.Context)

RemoveTokensAndCookies removes the jwt token and refresh token from the cookies.

func SaveResourceBlob added in v0.14.0

func SaveResourceBlob(ctx context.Context, s *store.Store, create *store.Resource, r io.Reader) error

SaveResourceBlob save the blob of resource based on the storage config

Depend on the storage config, some fields of *store.ResourceCreate will be changed: 1. *DatabaseStorage*: `create.Blob`. 2. *LocalStorage*: `create.InternalPath`. 3. Others( external service): `create.ExternalLink`.

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 int32 `json:"id"`

	// Standard fields
	CreatorID int32 `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 int32

	// 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"
)

func (ActivityLevel) String added in v0.14.0

func (l ActivityLevel) String() string

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 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"

	// 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"
)

func (ActivityType) String added in v0.14.0

func (t ActivityType) String() string

type ActivityUserAuthSignInPayload

type ActivityUserAuthSignInPayload struct {
	UserID int32  `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   int32  `json:"userId"`
	Username string `json:"username"`
	Role     Role   `json:"role"`
}

type CreateIdentityProviderRequest

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

type CreateMemoRequest added in v0.14.0

type CreateMemoRequest struct {
	// Standard fields
	CreatorID int32  `json:"-"`
	CreatedTs *int64 `json:"createdTs"`

	// Domain specific fields
	Visibility Visibility `json:"visibility"`
	Content    string     `json:"content"`

	// Related fields
	ResourceIDList []int32                      `json:"resourceIdList"`
	RelationList   []*UpsertMemoRelationRequest `json:"relationList"`
}

type CreateResourceRequest added in v0.14.0

type CreateResourceRequest struct {
	Filename        string `json:"filename"`
	InternalPath    string `json:"internalPath"`
	ExternalLink    string `json:"externalLink"`
	Type            string `json:"type"`
	DownloadToLocal bool   `json:"downloadToLocal"`
}

type CreateStorageRequest added in v0.14.0

type CreateStorageRequest struct {
	Name   string         `json:"name"`
	Type   StorageType    `json:"type"`
	Config *StorageConfig `json:"config"`
}

type CreateUserRequest added in v0.14.0

type CreateUserRequest struct {
	Username string `json:"username"`
	Role     Role   `json:"role"`
	Email    string `json:"email"`
	Nickname string `json:"nickname"`
	Password string `json:"password"`
}

func (CreateUserRequest) Validate added in v0.14.0

func (create CreateUserRequest) Validate() error

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 DeleteTagRequest added in v0.14.0

type DeleteTagRequest struct {
	Name string `json:"name"`
}

type FieldMapping

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

type FindMemoRequest added in v0.14.0

type FindMemoRequest struct {
	ID *int32

	// Standard fields
	RowStatus *RowStatus
	CreatorID *int32

	// Domain specific fields
	Pinned         *bool
	ContentSearch  []string
	VisibilityList []Visibility

	// Pagination
	Limit  *int
	Offset *int
}

type FindResourceRequest added in v0.14.0

type FindResourceRequest struct {
	ID        *int32  `json:"id"`
	CreatorID *int32  `json:"creatorId"`
	Filename  *string `json:"filename"`
}

type IdentityProvider

type IdentityProvider struct {
	ID               int32                   `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 (
	IdentityProviderOAuth2Type IdentityProviderType = "OAUTH2"
)

func (IdentityProviderType) String added in v0.14.0

func (t IdentityProviderType) String() string

type Memo added in v0.14.0

type Memo struct {
	ID int32 `json:"id"`

	// Standard fields
	RowStatus RowStatus `json:"rowStatus"`
	CreatorID int32     `json:"creatorId"`
	CreatedTs int64     `json:"createdTs"`
	UpdatedTs int64     `json:"updatedTs"`

	// Domain specific fields
	DisplayTs  int64      `json:"displayTs"`
	Content    string     `json:"content"`
	Visibility Visibility `json:"visibility"`
	Pinned     bool       `json:"pinned"`

	// Related fields
	CreatorName     string          `json:"creatorName"`
	CreatorUsername string          `json:"creatorUsername"`
	ResourceList    []*Resource     `json:"resourceList"`
	RelationList    []*MemoRelation `json:"relationList"`
}

type MemoOrganizer added in v0.14.0

type MemoOrganizer struct {
	MemoID int32 `json:"memoId"`
	UserID int32 `json:"userId"`
	Pinned bool  `json:"pinned"`
}

type MemoRelation added in v0.14.0

type MemoRelation struct {
	MemoID        int32            `json:"memoId"`
	RelatedMemoID int32            `json:"relatedMemoId"`
	Type          MemoRelationType `json:"type"`
}

type MemoRelationType added in v0.14.0

type MemoRelationType string
const (
	MemoRelationReference  MemoRelationType = "REFERENCE"
	MemoRelationAdditional MemoRelationType = "ADDITIONAL"
)

type MemoResource added in v0.14.0

type MemoResource struct {
	MemoID     int32 `json:"memoId"`
	ResourceID int32 `json:"resourceId"`
	CreatedTs  int64 `json:"createdTs"`
	UpdatedTs  int64 `json:"updatedTs"`
}

type MemoResourceDelete added in v0.14.0

type MemoResourceDelete struct {
	MemoID     *int32
	ResourceID *int32
}

type MemoResourceFind added in v0.14.0

type MemoResourceFind struct {
	MemoID     *int32
	ResourceID *int32
}

type PatchMemoRequest added in v0.14.0

type PatchMemoRequest struct {
	ID int32 `json:"-"`

	// Standard fields
	CreatedTs *int64 `json:"createdTs"`
	UpdatedTs *int64
	RowStatus *RowStatus `json:"rowStatus"`

	// Domain specific fields
	Content    *string     `json:"content"`
	Visibility *Visibility `json:"visibility"`

	// Related fields
	ResourceIDList []int32                      `json:"resourceIdList"`
	RelationList   []*UpsertMemoRelationRequest `json:"relationList"`
}

type Resource added in v0.14.0

type Resource struct {
	ID int32 `json:"id"`

	// Standard fields
	CreatorID int32 `json:"creatorId"`
	CreatedTs int64 `json:"createdTs"`
	UpdatedTs int64 `json:"updatedTs"`

	// Domain specific fields
	Filename     string `json:"filename"`
	Blob         []byte `json:"-"`
	InternalPath string `json:"-"`
	ExternalLink string `json:"externalLink"`
	Type         string `json:"type"`
	Size         int64  `json:"size"`

	// Related fields
	LinkedMemoAmount int `json:"linkedMemoAmount"`
}

type Role

type Role string

Role is the type of a role.

const (
	// RoleHost is the HOST role.
	RoleHost Role = "HOST"
	// RoleAdmin is the ADMIN role.
	RoleAdmin Role = "ADMIN"
	// RoleUser is the USER role.
	RoleUser Role = "USER"
)

func (Role) String

func (role 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 (r RowStatus) String() string

type SSOSignIn

type SSOSignIn struct {
	IdentityProviderID int32  `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 Storage added in v0.14.0

type Storage struct {
	ID     int32          `json:"id"`
	Name   string         `json:"name"`
	Type   StorageType    `json:"type"`
	Config *StorageConfig `json:"config"`
}

func ConvertStorageFromStore added in v0.14.0

func ConvertStorageFromStore(storage *store.Storage) (*Storage, error)

type StorageConfig added in v0.14.0

type StorageConfig struct {
	S3Config *StorageS3Config `json:"s3Config"`
}

type StorageS3Config added in v0.14.0

type StorageS3Config struct {
	EndPoint  string `json:"endPoint"`
	Path      string `json:"path"`
	Region    string `json:"region"`
	AccessKey string `json:"accessKey"`
	SecretKey string `json:"secretKey"`
	Bucket    string `json:"bucket"`
	URLPrefix string `json:"urlPrefix"`
	URLSuffix string `json:"urlSuffix"`
}

type StorageType added in v0.14.0

type StorageType string
const (
	StorageS3 StorageType = "S3"
)

func (StorageType) String added in v0.14.0

func (t StorageType) String() string

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 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"
	// SystemSettingDisablePasswordLoginName is the name of disable password login setting.
	SystemSettingDisablePasswordLoginName SystemSettingName = "disable-password-login"
	// 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"
	// SystemSettingTelegramBotToken is the name of Telegram Bot Token.
	SystemSettingTelegramBotTokenName SystemSettingName = "telegram-bot-token"
	// SystemSettingMemoDisplayWithUpdatedTsName is the name of memo display with updated ts.
	SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts"
	// SystemSettingAutoBackupIntervalName is the name of auto backup interval as seconds.
	SystemSettingAutoBackupIntervalName SystemSettingName = "auto-backup-interval"
)

func (SystemSettingName) String

func (key SystemSettingName) String() string

type SystemStatus added in v0.14.0

type SystemStatus struct {
	Host    *User           `json:"host"`
	Profile profile.Profile `json:"profile"`
	DBSize  int64           `json:"dbSize"`

	// System settings
	// Allow sign up.
	AllowSignUp bool `json:"allowSignUp"`
	// Disable password login.
	DisablePasswordLogin bool `json:"disablePasswordLogin"`
	// Disable public memos.
	DisablePublicMemos bool `json:"disablePublicMemos"`
	// Max upload size.
	MaxUploadSizeMiB int `json:"maxUploadSizeMiB"`
	// Auto Backup Interval.
	AutoBackupInterval int `json:"autoBackupInterval"`
	// Additional style.
	AdditionalStyle string `json:"additionalStyle"`
	// Additional script.
	AdditionalScript string `json:"additionalScript"`
	// Customized server profile, including server name and external url.
	CustomizedProfile CustomizedProfile `json:"customizedProfile"`
	// Storage service ID.
	StorageServiceID int32 `json:"storageServiceId"`
	// Local storage path.
	LocalStoragePath string `json:"localStoragePath"`
	// Memo display with updated timestamp.
	MemoDisplayWithUpdatedTs bool `json:"memoDisplayWithUpdatedTs"`
}

type Tag added in v0.14.0

type Tag struct {
	Name      string
	CreatorID int32
}

type UpdateIdentityProviderRequest

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

type UpdateResourceRequest added in v0.14.0

type UpdateResourceRequest struct {
	Filename *string `json:"filename"`
}

type UpdateStorageRequest added in v0.14.0

type UpdateStorageRequest struct {
	Type   StorageType    `json:"type"`
	Name   *string        `json:"name"`
	Config *StorageConfig `json:"config"`
}

type UpdateUserRequest added in v0.14.0

type UpdateUserRequest struct {
	RowStatus   *RowStatus `json:"rowStatus"`
	Username    *string    `json:"username"`
	Email       *string    `json:"email"`
	Nickname    *string    `json:"nickname"`
	Password    *string    `json:"password"`
	ResetOpenID *bool      `json:"resetOpenId"`
	AvatarURL   *string    `json:"avatarUrl"`
}

func (UpdateUserRequest) Validate added in v0.14.0

func (update UpdateUserRequest) Validate() error

type UpsertMemoOrganizerRequest added in v0.14.0

type UpsertMemoOrganizerRequest struct {
	Pinned bool `json:"pinned"`
}

type UpsertMemoRelationRequest added in v0.14.0

type UpsertMemoRelationRequest struct {
	RelatedMemoID int32            `json:"relatedMemoId"`
	Type          MemoRelationType `json:"type"`
}

type UpsertMemoResourceRequest added in v0.14.0

type UpsertMemoResourceRequest struct {
	ResourceID int32  `json:"resourceId"`
	UpdatedTs  *int64 `json:"updatedTs"`
}

type UpsertSystemSettingRequest added in v0.14.0

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

func (UpsertSystemSettingRequest) Validate added in v0.14.0

func (upsert UpsertSystemSettingRequest) Validate() error

type UpsertTagRequest added in v0.14.0

type UpsertTagRequest struct {
	Name string `json:"name"`
}

type UpsertUserSettingRequest added in v0.14.0

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

func (UpsertUserSettingRequest) Validate added in v0.14.0

func (upsert UpsertUserSettingRequest) Validate() error

type User added in v0.14.0

type User struct {
	ID int32 `json:"id"`

	// Standard fields
	RowStatus RowStatus `json:"rowStatus"`
	CreatedTs int64     `json:"createdTs"`
	UpdatedTs int64     `json:"updatedTs"`

	// Domain specific fields
	Username        string         `json:"username"`
	Role            Role           `json:"role"`
	Email           string         `json:"email"`
	Nickname        string         `json:"nickname"`
	PasswordHash    string         `json:"-"`
	OpenID          string         `json:"openId"`
	AvatarURL       string         `json:"avatarUrl"`
	UserSettingList []*UserSetting `json:"userSettingList"`
}

type UserSetting

type UserSetting struct {
	UserID int32          `json:"userId"`
	Key    UserSettingKey `json:"key"`
	Value  string         `json:"value"`
}

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 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