From 0e5b82f3348508eb7f4291a08722522a49edd752 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 5 Nov 2018 16:03:56 +0100 Subject: Facilitate file sending in chat --- shard/lib/cli/cli.ex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'shard') 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 -- cgit v1.2.3