Add file upload functionality to the agent. Implement API endpoint for uploading files, including validation and error handling. Update web interface to support file selection and display upload status. Enhance input handling with configurable key delay for text input.

This commit is contained in:
2026-08-28 12:52:26 +03:00
parent d7274f34e0
commit fe560c6a65
16 changed files with 408 additions and 24 deletions
+42 -9
View File
@@ -5,8 +5,11 @@ import (
"runtime"
"strings"
"syscall"
"time"
"unicode/utf16"
"unsafe"
"tea.chunkbyte.com/kato/go-worm/lib/config"
)
const (
@@ -98,10 +101,11 @@ func Click(x, y int, button string) error {
return nil
}
func TypeText(text string) error {
func TypeText(text string, delayMs int) error {
if text == "" {
return ErrEmptyText
}
delayMs = resolveKeyDelay(delayMs)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@@ -109,15 +113,44 @@ func TypeText(text string) error {
return err
}
units := utf16.Encode([]rune(text))
inputs := make([]keybdInput, 0, len(units)*2)
for _, unit := range units {
inputs = append(inputs,
keybdInput{Type: inputKeyboard, Scan: unit, Flags: keyeventfUnicode},
keybdInput{Type: inputKeyboard, Scan: unit, Flags: keyeventfUnicode | keyeventfKeyup},
)
runes := []rune(text)
for i, r := range runes {
if err := sendUnicodeRune(r); err != nil {
return err
}
if i < len(runes)-1 && delayMs > 0 {
time.Sleep(time.Duration(delayMs) * time.Millisecond)
}
}
return sendKeys(inputs)
return nil
}
func resolveKeyDelay(ms int) int {
if ms < 0 {
return 0
}
if ms > config.MaxKeyDelayMs {
return config.MaxKeyDelayMs
}
return ms
}
// ResolveKeyDelay returns the effective per-key delay for API responses.
func ResolveKeyDelay(ms int) int {
return resolveKeyDelay(ms)
}
func sendUnicodeRune(r rune) error {
for _, unit := range utf16.Encode([]rune{r}) {
inputs := []keybdInput{
{Type: inputKeyboard, Scan: unit, Flags: keyeventfUnicode},
{Type: inputKeyboard, Scan: unit, Flags: keyeventfUnicode | keyeventfKeyup},
}
if err := sendKeys(inputs); err != nil {
return err
}
}
return nil
}
func attachInputDesktop() error {