Try implementing keeping old server jars
All checks were successful
Build & Test / nix-build (push) Successful in 1m46s
All checks were successful
Build & Test / nix-build (push) Successful in 1m46s
This commit is contained in:
parent
02c05122d7
commit
d6ea25a64e
@ -43,19 +43,35 @@ defmodule Amethyst.DataGenerator do
|
||||
end
|
||||
end
|
||||
|
||||
@spec download_server_jar(:latest | String.t(), path) :: {:ok, path} | {:error, term} when path: String.t()
|
||||
def download_server_jar(version, path) do
|
||||
@spec get_server_jar(:latest | String.t(), path) :: {:ok, path} | {:error, term} when path: String.t()
|
||||
def get_server_jar(version, path) do
|
||||
case get_version_meta(version) do
|
||||
{:ok, %{"downloads" => %{"server" => %{"url" => url, "sha1" => sha1}}}} ->
|
||||
Logger.debug("Downloading server jar from #{url}, sha1: #{sha1}")
|
||||
case Req.get(url, into: File.stream!(path)) do
|
||||
{:ok, _} -> {:ok, path}
|
||||
{:error, err} -> {:error, err}
|
||||
# Check if the file already exists and has the right hash
|
||||
Logger.debug("Checking if server jar exists at #{path} with hash #{sha1}")
|
||||
case File.read(path) do
|
||||
{:ok, data} ->
|
||||
if :crypto.hash(:sha, data) == sha1 do
|
||||
Logger.debug("Using cached server jar at #{path}")
|
||||
{:ok, path}
|
||||
else
|
||||
Logger.debug("Mismatched hash, redownloading server jar")
|
||||
download_jar(url, path)
|
||||
end
|
||||
{:error, _} -> download_jar(url, path)
|
||||
end
|
||||
{:error, err} -> {:error, err}
|
||||
end
|
||||
end
|
||||
|
||||
defp download_jar(url, path) do
|
||||
Logger.debug("Downloading server jar from #{url}")
|
||||
case Req.get(url, into: File.stream!(path)) do
|
||||
{:ok, _} -> {:ok, path}
|
||||
{:error, err} -> {:error, err}
|
||||
end
|
||||
end
|
||||
|
||||
@spec get_latest_version() ::
|
||||
{:error, %{:__exception__ => true, :__struct__ => atom(), optional(atom()) => any()}}
|
||||
| {:ok, any()}
|
||||
|
Loading…
Reference in New Issue
Block a user