feat: add bounded binary file writes

This commit is contained in:
2026-06-29 10:12:26 +08:00
parent df4538532f
commit fe91784a8e
12 changed files with 240 additions and 20 deletions
+8 -6
View File
@@ -68,10 +68,11 @@ type CaptureLink struct {
}
type CaptureFile struct {
Name string `json:"name"`
Mime string `json:"mime"`
Size int64 `json:"size"`
Text string `json:"text"`
Name string `json:"name"`
Mime string `json:"mime"`
Size int64 `json:"size"`
Text string `json:"text"`
DataBase64 string `json:"dataBase64"`
}
type CaptureBrowser struct {
@@ -232,8 +233,8 @@ func (p CapturePayload) Validate() error {
if p.Kind == "file" && (p.File == nil || strings.TrimSpace(p.File.Name) == "") {
return fmt.Errorf("file.name is required")
}
if p.Kind == "file" && (p.File == nil || p.File.Text == "") {
return fmt.Errorf("file.text is required")
if p.Kind == "file" && (p.File == nil || (p.File.Text == "" && strings.TrimSpace(p.File.DataBase64) == "")) {
return fmt.Errorf("file.text or file.dataBase64 is required")
}
return nil
}
@@ -269,6 +270,7 @@ func (p CapturePayload) EventPayload() map[string]interface{} {
result["fileMime"] = strings.TrimSpace(p.File.Mime)
result["fileSize"] = p.File.Size
result["fileText"] = p.File.Text
result["fileDataBase64"] = strings.TrimSpace(p.File.DataBase64)
}
return result
}
@@ -108,7 +108,8 @@ func TestReceiverAcceptsFileCaptureAndPublishesEvent(t *testing.T) {
"name": "notes.txt",
"mime": "text/plain",
"size": 11,
"text": "hello file"
"text": "hello file",
"dataBase64": "aGVsbG8gZmlsZQ=="
},
"browser": {
"name": "Firefox"
@@ -146,6 +147,9 @@ func TestReceiverAcceptsFileCaptureAndPublishesEvent(t *testing.T) {
if payload["fileText"] != "hello file" {
t.Fatalf("payload fileText = %v, want hello file", payload["fileText"])
}
if payload["fileDataBase64"] != "aGVsbG8gZmlsZQ==" {
t.Fatalf("payload fileDataBase64 = %v, want aGVsbG8gZmlsZQ==", payload["fileDataBase64"])
}
}
func TestReceiverAnnotatesCaptureWithCurrentWorkspace(t *testing.T) {