Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
This commit is contained in:
1 parent
9dd425f765
commit
d5d21b7841
302 files changed
+20037
-3492
No files matched your search
@@ -1,225 +1,20 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
import "pageswiki/internal/kunstzeal"
|
||||
|
||||
type projectionDelivery string
|
||||
type projectionDelivery = kunstzeal.Delivery
|
||||
type contentDescriptor = kunstzeal.Descriptor
|
||||
type projectionAdapter = kunstzeal.Adapter
|
||||
|
||||
const (
|
||||
deliveryHTML projectionDelivery = "html"
|
||||
deliveryText projectionDelivery = "text"
|
||||
deliveryRawMedia projectionDelivery = "raw-media"
|
||||
deliveryRawFrame projectionDelivery = "raw-frame"
|
||||
deliveryDownload projectionDelivery = "download"
|
||||
deliveryHTML = kunstzeal.DeliveryHTML
|
||||
deliveryText = kunstzeal.DeliveryText
|
||||
deliveryRawMedia = kunstzeal.DeliveryRawMedia
|
||||
deliveryRawFrame = kunstzeal.DeliveryRawFrame
|
||||
deliveryDownload = kunstzeal.DeliveryDownload
|
||||
inlineTextWindowThreshold = kunstzeal.InlineTextWindowThreshold
|
||||
)
|
||||
|
||||
type contentDescriptor struct {
|
||||
MediaType string
|
||||
Filename string
|
||||
SizeBytes int64
|
||||
}
|
||||
|
||||
type projectionAdapter struct {
|
||||
ID string
|
||||
Kind string
|
||||
Delivery projectionDelivery
|
||||
NeedsText bool
|
||||
WindowableText bool
|
||||
Match func(contentDescriptor) bool
|
||||
}
|
||||
|
||||
const inlineTextWindowThreshold = int64(2 << 20)
|
||||
|
||||
var projectionAdapters = []projectionAdapter{
|
||||
{
|
||||
ID: "html",
|
||||
Kind: "html",
|
||||
Delivery: deliveryHTML,
|
||||
Match: mediaTypes("text/html"),
|
||||
},
|
||||
{
|
||||
ID: "excalidraw",
|
||||
Kind: "excalidraw",
|
||||
Delivery: deliveryText,
|
||||
NeedsText: true,
|
||||
WindowableText: true,
|
||||
Match: extensions(".excalidraw"),
|
||||
},
|
||||
{
|
||||
ID: "csv",
|
||||
Kind: "csv",
|
||||
Delivery: deliveryText,
|
||||
NeedsText: true,
|
||||
WindowableText: true,
|
||||
Match: matchAny(
|
||||
mediaTypes("text/csv", "application/csv"),
|
||||
extensions(".csv"),
|
||||
),
|
||||
},
|
||||
{
|
||||
ID: "archive",
|
||||
Kind: "archive",
|
||||
Delivery: deliveryDownload,
|
||||
Match: matchAny(
|
||||
mediaTypes(
|
||||
"application/zip", "application/x-zip-compressed",
|
||||
"application/x-rar-compressed", "application/vnd.rar",
|
||||
"application/x-7z-compressed", "application/x-tar",
|
||||
"application/gzip", "application/x-xz",
|
||||
),
|
||||
extensions(".zip", ".rar", ".7z", ".tar", ".gz", ".tgz", ".xz", ".txz"),
|
||||
),
|
||||
},
|
||||
{
|
||||
ID: "debian-package",
|
||||
Kind: "metadata",
|
||||
Delivery: deliveryDownload,
|
||||
Match: matchAny(
|
||||
mediaTypes(
|
||||
"application/vnd.debian.binary-package",
|
||||
"application/x-debian-package",
|
||||
),
|
||||
extensions(".deb"),
|
||||
),
|
||||
},
|
||||
{
|
||||
ID: "eml",
|
||||
Kind: "email",
|
||||
Delivery: deliveryText,
|
||||
Match: matchAny(
|
||||
mediaTypes("message/rfc822"),
|
||||
extensions(".eml"),
|
||||
),
|
||||
},
|
||||
{
|
||||
ID: "pe",
|
||||
Kind: "metadata",
|
||||
Delivery: deliveryDownload,
|
||||
Match: extensions(".exe", ".dll", ".sys"),
|
||||
},
|
||||
{
|
||||
ID: "json",
|
||||
Kind: "json",
|
||||
Delivery: deliveryText,
|
||||
WindowableText: true,
|
||||
Match: matchAny(mediaTypes("application/json", "application/ld+json"), extensions(".json", ".jsonl")),
|
||||
},
|
||||
{
|
||||
ID: "text",
|
||||
Kind: "code",
|
||||
Delivery: deliveryText,
|
||||
NeedsText: true,
|
||||
WindowableText: true,
|
||||
Match: textMediaType,
|
||||
},
|
||||
{
|
||||
ID: "image",
|
||||
Kind: "image",
|
||||
Delivery: deliveryRawMedia,
|
||||
Match: matchAny(
|
||||
mediaTypePrefix("image/"),
|
||||
extensions(".png", ".jpg", ".jpeg", ".gif", ".webp", ".avif", ".svg"),
|
||||
),
|
||||
},
|
||||
{
|
||||
ID: "audio",
|
||||
Kind: "audio",
|
||||
Delivery: deliveryRawMedia,
|
||||
Match: matchAny(
|
||||
mediaTypePrefix("audio/"),
|
||||
extensions(".mp3", ".flac", ".wav", ".ogg", ".m4a", ".aac", ".opus"),
|
||||
),
|
||||
},
|
||||
{
|
||||
ID: "video",
|
||||
Kind: "video",
|
||||
Delivery: deliveryRawMedia,
|
||||
Match: matchAny(
|
||||
mediaTypePrefix("video/"),
|
||||
extensions(".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"),
|
||||
),
|
||||
},
|
||||
{
|
||||
ID: "pdf",
|
||||
Kind: "pdf",
|
||||
Delivery: deliveryRawFrame,
|
||||
Match: matchAny(
|
||||
mediaTypes("application/pdf"),
|
||||
extensions(".pdf"),
|
||||
),
|
||||
},
|
||||
{
|
||||
ID: "download",
|
||||
Kind: "download",
|
||||
Delivery: deliveryDownload,
|
||||
Match: func(contentDescriptor) bool { return true },
|
||||
},
|
||||
}
|
||||
|
||||
func selectProjectionAdapter(descriptor contentDescriptor) projectionAdapter {
|
||||
for _, adapter := range projectionAdapters {
|
||||
if adapter.Match(descriptor) {
|
||||
return adapter
|
||||
}
|
||||
}
|
||||
return projectionAdapters[len(projectionAdapters)-1]
|
||||
}
|
||||
|
||||
func mediaTypes(types ...string) func(contentDescriptor) bool {
|
||||
return func(descriptor contentDescriptor) bool {
|
||||
for _, candidate := range types {
|
||||
if descriptor.MediaType == candidate {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func mediaTypePrefix(prefix string) func(contentDescriptor) bool {
|
||||
return func(descriptor contentDescriptor) bool {
|
||||
return strings.HasPrefix(descriptor.MediaType, prefix)
|
||||
}
|
||||
}
|
||||
|
||||
func extensions(values ...string) func(contentDescriptor) bool {
|
||||
return func(descriptor contentDescriptor) bool {
|
||||
extension := strings.ToLower(filepath.Ext(descriptor.Filename))
|
||||
for _, candidate := range values {
|
||||
if extension == candidate {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func matchAny(matchers ...func(contentDescriptor) bool) func(contentDescriptor) bool {
|
||||
return func(descriptor contentDescriptor) bool {
|
||||
for _, matcher := range matchers {
|
||||
if matcher(descriptor) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func textMediaType(descriptor contentDescriptor) bool {
|
||||
switch descriptor.MediaType {
|
||||
case "application/json",
|
||||
"application/xml",
|
||||
"application/javascript",
|
||||
"application/x-javascript",
|
||||
"application/x-sh",
|
||||
"application/x-shellscript",
|
||||
"application/x-yaml",
|
||||
"application/yaml",
|
||||
"application/toml":
|
||||
return true
|
||||
default:
|
||||
return strings.HasPrefix(descriptor.MediaType, "text/")
|
||||
}
|
||||
return kunstzeal.SelectAdapter(descriptor)
|
||||
}
|
||||
Reference in new issue
Block a user