backend

package
v0.0.0-...-91e6b38 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeSection  = "section"
	TypeDocument = "document"
	TypeResource = "resource"
)
View Source
const (
	TypeInitialContent = "initial-content"
	TypeEditRequest    = "edit-request"
	TypeSyncRequest    = "sync-request"
)
View Source
const (
	ContentPath = "content"
)
View Source
const (
	EndpointPathAlive = "/alive/"
)

Variables

This section is empty.

Functions

func ApplyPatch

func ApplyPatch(textToPatch string, patchesText string) (patched string, err error)

ApplyPatch applies a list of patches in the form of a string to a given text

func CreateFile

func CreateFile(path string, content string)

CreateFile create a new file with the given content

func CreatePatch

func CreatePatch(oldText string, newText string) (patches string, err error)

CreatePatch detect diff and create patch from diff

func DeleteFileOrFolder

func DeleteFileOrFolder(path string) (bool, error)

DeleteFileOrFolder delete a file from disk

func ReadFile

func ReadFile(path string) (string, error)

ReadFile read the content of a file

func UpdateFileFromForm

func UpdateFileFromForm(file *multipart.FileHeader, targetPath string) error

UpdateFileFromForm update the content of an existing file

func WriteFile

func WriteFile(path string, data []byte) (err error)

Types

type AutomergeSyncManager

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

AutomergeSyncManager manages processing of SyncRequests from clients

func NewAutomergeSyncManager

func NewAutomergeSyncManager(
	treeManager *TreeManager,
) *AutomergeSyncManager

func (*AutomergeSyncManager) IsItemBeingEditedRecursive

func (sm *AutomergeSyncManager) IsItemBeingEditedRecursive(s *Section) (err error)

func (*AutomergeSyncManager) SetWebsocketConnectionManager

func (sm *AutomergeSyncManager) SetWebsocketConnectionManager(manager *WebsocketConnectionManager)

type DSSyncManager

type DSSyncManager struct {

	// ServerShadows client connection -> server shadow
	ServerShadows map[*websocket.Conn]string
	// contains filtered or unexported fields
}

DSSyncManager manages processing of EditRequests from clients

func NewSyncManager

func NewSyncManager(
	treeManager *TreeManager,
) *DSSyncManager

func (*DSSyncManager) IsItemBeingEditedRecursive

func (sm *DSSyncManager) IsItemBeingEditedRecursive(s *Section) (err error)

func (*DSSyncManager) SetWebsocketConnectionManager

func (sm *DSSyncManager) SetWebsocketConnectionManager(manager *WebsocketConnectionManager)

type Document

type Document struct {
	Type     string    `json:"type" xml:"type" form:"type" query:"type"`
	ID       string    `json:"id" xml:"id" form:"id" query:"id"`
	Name     string    `json:"name" xml:"name" form:"name" query:"name"`
	Path     string    `json:"-" xml:"-" form:"-" query:"-"`
	Filesize int64     `json:"filesize" xml:"filesize" form:"filesize" query:"filesize"`
	ModTime  time.Time `json:"modtime" xml:"modtime" form:"modtime" query:"modtime"`
	Content  string    `json:"-" xml:"-" form:"-" query:"-"`
	SubUrl   string    `json:"url" xml:"url" form:"url" query:"url"`
}

type EditRequest

type EditRequest struct {
	Type           string `json:"type" xml:"type" form:"type" query:"type"`
	RequestId      string `json:"requestId" xml:"requestId" form:"requestId" query:"requestId"`
	DocumentId     string `json:"documentId" xml:"documentId" form:"documentId" query:"documentId"`
	Patches        string `json:"patches" xml:"patches" form:"patches" query:"patches"`
	ShadowChecksum string `json:"shadowChecksum" xml:"shadowChecksum" form:"shadowChecksum" query:"shadowChecksum"`
}

type ErrorResult

type ErrorResult struct {
	Name    string `json:"name" xml:"name" form:"name" query:"name"`
	Message string `json:"message" xml:"message" form:"message" query:"message"`
}

type FileWatcher

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

func NewFileWatcher

func NewFileWatcher(path string, action func(s string)) *FileWatcher

func (*FileWatcher) Close

func (fw *FileWatcher) Close()

stop watching any files

func (*FileWatcher) WatchDirRecursive

func (fw *FileWatcher) WatchDirRecursive()

watches all files and folders in the given path recursively

type InitialContentRequest

type InitialContentRequest struct {
	Type       string `json:"type" xml:"type" form:"type" query:"type"`
	RequestId  string `json:"requestId" xml:"requestId" form:"requestId" query:"requestId"`
	DocumentId string `json:"documentId" xml:"documentId" form:"documentId" query:"documentId"`
	Content    string `json:"content" xml:"content" form:"content" query:"content"`
}

