Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
|
|
@ -0,0 +1,14 @@
|
|||
package page
|
||||
|
||||
// DeleteRequest represents the delete pages request
|
||||
type DeleteRequest struct {
|
||||
PageIDs []string `json:"page_ids"`
|
||||
}
|
||||
|
||||
// DeleteResponse represents the delete pages response
|
||||
type DeleteResponse struct {
|
||||
DeletedCount int `json:"deleted_count"`
|
||||
DeindexedCount int `json:"deindexed_count"`
|
||||
FailedPages []string `json:"failed_pages,omitempty"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package page
|
||||
|
||||
// SearchRequest represents the search pages request
|
||||
type SearchRequest struct {
|
||||
Query string `json:"query"`
|
||||
Limit int64 `json:"limit"`
|
||||
Offset int64 `json:"offset"`
|
||||
Filter string `json:"filter,omitempty"`
|
||||
}
|
||||
|
||||
// SearchResponse represents the search pages response
|
||||
type SearchResponse struct {
|
||||
Hits []map[string]interface{} `json:"hits"`
|
||||
Query string `json:"query"`
|
||||
ProcessingTimeMs int64 `json:"processing_time_ms"`
|
||||
TotalHits int64 `json:"total_hits"`
|
||||
Limit int64 `json:"limit"`
|
||||
Offset int64 `json:"offset"`
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package page
|
||||
|
||||
import "time"
|
||||
|
||||
// StatusResponse represents the sync status response
|
||||
type StatusResponse struct {
|
||||
SiteID string `json:"site_id"`
|
||||
TotalPages int64 `json:"total_pages"`
|
||||
PublishedPages int64 `json:"published_pages"`
|
||||
DraftPages int64 `json:"draft_pages"`
|
||||
LastSyncedAt time.Time `json:"last_synced_at"`
|
||||
PagesIndexedMonth int64 `json:"pages_indexed_month"`
|
||||
SearchRequestsMonth int64 `json:"search_requests_month"`
|
||||
LastResetAt time.Time `json:"last_reset_at"`
|
||||
SearchIndexStatus string `json:"search_index_status"`
|
||||
SearchIndexDocCount int64 `json:"search_index_doc_count"`
|
||||
}
|
||||
|
||||
// PageDetailsResponse represents the page details response
|
||||
type PageDetailsResponse struct {
|
||||
PageID string `json:"page_id"`
|
||||
Title string `json:"title"`
|
||||
Excerpt string `json:"excerpt"`
|
||||
URL string `json:"url"`
|
||||
Status string `json:"status"`
|
||||
PostType string `json:"post_type"`
|
||||
Author string `json:"author"`
|
||||
PublishedAt time.Time `json:"published_at"`
|
||||
ModifiedAt time.Time `json:"modified_at"`
|
||||
IndexedAt time.Time `json:"indexed_at"`
|
||||
MeilisearchDocID string `json:"meilisearch_doc_id"`
|
||||
IsIndexed bool `json:"is_indexed"`
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
package page
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/pkg/validation"
|
||||
)
|
||||
|
||||
// Allowed page statuses
|
||||
var AllowedPageStatuses = []string{"publish", "draft", "pending", "private", "trash"}
|
||||
|
||||
// Allowed post types
|
||||
var AllowedPostTypes = []string{"post", "page", "attachment", "custom"}
|
||||
|
||||
// SyncPageInput represents a single page to sync in the request
|
||||
type SyncPageInput struct {
|
||||
PageID string `json:"page_id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Excerpt string `json:"excerpt"`
|
||||
URL string `json:"url"`
|
||||
Status string `json:"status"`
|
||||
PostType string `json:"post_type"`
|
||||
Author string `json:"author"`
|
||||
PublishedAt time.Time `json:"published_at"`
|
||||
ModifiedAt time.Time `json:"modified_at"`
|
||||
}
|
||||
|
||||
// Validate validates a single page input
|
||||
func (p *SyncPageInput) Validate() error {
|
||||
v := validation.NewValidator()
|
||||
|
||||
// Validate page ID (required)
|
||||
if err := v.ValidateRequired(p.PageID, "page_id"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v.ValidateLength(p.PageID, "page_id", 1, 255); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Validate title
|
||||
title, err := v.ValidateAndSanitizeString(p.Title, "title", 1, 500)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Title = title
|
||||
|
||||
// Validate content (optional but has max length if provided)
|
||||
if p.Content != "" {
|
||||
if err := v.ValidateLength(p.Content, "content", 0, 1000000); err != nil { // 1MB limit
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Validate excerpt (optional but has max length if provided)
|
||||
if p.Excerpt != "" {
|
||||
if err := v.ValidateLength(p.Excerpt, "excerpt", 0, 1000); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Validate URL
|
||||
if err := v.ValidateURL(p.URL, "url"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Validate status (enum)
|
||||
if err := v.ValidateEnum(p.Status, "status", AllowedPageStatuses); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Validate post type (enum)
|
||||
if err := v.ValidateEnum(p.PostType, "post_type", AllowedPostTypes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Validate author
|
||||
author, err := v.ValidateAndSanitizeString(p.Author, "author", 1, 255)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Author = author
|
||||
if err := v.ValidateNoHTML(p.Author, "author"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SyncRequest represents the sync pages request
|
||||
type SyncRequest struct {
|
||||
Pages []SyncPageInput `json:"pages"`
|
||||
}
|
||||
|
||||
// Validate validates the sync request
|
||||
func (r *SyncRequest) Validate() error {
|
||||
// Check pages array is not empty
|
||||
if len(r.Pages) == 0 {
|
||||
return fmt.Errorf("pages: array cannot be empty")
|
||||
}
|
||||
|
||||
// Validate maximum number of pages in a single request
|
||||
if len(r.Pages) > 1000 {
|
||||
return fmt.Errorf("pages: cannot sync more than 1000 pages at once")
|
||||
}
|
||||
|
||||
// Validate each page
|
||||
for i, page := range r.Pages {
|
||||
if err := page.Validate(); err != nil {
|
||||
return fmt.Errorf("pages[%d]: %w", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SyncResponse represents the sync pages response
|
||||
type SyncResponse struct {
|
||||
SyncedCount int `json:"synced_count"`
|
||||
IndexedCount int `json:"indexed_count"`
|
||||
FailedPages []string `json:"failed_pages,omitempty"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue