feat: inline image previews, revert, and the official icon
- sent images keep a local copy and render as rounded thumbnails in the message, surviving later page reloads - a prompt's menu can revert it and everything after it: confirm, then stage and commit the server-side revert - the app icon is OpenChamber's own (packages/mobile/assets/icon-only.png) - document a terminal assessment (native view vs Go ANSI vs xterm.js in a WebView) for the next decision Bump version to 0.2.1 (build 15).
This commit is contained in:
1 parent
72119b73e8
commit
dc3730eba7
9 files changed
+221
-22
No files matched your search
@@ -7,10 +7,12 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/egoist/asuka/colors"
|
||||
"github.com/egoist/asuka/fonts"
|
||||
"github.com/egoist/asuka/sdk/device"
|
||||
"github.com/egoist/asuka/sdk/store"
|
||||
"github.com/egoist/asuka/signal"
|
||||
"github.com/egoist/asuka/ui"
|
||||
"github.com/openchamber/openchamber-native/internal/ocapi"
|
||||
@@ -23,10 +25,11 @@ const maxAttachmentBytes = 10 << 20
|
||||
|
||||
// attachment is a picked file waiting to ride with the next prompt.
|
||||
type attachment struct {
|
||||
Name string
|
||||
MIME string
|
||||
DataURL string
|
||||
Size int64
|
||||
Name string
|
||||
MIME string
|
||||
DataURL string
|
||||
Size int64
|
||||
LocalPath string // a copy in the app's data dir, for inline preview
|
||||
}
|
||||
|
||||
func (ch *chat) attachMenu() {
|
||||
@@ -105,11 +108,15 @@ func (ch *chat) readAttachment(path, name, mimeType string) {
|
||||
return
|
||||
}
|
||||
url := "data:" + mimeType + ";base64," + base64.StdEncoding.EncodeToString(data)
|
||||
kept := ""
|
||||
if strings.HasPrefix(mimeType, "image/") {
|
||||
kept = keepImage(path, name)
|
||||
}
|
||||
ui.Post(func() {
|
||||
list := ch.attachments.Peek()
|
||||
next := make([]attachment, len(list), len(list)+1)
|
||||
copy(next, list)
|
||||
next = append(next, attachment{Name: name, MIME: mimeType, DataURL: url, Size: info.Size()})
|
||||
next = append(next, attachment{Name: name, MIME: mimeType, DataURL: url, Size: info.Size(), LocalPath: kept})
|
||||
ch.attachments.Set(next)
|
||||
})
|
||||
}()
|
||||
@@ -172,6 +179,40 @@ func (ch *chat) optimisticFiles() []ocapi.FileAttachment {
|
||||
return out
|
||||
}
|
||||
|
||||
// keepImage copies a picked image into the app's data dir so the sent
|
||||
// message can show it inline after a reload clears the caches copy.
|
||||
func keepImage(source, name string) string {
|
||||
dir := filepath.Join(store.Dir(), "attachments")
|
||||
_ = os.MkdirAll(dir, 0o700)
|
||||
dst := filepath.Join(dir, fmt.Sprintf("%d-%s", time.Now().UnixNano(), sanitizeName(name)))
|
||||
if err := copyFile(source, dst); err != nil {
|
||||
return ""
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
func sanitizeName(name string) string {
|
||||
clean := strings.Map(func(r rune) rune {
|
||||
switch r {
|
||||
case '/', '\\', ':', '*', '?', '"', '<', '>', '|':
|
||||
return '_'
|
||||
}
|
||||
return r
|
||||
}, name)
|
||||
if clean == "" {
|
||||
return "image"
|
||||
}
|
||||
return clean
|
||||
}
|
||||
|
||||
func copyFile(src, dst string) error {
|
||||
data, err := os.ReadFile(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(dst, data, 0o600)
|
||||
}
|
||||
|
||||
func humanSize(bytes int64) string {
|
||||
switch {
|
||||
case bytes >= 1<<20:
|
||||
|
||||
Reference in new issue
Block a user