type MkDocsConfig

type MkDocsConfig struct {
	Copyright          string                 `yaml:"copyright"`
	EditUri            string                 `yaml:"edit_uri"`
	Extra              map[string]interface{} `yaml:",inline"`
	ExtraCss           []string               `yaml:"extra_css"`
	MarkdownExtensions []interface{}          `yaml:"markdown_extensions"`

	RepoName string `yaml:"repo_name"`
	RepoUrl  string `yaml:"repo_url"`

	SiteAuthor      string `yaml:"site_author"`
	SiteDescription string `yaml:"site_description"`
	SiteDir         string `yaml:"site_dir"`
	SiteName        string `yaml:"site_name"`
	SiteUrl         string `yaml:"site_url"`

	Theme MkDocsConfigTheme `yaml:"theme"`
}

type MkDocsConfigTheme

type MkDocsConfigTheme struct {
	Name      string                   `yaml:"name"`
	Palette   MkDocsConfigThemePalette `yaml:"palette"`
	CustomDir string                   `yaml:"custom_dir"`
}

type MkDocsConfigThemePalette

type MkDocsConfigThemePalette struct {
	Primary string `yaml:"primary"`
	Accent  string `yaml:"accent"`
}

type NewDocumentRequest

type NewDocumentRequest struct {
	Parent string `json:"parent" xml:"parent" form:"parent" query:"parent" validate:"required"`
	Name   string `json:"name" xml:"name" form:"name" query:"name" validate:"required"`
}

type NewSectionRequest

type NewSectionRequest struct {
	Parent string `json:"parent" xml:"parent" form:"parent" query:"parent" validate:"required"`
	Name   string `json:"name" xml:"name" form:"name" query:"name" validate:"required"`
}

type RenameDocumentRequest

type RenameDocumentRequest struct {
	Name string `json:"name" xml:"name" form:"name" query:"name" validate:"required"`
}

type RenameResourceRequest

type RenameResourceRequest struct {
	Name string `json:"name" xml:"name" form:"name" query:"name" validate:"required"`
}

type RenameSectionRequest

type RenameSectionRequest struct {
	Name string `json:"name" xml:"name" form:"name" query:"name" validate:"required"`
}

type Resource

type Resource struct {
	Type     string    `json:"type" xml:"type" form:"type" query:"type"`
	ID       string    `json:"id" xml:"id" form:"id" query:"id"`
	Name     string    `json:"name" xml:"name" form:"name" query:"name"`
	Path     string    `json:"-" xml:"-" form:"-" query:"-"`
	Filesize int64     `json:"filesize" xml:"filesize" form:"filesize" query:"filesize"`
	ModTime  time.Time `json:"modtime" xml:"modtime" form:"modtime" query:"modtime"`
}

type RestService

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

func NewRestService

func NewRestService(
	treeManager *TreeManager,
	syncManager SyncManager,
) *RestService

func (*RestService) GetResourceDescription

func (rs *RestService) GetResourceDescription(c echo.Context) (err error)

GetResourceDescription returns the description of a single resource with the given id (if found)

func (*RestService) RegisterWebsocketHandler

func (rs *RestService) RegisterWebsocketHandler(websocketConnectionManager *WebsocketConnectionManager)

func (*RestService) ReturnError

func (rs *RestService) ReturnError(c echo.Context, e error) (err error)

return the error message of an error

func (*RestService) ReturnNotFound

func (rs *RestService) ReturnNotFound(c echo.Context, id string) (err error)

return a "not found" message

func (*RestService) Start

func (rs *RestService) Start()

Start the REST service

type Section

type Section struct {
	Type        string       `json:"type" xml:"type" form:"type" query:"type"`
	ID          string       `json:"id" xml:"id" form:"id" query:"id"`
	Name        string       `json:"name" xml:"name" form:"name" query:"name"`
	Path        string       `json:"-" xml:"-" form:"-" query:"-"`
	Subsections *[]*Section  `json:"subsections" xml:"subsections" form:"subsections" query:"subsections"`
	Documents   *[]*Document `json:"documents" xml:"documents" form:"documents" query:"documents"`
	Resources   *[]*Resource `json:"resources" xml:"resources" form:"resources" query:"resources"`
}

type SocketEntityBase

type SocketEntityBase struct {
	Type       string `json:"type" xml:"type" form:"type" query:"type"`
	RequestId  string `json:"requestId" xml:"requestId" form:"requestId" query:"requestId"`
	DocumentId string `json:"documentId" xml:"documentId" form:"documentId" query:"documentId"`
}

