aboutsummaryrefslogtreecommitdiff
path: root/shard
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-11-05 16:03:56 +0100
committerAlex Auvolat <alex@adnab.me>2018-11-05 16:03:56 +0100
commit0e5b82f3348508eb7f4291a08722522a49edd752 (patch)
tree40bf4c9aa8d5b1920369c176665f5a4e7285de55 /shard
parent0b27af3dab56b667b50fd80590cdfd9df0feffbd (diff)
downloadshard-0e5b82f3348508eb7f4291a08722522a49edd752.tar.gz
shard-0e5b82f3348508eb7f4291a08722522a49edd752.zip
Facilitate file sending in chat0.0.4
Diffstat (limited to 'shard')
-rw-r--r--shard/lib/cli/cli.ex19
1 files changed, 19 insertions, 0 deletions
diff --git a/shard/lib/cli/cli.ex b/shard/lib/cli/cli.ex
index d454a0b..380282d 100644
--- a/shard/lib/cli/cli.ex
+++ b/shard/lib/cli/cli.ex
@@ -170,6 +170,25 @@ defmodule SCLI do
state
end
+ defp handle_command(state, ["send_file", path]) do
+ {mime_type, 0} = System.cmd("file", ["-b", "--mime-type", path])
+ mime_type = String.trim mime_type
+ IO.puts("Guessed mime type: #{mime_type}")
+ handle_command(state, ["send_file", path, mime_type])
+ end
+
+ defp handle_command(state, ["send_file", path, mime_type]) do
+ if state.room_pid != nil do
+ {:ok, m, _} = SApp.File.create(path, mime_type)
+ uri = ShardURI.from_manifest(m)
+ IO.puts("sending URI: #{uri}")
+ SApp.Chat.chat_send(state.room_pid, state.pk, uri)
+ else
+ IO.puts("Not in a chat room!")
+ end
+ state
+ end
+
defp handle_command(state, _cmd) do
IO.puts "Invalid command"
state