Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
This commit is contained in:
1 parent
288e6e94ac
commit
c1175d389f
699 files changed
+110197
-4117
No files matched your search
@@ -0,0 +1,173 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"pageswiki/internal/store"
|
||||
)
|
||||
|
||||
func (s *Server) windowedContentViewForRequest(r *http.Request, objectUUID, semanticPath string) (contentView, bool, error) {
|
||||
metadata, err := s.latestRevisionMetadataForRequest(r, objectUUID)
|
||||
if err != nil || metadata.UUID == "" {
|
||||
return contentView{}, false, err
|
||||
}
|
||||
size, err := s.store.DocumentSize(metadata.DocumentHash)
|
||||
if err != nil {
|
||||
return contentView{}, false, nil
|
||||
}
|
||||
mediaType := strings.ToLower(strings.TrimSpace(strings.Split(metadata.ContentType, ";")[0]))
|
||||
adapter := selectProjectionAdapter(contentDescriptor{MediaType: mediaType, Filename: metadata.Filename, SizeBytes: size})
|
||||
if adapter.ID == "pdf" || (adapter.ID == "archive" && !strings.EqualFold(filepath.Ext(metadata.Filename), ".zip")) {
|
||||
view := revisionContentView(metadata, semanticPath)
|
||||
view.SizeBytes = size
|
||||
view.RawURL = rawProjectionURL("rev:" + metadata.UUID)
|
||||
s.applyMetadataProjection(&view, semanticPath)
|
||||
return view, true, nil
|
||||
}
|
||||
if size <= inlineTextWindowThreshold || !adapter.WindowableText {
|
||||
return contentView{}, false, nil
|
||||
}
|
||||
window, err := s.store.ReadDocumentWindow(metadata.DocumentHash, 0, 128<<10)
|
||||
if err != nil {
|
||||
return contentView{}, false, err
|
||||
}
|
||||
view := revisionWindowedContentView(metadata, semanticPath, size, window.Data, window.NextOffset)
|
||||
view.RawURL = rawProjectionURL("rev:" + metadata.UUID)
|
||||
return view, true, nil
|
||||
}
|
||||
|
||||
type contentView struct {
|
||||
Kind string
|
||||
AdapterID string
|
||||
Delivery projectionDelivery
|
||||
ContentType string
|
||||
Filename string
|
||||
Text string
|
||||
RawURL string
|
||||
Language string
|
||||
SizeBytes int64
|
||||
Windowed bool
|
||||
ArchiveEntries []archiveEntryView
|
||||
ArchiveTruncated bool
|
||||
MetadataStatus string
|
||||
MetadataURL string
|
||||
Metadata []metadataView
|
||||
ParseError string
|
||||
EmailHTML bool
|
||||
PDFPages int
|
||||
CSVRows [][]string
|
||||
CSVTruncated bool
|
||||
ExcalidrawValid bool
|
||||
ExcalidrawElements int
|
||||
ObjectUUID string
|
||||
RevisionUUID string
|
||||
DocumentHash string
|
||||
WindowURL string
|
||||
NextOffset int64
|
||||
JSONURL string
|
||||
}
|
||||
|
||||
func revisionWindowedContentView(revision *store.Revision, semanticPath string, totalBytes int64, initial []byte, nextOffset int64) contentView {
|
||||
contentType := revision.ContentType
|
||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||
if err != nil {
|
||||
mediaType, contentType = "application/octet-stream", "application/octet-stream"
|
||||
}
|
||||
filename := strings.TrimSpace(revision.Filename)
|
||||
if filename == "" {
|
||||
filename = filepath.Base(semanticPath)
|
||||
}
|
||||
if mediaType == "application/octet-stream" {
|
||||
detected := detectRevisionText(initial, filename)
|
||||
if detected.ContentType != "" {
|
||||
contentType = detected.ContentType
|
||||
mediaType, _, _ = mime.ParseMediaType(contentType)
|
||||
}
|
||||
}
|
||||
adapter := selectProjectionAdapter(contentDescriptor{MediaType: strings.ToLower(mediaType), Filename: filename, SizeBytes: totalBytes})
|
||||
text, _, ok := decodeTextBytes(initial)
|
||||
if !ok {
|
||||
text = string(initial)
|
||||
}
|
||||
view := contentView{Kind: adapter.Kind, AdapterID: adapter.ID, Delivery: adapter.Delivery, ContentType: contentType, Filename: filename, Text: text, Language: codeLanguage(contentType, filename, text), SizeBytes: totalBytes, Windowed: true, ObjectUUID: revision.ObjectUUID, RevisionUUID: revision.UUID, DocumentHash: revision.DocumentHash, WindowURL: "/v/text/rev:" + revision.UUID, NextOffset: nextOffset}
|
||||
if adapter.ID == "json" {
|
||||
view.JSONURL = "/v/json/rev:" + revision.UUID
|
||||
view.Text = ""
|
||||
}
|
||||
if adapter.ID == "csv" {
|
||||
parseCSVView(&view, initial)
|
||||
view.CSVTruncated = view.CSVTruncated || nextOffset < totalBytes
|
||||
}
|
||||
if adapter.ID == "excalidraw" {
|
||||
// Large scenes keep bounded source delivery rather than parsing an
|
||||
// incomplete or unbounded graph during navigation.
|
||||
view.Kind = "code"
|
||||
view.Language = "json"
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
func revisionContentView(revision *store.Revision, semanticPath string) contentView {
|
||||
contentType := revision.ContentType
|
||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||
if err != nil {
|
||||
mediaType = "application/octet-stream"
|
||||
contentType = mediaType
|
||||
}
|
||||
mediaType = strings.ToLower(mediaType)
|
||||
filename := strings.TrimSpace(revision.Filename)
|
||||
if filename == "" {
|
||||
filename = filepath.Base(semanticPath)
|
||||
}
|
||||
view := contentView{
|
||||
ContentType: contentType,
|
||||
Filename: filename,
|
||||
SizeBytes: int64(len(revision.Body)),
|
||||
ObjectUUID: revision.ObjectUUID,
|
||||
RevisionUUID: revision.UUID,
|
||||
DocumentHash: revision.DocumentHash,
|
||||
}
|
||||
if mediaType == "application/octet-stream" {
|
||||
detected := detectRevisionText([]byte(revision.Body), filename)
|
||||
if detected.ContentType != "" {
|
||||
contentType = detected.ContentType
|
||||
mediaType, _, _ = mime.ParseMediaType(contentType)
|
||||
view.ContentType = contentType
|
||||
}
|
||||
if detected.IsText {
|
||||
view.Text = detected.Text
|
||||
}
|
||||
}
|
||||
adapter := selectProjectionAdapter(contentDescriptor{
|
||||
MediaType: mediaType,
|
||||
Filename: filename,
|
||||
SizeBytes: view.SizeBytes,
|
||||
})
|
||||
view.Kind = adapter.Kind
|
||||
view.AdapterID = adapter.ID
|
||||
view.Delivery = adapter.Delivery
|
||||
view.Windowed = adapter.WindowableText &&
|
||||
view.SizeBytes > inlineTextWindowThreshold
|
||||
if adapter.ID == "json" {
|
||||
view.JSONURL = "/v/json/rev:" + revision.UUID
|
||||
}
|
||||
|
||||
if adapter.NeedsText {
|
||||
if view.Text == "" {
|
||||
if decoded, _, ok := decodeTextBytes([]byte(revision.Body)); ok {
|
||||
view.Text = decoded
|
||||
} else {
|
||||
view.Text = revision.Body
|
||||
}
|
||||
}
|
||||
view.Language = codeLanguage(contentType, filename, view.Text)
|
||||
}
|
||||
structuredContentView(&view, []byte(revision.Body), semanticPath)
|
||||
if adapter.ID == "eml" {
|
||||
view.EmailHTML = extractEmailHTML([]byte(revision.Body)) != ""
|
||||
}
|
||||
return view
|
||||
}
|
||||
Reference in new issue
Block a user