type SyncManager

type SyncManager interface {
	IsItemBeingEditedRecursive(s *Section) (err error)
}

type SyncRequest

type SyncRequest struct {
	Type       string `json:"type" xml:"type" form:"type" query:"type"`
	RequestId  string `json:"requestId" xml:"requestId" form:"requestId" query:"requestId"`
	DocumentId string `json:"documentId" xml:"documentId" form:"documentId" query:"documentId"`
	// *automerge.Doc as base64 encoded string
	DocumentState string `json:"documentState" xml:"documentState" form:"documentState" query:"documentState"`
	// *automerge.SyncMessage as base64 encoded string
	SyncMessage string `json:"syncMessage" xml:"syncMessage" form:"syncMessage" query:"syncMessage"`
}

func (SyncRequest) GetSyncMessageBytes

func (s SyncRequest) GetSyncMessageBytes() ([]byte, error)

type TreeManager

type TreeManager struct {

	// DocumentTree an in memory representation of the mkdocs file structure
	DocumentTree Section
	// contains filtered or unexported fields
}

func NewTreeManager

func NewTreeManager() *TreeManager

func (*TreeManager) CreateDocument

func (tm *TreeManager) CreateDocument(parentSectionId string, documentName string) (document *Document, err error)

CreateDocument creates a new document as a child of the given parent section id and the given name

func (*TreeManager) CreateItemTree

func (tm *TreeManager) CreateItemTree()

CreateItemTree traverses the mkdocs directory and puts all files into a tree representation

func (*TreeManager) CreateResource

func (tm *TreeManager) CreateResource(parentSectionId string, resourceName string, content string) (resource *Resource, err error)

func (*TreeManager) CreateResourceFromMultipart

func (tm *TreeManager) CreateResourceFromMultipart(parentSectionId string, resourceName string, src multipart.File) (resource *Resource, err error)

func (*TreeManager) CreateSection

func (tm *TreeManager) CreateSection(parentSection *Section, sectionName string) (section *Section, err error)

CreateSection creates a new section with the given name as a child of the given parent section

func (*TreeManager) DeleteItem

func (tm *TreeManager) DeleteItem(id string, itemType string) (success bool, err error)

DeleteItem deletes a file/folder with the given ID and type from disk

func (*TreeManager) GetDocument

func (tm *TreeManager) GetDocument(id string) *Document

GetDocument finds a document with the given id in the document tree

func (*TreeManager) GetResource

func (tm *TreeManager) GetResource(id string) *Resource

GetResource finds a resource with the given id in the document tree

func (*TreeManager) GetSection

func (tm *TreeManager) GetSection(id string) *Section

GetSection finds a document with the given id in the document tree

func (*TreeManager) RenameDocument

func (tm *TreeManager) RenameDocument(document *Document, name string) (doc *Document, err error)

func (*TreeManager) RenameResource

func (tm *TreeManager) RenameResource(resource *Resource, name string) (res *Resource, err error)

func (*TreeManager) RenameSection

func (tm *TreeManager) RenameSection(section *Section, name string) (sec *Section, err error)

type WebsocketConnectionManager

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

func NewWebsocketConnectionManager

func NewWebsocketConnectionManager(
	treeManager *TreeManager,
) *WebsocketConnectionManager

func (*WebsocketConnectionManager) HandleNewConnection

func (wcm *WebsocketConnectionManager) HandleNewConnection(c echo.Context, documentId string) (err error)

handle new websocket connections

func (*WebsocketConnectionManager) IsClientConnected

func (wcm *WebsocketConnectionManager) IsClientConnected(documentId string) bool

func (*WebsocketConnectionManager) SetOnClientDisconnectedListener

func (wcm *WebsocketConnectionManager) SetOnClientDisconnectedListener(f func(client *websocket.Conn, documentId string, remainingConnections uint))

func (*WebsocketConnectionManager) SetOnIncomingEditRequestMessageListener

func (wcm *WebsocketConnectionManager) SetOnIncomingEditRequestMessageListener(f func(client *websocket.Conn, request EditRequest) error)

func (*WebsocketConnectionManager) SetOnNewClientListener

func (wcm *WebsocketConnectionManager) SetOnNewClientListener(f func(client *websocket.Conn, document *Document) error)

func (*WebsocketConnectionManager) SetOnSyncRequestMessageListener

func (wcm *WebsocketConnectionManager) SetOnSyncRequestMessageListener(f func(client *websocket.Conn, request SyncRequest) error)

Jump to

Keyboard shortcuts

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