Compare commits

...

3 Commits

Author SHA1 Message Date
Peter Steinberger
12f3d0dc6c feat: add send file filename override (#7) (thanks @plattenschieber) 2026-01-23 01:52:54 +00:00
Jeronim
256bbb5395 fix: use filePath for MIME detection instead of display name
Keep MIME detection independent of --filename override.
The display name should only affect what the recipient sees,
not how the file is handled (image/video/document routing).
2026-01-23 01:52:38 +00:00
Jeronim
c79cbef7a6 feat: add --filename flag to override display name when sending files
When sending files via 'wacli send file', the displayed filename was
derived from the file path using filepath.Base(). This caused issues
when the file was stored in a temporary location with a non-descriptive
name (e.g., '/tmp/abc123' would display as 'abc123').

This commit adds a new --filename flag that allows callers to explicitly
specify the display name for the file, independent of the actual file path.
If --filename is not provided, the behavior falls back to using the
basename of the --file path.

Example usage:
  wacli send file --to +1234567890 --file /tmp/abc123 --filename report.pdf
2026-01-23 01:52:38 +00:00
3 changed files with 14 additions and 4 deletions

View File

@ -10,6 +10,10 @@
- Build: preserve existing `CGO_CFLAGS` when adding GCC 15+ workaround. (#8 — thanks @ramarivera)
### Added
- Send: `wacli send file --filename` to override display name for uploads. (#7 — thanks @plattenschieber)
## 0.1.0 - 2026-01-01
### Added

View File

@ -20,16 +20,20 @@ import (
func sendFile(ctx context.Context, a interface {
WA() app.WAClient
DB() *store.DB
}, to types.JID, filePath, caption, mimeOverride string) (string, map[string]string, error) {
}, to types.JID, filePath, filename, caption, mimeOverride string) (string, map[string]string, error) {
data, err := os.ReadFile(filePath)
if err != nil {
return "", nil, err
}
name := filepath.Base(filePath)
name := strings.TrimSpace(filename)
if name == "" {
name = filepath.Base(filePath)
}
mimeType := strings.TrimSpace(mimeOverride)
if mimeType == "" {
mimeType = mime.TypeByExtension(strings.ToLower(filepath.Ext(name)))
// Use filePath for MIME detection, not the display name override
mimeType = mime.TypeByExtension(strings.ToLower(filepath.Ext(filePath)))
}
if mimeType == "" {
sniff := data

View File

@ -13,6 +13,7 @@ import (
func newSendFileCmd(flags *rootFlags) *cobra.Command {
var to string
var filePath string
var filename string
var caption string
var mimeOverride string
@ -45,7 +46,7 @@ func newSendFileCmd(flags *rootFlags) *cobra.Command {
return err
}
msgID, meta, err := sendFile(ctx, a, toJID, filePath, caption, mimeOverride)
msgID, meta, err := sendFile(ctx, a, toJID, filePath, filename, caption, mimeOverride)
if err != nil {
return err
}
@ -65,6 +66,7 @@ func newSendFileCmd(flags *rootFlags) *cobra.Command {
cmd.Flags().StringVar(&to, "to", "", "recipient phone number or JID")
cmd.Flags().StringVar(&filePath, "file", "", "path to file")
cmd.Flags().StringVar(&filename, "filename", "", "display name for the file (defaults to basename of --file)")
cmd.Flags().StringVar(&caption, "caption", "", "caption (images/videos/documents)")
cmd.Flags().StringVar(&mimeOverride, "mime", "", "override detected mime type")
return cmd