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,225 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type projectionDelivery string
|
||||
|
||||
const (
|
||||
deliveryHTML projectionDelivery = "html"
|
||||
deliveryText projectionDelivery = "text"
|
||||
deliveryRawMedia projectionDelivery = "raw-media"
|
||||
deliveryRawFrame projectionDelivery = "raw-frame"
|
||||
deliveryDownload projectionDelivery = "download"
|
||||
)
|
||||
|
||||
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/")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user