Current section
7 Versions
Jump to
Current section
7 Versions
Compare versions
4
files changed
+31
additions
-31
deletions
| @@ -1,5 +1,8 @@ | |
| 1 1 | # WaffleAliyunOss |
| 2 2 | |
| 3 | + [](https://github.com/ug0/waffle_aliyun_oss/actions/workflows/publish.yml) |
| 4 | + [](https://github.com/ug0/waffle_aliyun_oss/actions/workflows/test.yml) |
| 5 | + |
| 3 6 | Aliyun OSS Storage for Waffle |
| 4 7 | |
| 5 8 | ## Installation |
| @@ -10,7 +13,7 @@ by adding `waffle_aliyun_oss` to your list of dependencies in `mix.exs`: | |
| 10 13 | ```elixir |
| 11 14 | def deps do |
| 12 15 | [ |
| 13 | - {:waffle_aliyun_oss, "~> 0.3.0"} |
| 16 | + {:waffle_aliyun_oss, "~> 0.4.0"} |
| 14 17 | ] |
| 15 18 | end |
| 16 19 | ``` |
| @@ -21,6 +24,7 @@ All configuration values are stored under the :waffle app key. E.g. | |
| 21 24 | config :waffle, |
| 22 25 | storage: Waffle.Storage.AliyunOss, |
| 23 26 | bucket: "some-bucket", |
| 27 | + region: "cn-hangzhou", |
| 24 28 | endpoint: "some.endpoint.com", |
| 25 29 | access_key_id: "ALIYUN_ACCESS_KEY_ID", |
| 26 30 | access_key_secret: "ALIYUN_ACCESS_KEY_SECRET" |
| @@ -30,6 +34,7 @@ You may also set the bucket from an environment variable: | |
| 30 34 | config :waffle, |
| 31 35 | storage: Waffle.Storage.AliyunOss, |
| 32 36 | bucket: {:system, "OSS_BUCKET"}, |
| 37 | + region: {:system, "OSS_REGION"}, |
| 33 38 | endpoint: {:system, "OSS_ENDPOINT"}, |
| 34 39 | access_key_id: {:system, "ALIYUN_ACCESS_KEY_ID"}, |
| 35 40 | access_key_secret: {:system, "ALIYUN_ACCESS_KEY_SECRET"} |
| @@ -1,23 +1,23 @@ | |
| 1 | - {<<"app">>,<<"waffle_aliyun_oss">>}. |
| 2 | - {<<"build_tools">>,[<<"mix">>]}. |
| 3 | - {<<"description">>,<<"Aliyun OSS Storage for Waffle">>}. |
| 4 | - {<<"elixir">>,<<"~> 1.10">>}. |
| 5 | - {<<"files">>, |
| 6 | - [<<"lib">>,<<"lib/application.ex">>,<<"lib/waffle">>, |
| 7 | - <<"lib/waffle/storage">>,<<"lib/waffle/storage/aliyun_oss.ex">>, |
| 8 | - <<".formatter.exs">>,<<"mix.exs">>,<<"README.md">>]}. |
| 9 | - {<<"licenses">>,[<<"MIT">>]}. |
| 10 1 | {<<"links">>,[{<<"GitHub">>,<<"https://github.com/ug0/waffle_aliyun_oss">>}]}. |
| 11 2 | {<<"name">>,<<"waffle_aliyun_oss">>}. |
| 3 | + {<<"version">>,<<"0.4.0">>}. |
| 4 | + {<<"description">>,<<"Aliyun OSS Storage for Waffle">>}. |
| 5 | + {<<"elixir">>,<<"~> 1.18">>}. |
| 6 | + {<<"app">>,<<"waffle_aliyun_oss">>}. |
| 7 | + {<<"licenses">>,[<<"MIT">>]}. |
| 12 8 | {<<"requirements">>, |
| 13 | - [[{<<"app">>,<<"waffle">>}, |
| 14 | - {<<"name">>,<<"waffle">>}, |
| 9 | + [[{<<"name">>,<<"waffle">>}, |
| 10 | + {<<"app">>,<<"waffle">>}, |
| 15 11 | {<<"optional">>,false}, |
| 16 | - {<<"repository">>,<<"hexpm">>}, |
| 17 | - {<<"requirement">>,<<"~> 1.0">>}], |
| 18 | - [{<<"app">>,<<"aliyun_oss">>}, |
| 19 | - {<<"name">>,<<"aliyun_oss">>}, |
| 12 | + {<<"requirement">>,<<"~> 1.1">>}, |
| 13 | + {<<"repository">>,<<"hexpm">>}], |
| 14 | + [{<<"name">>,<<"aliyun_oss">>}, |
| 15 | + {<<"app">>,<<"aliyun_oss">>}, |
| 20 16 | {<<"optional">>,false}, |
| 21 | - {<<"repository">>,<<"hexpm">>}, |
| 22 | - {<<"requirement">>,<<"~> 2.0">>}]]}. |
| 23 | - {<<"version">>,<<"0.3.0">>}. |
| 17 | + {<<"requirement">>,<<"~> 3.1.0">>}, |
| 18 | + {<<"repository">>,<<"hexpm">>}]]}. |
| 19 | + {<<"files">>, |
| 20 | + [<<"lib">>,<<"lib/waffle">>,<<"lib/waffle/storage">>, |
| 21 | + <<"lib/waffle/storage/aliyun_oss.ex">>,<<"lib/application.ex">>, |
| 22 | + <<".formatter.exs">>,<<"mix.exs">>,<<"README.md">>]}. |
| 23 | + {<<"build_tools">>,[<<"mix">>]}. |
| @@ -111,7 +111,7 @@ defmodule Waffle.Storage.AliyunOss do | |
| 111 111 | |
| 112 112 | # If the file is stored as a binary in-memory, send to OSS in a single request |
| 113 113 | defp do_put(file = %Waffle.File{binary: file_binary}, {oss_config, bucket, key, oss_options}) when is_binary(file_binary) do |
| 114 | - Aliyun.Oss.Object.put_object(oss_config, bucket, key, file_binary, req_headers(oss_options)) |
| 114 | + Aliyun.Oss.Object.put_object(oss_config, bucket, key, file_binary, headers: req_headers(oss_options)) |
| 115 115 | |> case do |
| 116 116 | {:ok, _res} -> {:ok, file.file_name} |
| 117 117 | {:error, error} -> {:error, error} |
| @@ -160,19 +160,13 @@ defmodule Waffle.Storage.AliyunOss do | |
| 160 160 | # fallback to default, if neither is present. |
| 161 161 | expires_in = Keyword.get(options, :expires_in) || Keyword.get(options, :expires_at) || @default_expiry_time |
| 162 162 | |
| 163 | - expires = |
| 164 | - DateTime.utc_now() |
| 165 | - |> DateTime.to_unix() |
| 166 | - |> Kernel.+(expires_in) |
| 167 | - |
| 168 163 | key = object_key(definition, version, file_and_scope) |
| 169 164 | bucket = oss_bucket(definition) |
| 170 165 | |
| 171 | - definition |> oss_config() |> Aliyun.Oss.Object.object_url(bucket, key, expires) |
| 166 | + definition |> oss_config() |> Aliyun.Oss.Object.object_url(bucket, key, expires_in) |
| 172 167 | end |
| 173 168 | |
| 174 169 | defp signed_url?(definition, version, file_and_scope, options) do |
| 175 | - definition.acl(version, file_and_scope) not in [:public_read, :public_read_write] or |
| 176 170 | Keyword.get(options, :signed, false) |
| 177 171 | end |
| 178 172 | |
| @@ -211,6 +205,7 @@ defmodule Waffle.Storage.AliyunOss do | |
| 211 205 | |
| 212 206 | defp oss_config(definition) do |
| 213 207 | Aliyun.Oss.Config.new!(%{ |
| 208 | + region: get_config_value(definition, :region), |
| 214 209 | endpoint: endpoint(definition), |
| 215 210 | access_key_id: get_config_value(definition, :access_key_id), |
| 216 211 | access_key_secret: get_config_value(definition, :access_key_secret) |
| @@ -4,8 +4,8 @@ defmodule WaffleAliyunOss.MixProject do | |
| 4 4 | def project do |
| 5 5 | [ |
| 6 6 | app: :waffle_aliyun_oss, |
| 7 | - version: "0.3.0", |
| 8 | - elixir: "~> 1.10", |
| 7 | + version: "0.4.0", |
| 8 | + elixir: "~> 1.18", |
| 9 9 | start_permanent: Mix.env() == :prod, |
| 10 10 | description: description(), |
| 11 11 | package: package(), |
| @@ -25,8 +25,8 @@ defmodule WaffleAliyunOss.MixProject do | |
| 25 25 | # Run "mix help deps" to learn about dependencies. |
| 26 26 | defp deps do |
| 27 27 | [ |
| 28 | - {:waffle, "~> 1.0"}, |
| 29 | - {:aliyun_oss, "~> 2.0"}, |
| 28 | + {:waffle, "~> 1.1"}, |
| 29 | + {:aliyun_oss, "~> 3.1.0"}, |
| 30 30 | {:ex_doc, "~> 0.20", only: :dev} |
| 31 31 | ] |
| 32 32 | end |