mirror of
https://github.com/Rudi9719/kbtui.git
synced 2026-03-22 07:37:23 +00:00
Feature: Allow relative paths for file upload
This commit is contained in:
@ -4,12 +4,14 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
command := Command{
|
command := Command{
|
||||||
Cmd: []string{"upload", "u"},
|
Cmd: []string{"upload", "u"},
|
||||||
Description: "$filePath $fileName - Upload file with optional name",
|
Description: "$filePath $fileName - Upload file from absolute path with optional name",
|
||||||
Help: "",
|
Help: "",
|
||||||
Exec: cmdUploadFile,
|
Exec: cmdUploadFile,
|
||||||
}
|
}
|
||||||
@ -19,6 +21,13 @@ func init() {
|
|||||||
|
|
||||||
func cmdUploadFile(cmd []string) {
|
func cmdUploadFile(cmd []string) {
|
||||||
filePath := cmd[1]
|
filePath := cmd[1]
|
||||||
|
if !strings.HasPrefix(filePath, "/") {
|
||||||
|
dir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
printToView("Feed", fmt.Sprintf("There was an error determining path %+v", err))
|
||||||
|
}
|
||||||
|
filePath = fmt.Sprintf("%s/%s", dir, filePath)
|
||||||
|
}
|
||||||
var fileName string
|
var fileName string
|
||||||
if len(cmd) == 3 {
|
if len(cmd) == 3 {
|
||||||
fileName = cmd[2]
|
fileName = cmd[2]
|
||||||
@ -28,7 +37,7 @@ func cmdUploadFile(cmd []string) {
|
|||||||
chat := k.NewChat(channel)
|
chat := k.NewChat(channel)
|
||||||
_, err := chat.Upload(fileName, filePath)
|
_, err := chat.Upload(fileName, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error uploading %s to %s", filePath, channel.Name))
|
printToView("Feed", fmt.Sprintf("There was an error uploading %s to %s\n%+v", filePath, channel.Name, err))
|
||||||
} else {
|
} else {
|
||||||
printToView("Feed", fmt.Sprintf("Uploaded %s to %s", filePath, channel.Name))
|
printToView("Feed", fmt.Sprintf("Uploaded %s to %s", filePath, channel.Name))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user