Skip to content

Commit

Permalink
style: address PR comments
Browse files Browse the repository at this point in the history
- reduce blank lines for single-line `def`s
- style: direct use `:notifyURL`
- pipline funs calling
  • Loading branch information
Wade Xing committed Jul 19, 2017
1 parent 19a2b7a commit 93d1c0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
9 changes: 2 additions & 7 deletions lib/qiniu/chunk_upload.ex
Expand Up @@ -19,18 +19,17 @@ defmodule Qiniu.ChunkUpload do
* `:mimeType` - file name in a Qiniu bucket
"""
def chunk_upload(put_policy, local_file, opts \\ [])

def chunk_upload(%PutPolicy{}=put_policy, local_file, opts) do
uptoken = Qiniu.Auth.generate_uptoken(put_policy)
chunk_upload(uptoken, local_file, opts)
end

def chunk_upload(uptoken, local_file, opts) when is_binary(uptoken) do
case File.stat(local_file) do
{:ok, %{size: file_size, type: :regular}} ->
File.stream!(local_file, [], @default_block_size)
|> Stream.map(fn(blk) ->
chop(blk, @default_chunk_size)
blk
|> chop(@default_chunk_size)
|> send_block(byte_size(blk), opts, uptoken)
end)
|> Enum.join(",")
Expand All @@ -53,7 +52,6 @@ defmodule Qiniu.ChunkUpload do
end

def send_chunk([], _offset, ctx, _uptoken, _host), do: ctx

def send_chunk([chunk | rest], offset, ctx, uptoken, host) do
case bput(chunk, offset, ctx, uptoken, host) do
%HTTPoison.Response{body: %{"ctx" => ctx, "host" => host}} ->
Expand All @@ -75,7 +73,6 @@ defmodule Qiniu.ChunkUpload do
<<chunk :: binary-size(chunk_size), rest :: binary>> = chunks
chop(rest, chunk_size, [chunk | acc])
end

def chop(chunks, _size, acc) do
Enum.reverse([chunks | acc])
end
Expand Down Expand Up @@ -118,7 +115,6 @@ defmodule Qiniu.ChunkUpload do
end

def post_with_retry(url, body, headers, retry_limit \\ 1)

def post_with_retry(url, body, headers, retry_limit) when retry_limit > 0 do
try do
Qiniu.HTTP.post(url, body, headers)
Expand All @@ -130,7 +126,6 @@ defmodule Qiniu.ChunkUpload do
end
end
end

def post_with_retry(url, body, headers, _retry_limit) do
Qiniu.HTTP.post(url, body, headers)
end
Expand Down
9 changes: 4 additions & 5 deletions lib/qiniu/fop/av.ex
Expand Up @@ -6,17 +6,17 @@ defmodule Qiniu.Fop.AV do
alias Qiniu.HTTP

def avthumb(bucket_name, key, opts \\ []) do
query_opts = opts |> Keyword.take([:"notifyURL", :pipeline]) |> Enum.into(%{})
fog_opts = opts |> Keyword.delete(:"notifyURL") |> Keyword.delete(:pipeline)
query_opts = opts |> Keyword.take([:notifyURL, :pipeline]) |> Enum.into(%{})
fog_opts = opts |> Keyword.delete(:notifyURL) |> Keyword.delete(:pipeline)

body = URI.encode_query(
body =
%{
bucket: bucket_name,
key: key,
fops: trans_fops(fog_opts),
}
|> Map.merge(query_opts)
)
|> URI.encode_query

HTTP.auth_post("#{Qiniu.config[:api_host]}/pfop/", body)
end
Expand All @@ -37,7 +37,6 @@ defmodule Qiniu.Fop.AV do
end
end)
end

defp trans_fop(:saveas, bucket_name_key) do
"|saveas/" <> Base.url_encode64(bucket_name_key)
end
Expand Down

0 comments on commit 93d1c0b

Please sign in to comment.