Skip to content

Commit fc784c4

Browse files
committed
Revert "mix format"
This reverts commit 76b5e1c.
1 parent a636aed commit fc784c4

File tree

13 files changed

+164
-247
lines changed

13 files changed

+164
-247
lines changed

lib/ret/discord_client.ex

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,21 @@ defmodule Ret.DiscordClient do
7676
{status, result} when status in [:commit, :ok] -> "#{result["nick"]}"
7777
end
7878

79-
nickname =
80-
if !nickname or nickname == "" do
81-
case Cachex.fetch(:discord_api, "/users/#{provider_account_id}") do
82-
{status, result} when status in [:commit, :ok] -> "#{result["global_name"]}"
83-
end
79+
nickname = if !nickname or nickname == "" do
80+
case Cachex.fetch(:discord_api, "/users/#{provider_account_id}") do
81+
{status, result} when status in [:commit, :ok] -> "#{result["global_name"]}"
82+
end
8483
else
8584
nickname
86-
end
85+
end
8786

88-
nickname =
89-
if !nickname or nickname == "" do
90-
case Cachex.fetch(:discord_api, "/users/#{provider_account_id}") do
91-
{status, result} when status in [:commit, :ok] -> "#{result["username"]}"
92-
end
87+
nickname = if !nickname or nickname == "" do
88+
case Cachex.fetch(:discord_api, "/users/#{provider_account_id}") do
89+
{status, result} when status in [:commit, :ok] -> "#{result["username"]}"
90+
end
9391
else
9492
nickname
95-
end
93+
end
9694
end
9795

9896
def fetch_community_identifier(%Ret.OAuthProvider{
@@ -171,21 +169,18 @@ defmodule Ret.DiscordClient do
171169
case Cachex.fetch(:discord_api, "/guilds/#{community_id}/roles") do
172170
{status, result} when status in [:commit, :ok] -> result |> Map.new(&{&1["id"], &1})
173171
end
174-
175-
# Note: Whether the bitfield values in guild_roles are represented as strings or integers is inconsistent (possibly based on what permissions the user has), so every time they're used they need to be checked and, if needed, converted to integers.
172+
# Note: Whether the bitfield values in guild_roles are represented as strings or integers is inconsistent (possibly based on what permissions the user has), so every time they're used they need to be checked and, if needed, converted to integers.
176173

177174
role_everyone = guild_roles[community_id]
178175
permissions = role_everyone["permissions"]
179176

180177
user_permissions = user_roles |> Enum.map(&guild_roles[&1]["permissions"])
181178

182-
permissions =
183-
user_permissions
184-
|> Enum.reduce(
185-
permissions,
186-
&(if(is_binary(&1), do: String.to_integer(&1), else: &1) |||
187-
if(is_binary(&2), do: String.to_integer(&2), else: &2))
188-
)
179+
permissions = user_permissions |>
180+
Enum.reduce(permissions, &(
181+
(if is_binary(&1), do: String.to_integer(&1), else: &1) |||
182+
(if is_binary(&2), do: String.to_integer(&2), else: &2)
183+
))
189184

190185
if (permissions &&& @administrator) == @administrator do
191186
@all
@@ -208,21 +203,15 @@ defmodule Ret.DiscordClient do
208203
|> Map.get("permission_overwrites")
209204
|> Map.new(&{&1["id"], &1})
210205
end
211-
212-
# Note: Whether the bitfield values in channel_overwrites are represented as strings or integers is inconsistent (possibly based on what permissions the user has), so every time they're used they need to be checked and, if needed, converted to integers.
206+
# Note: Whether the bitfield values in channel_overwrites are represented as strings or integers is inconsistent (possibly based on what permissions the user has), so every time they're used they need to be checked and, if needed, converted to integers.
213207

214208
overwrite_everyone = channel_overwrites[community_id]
215209

216210
permissions =
217211
if overwrite_everyone do
218212
(permissions &&&
219-
~~~if(is_binary(overwrite_everyone["deny"]),
220-
do: String.to_integer(overwrite_everyone["deny"]),
221-
else: overwrite_everyone["deny"]
222-
)) |||
223-
if is_binary(overwrite_everyone["allow"]),
224-
do: String.to_integer(overwrite_everyone["allow"]),
225-
else: overwrite_everyone["allow"]
213+
~~~(if is_binary(overwrite_everyone["deny"]), do: String.to_integer(overwrite_everyone["deny"]), else: overwrite_everyone["deny"])) |||
214+
(if is_binary(overwrite_everyone["allow"]), do: String.to_integer(overwrite_everyone["allow"]), else: overwrite_everyone["allow"])
226215
else
227216
permissions
228217
end
@@ -231,21 +220,14 @@ defmodule Ret.DiscordClient do
231220
user_permissions =
232221
user_roles |> Enum.map(&channel_overwrites[&1]) |> Enum.filter(&(&1 != nil))
233222

234-
allow =
235-
user_permissions
236-
|> Enum.reduce(
237-
@none,
238-
&(if(is_binary(&1["allow"]), do: String.to_integer(&1["allow"]), else: &1["allow"]) |||
239-
&2)
240-
)
241-
242-
deny =
243-
user_permissions
244-
|> Enum.reduce(
245-
@none,
246-
&(if(is_binary(&1["deny"]), do: String.to_integer(&1["deny"]), else: &1["deny"]) |||
247-
&2)
248-
)
223+
allow = user_permissions |> Enum.reduce(@none, &(
224+
(if is_binary(&1["allow"]), do: String.to_integer(&1["allow"]), else: &1["allow"]) |||
225+
&2
226+
))
227+
deny = user_permissions |> Enum.reduce(@none, &(
228+
(if is_binary(&1["deny"]), do: String.to_integer(&1["deny"]), else: &1["deny"]) |||
229+
&2
230+
))
249231

250232
permissions = (permissions &&& ~~~deny) ||| allow
251233

@@ -255,13 +237,8 @@ defmodule Ret.DiscordClient do
255237
permissions =
256238
if overwrite_member do
257239
(permissions &&&
258-
~~~if(is_binary(overwrite_member["deny"]),
259-
do: String.to_integer(overwrite_member["deny"]),
260-
else: overwrite_member["deny"]
261-
)) |||
262-
if is_binary(overwrite_member["allow"]),
263-
do: String.to_integer(overwrite_member["allow"]),
264-
else: overwrite_member["allow"]
240+
~~~(if is_binary(overwrite_member["deny"]), do: String.to_integer(overwrite_member["deny"]), else: overwrite_member["deny"])) |||
241+
(if is_binary(overwrite_member["allow"]), do: String.to_integer(overwrite_member["allow"]), else: overwrite_member["allow"])
265242
else
266243
permissions
267244
end

lib/ret/http_utils.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,18 @@ defmodule Ret.HttpUtils do
177177
end
178178

179179
def join_smart(enum) do
180-
Enum.reduce(enum, "", fn x, acc ->
181-
x =
182-
cond do
183-
!x -> nil
184-
is_binary(x) -> String.trim(x)
185-
true -> "#{x}"
186-
end
187-
180+
Enum.reduce(enum, "", fn(x, acc) ->
181+
x = cond do
182+
!x -> nil
183+
is_binary(x) -> String.trim(x)
184+
true -> "#{x}"
185+
end
188186
if x && x != "" do
189187
if acc && acc != "", do: acc <> " — " <> x, else: x
190188
else
191189
acc
192190
end
193191
end)
194192
end
193+
195194
end

lib/ret/media_resolver.ex

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -337,45 +337,43 @@ defmodule Ret.MediaResolver do
337337
end
338338

339339
defp resolve_non_video(
340-
%MediaResolverQuery{
341-
url: %URI{host: "api.icosa.gallery", path: "/v1/assets/" <> asset_id} = uri
342-
},
340+
%MediaResolverQuery{url: %URI{host: "api.icosa.gallery", path: "/v1/assets/" <> asset_id} = uri},
343341
"icosa.gallery"
344-
) do
345-
# Increment stat for the request
346-
Statix.increment("ret.media_resolver.icosa.requests")
347-
348-
# Make the API call to get the asset data
349-
payload =
350-
"https://api.icosa.gallery/v1/assets/#{asset_id}"
351-
# Assuming this function sends the request and handles retries
352-
|> retry_get_until_success()
353-
|> Map.get(:body)
354-
|> Poison.decode!()
355-
356-
# Create the meta information based on the payload
357-
meta =
358-
%{
359-
expected_content_type: "model/gltf",
360-
name: payload["displayName"],
361-
author: payload["authorName"],
362-
license: payload["license"]
363-
}
364-
365-
# Extract the GLTF2 format URL from the payload
366-
uri =
367-
payload["formats"]
368-
|> Enum.find(&(&1["formatType"] == "GLTF2"))
369-
|> Kernel.get_in(["root", "url"])
370-
|> URI.parse()
371-
372-
# Increment stat for successful resolution
373-
Statix.increment("ret.media_resolver.icosa.ok")
374-
375-
# Return the URI and meta data for further processing
376-
{:commit, resolved(uri, meta)}
342+
) do
343+
# Increment stat for the request
344+
Statix.increment("ret.media_resolver.icosa.requests")
345+
346+
# Make the API call to get the asset data
347+
payload =
348+
"https://api.icosa.gallery/v1/assets/#{asset_id}"
349+
|> retry_get_until_success() # Assuming this function sends the request and handles retries
350+
|> Map.get(:body)
351+
|> Poison.decode!()
352+
353+
# Create the meta information based on the payload
354+
meta =
355+
%{
356+
expected_content_type: "model/gltf",
357+
name: payload["displayName"],
358+
author: payload["authorName"],
359+
license: payload["license"]
360+
}
361+
362+
# Extract the GLTF2 format URL from the payload
363+
uri =
364+
payload["formats"]
365+
|> Enum.find(&(&1["formatType"] == "GLTF2"))
366+
|> Kernel.get_in(["root", "url"])
367+
|> URI.parse()
368+
369+
# Increment stat for successful resolution
370+
Statix.increment("ret.media_resolver.icosa.ok")
371+
372+
# Return the URI and meta data for further processing
373+
{:commit, resolved(uri, meta)}
377374
end
378375

376+
379377
defp resolve_non_video(
380378
%MediaResolverQuery{url: %URI{path: "/models/" <> model_id}} = query,
381379
"sketchfab.com" = root_host

lib/ret/media_search.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,7 @@ defmodule Ret.MediaSearch do
418418
end
419419
end
420420

421-
# Icosa does not currently require an API key
422-
def available?(:icosa), do: true
421+
def available?(:icosa), do: true # Icosa does not currently require an API key
423422
def available?(:bing_images), do: has_resolver_config?(:bing_search_api_key)
424423
def available?(:bing_videos), do: has_resolver_config?(:bing_search_api_key)
425424
def available?(:youtube_videos), do: has_resolver_config?(:youtube_api_key)
@@ -602,7 +601,6 @@ defmodule Ret.MediaSearch do
602601

603602
defp created_rooms_search(cursor, account_id, _query) do
604603
page_number = (cursor || "1") |> Integer.parse() |> elem(0)
605-
606604
ecto_query =
607605
from h in Hub,
608606
where: h.created_by_account_id == ^account_id,

lib/ret/scene.ex

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,38 +226,37 @@ defmodule Ret.Scene do
226226
model_owned_file: old_model_owned_file,
227227
account: account
228228
} = scene
229-
229+
230230
new_scene_owned_file =
231231
Storage.create_new_owned_file_with_replaced_string(
232232
old_scene_owned_file,
233233
account,
234234
old_domain_url,
235235
new_domain_url
236236
)
237-
237+
238238
{:ok, new_model_owned_file} =
239239
Storage.duplicate_and_transform(old_model_owned_file, account, fn glb_stream,
240240
_total_bytes ->
241241
GLTFUtils.replace_in_glb(glb_stream, old_domain_url, new_domain_url)
242242
end)
243-
243+
244244
scene
245245
|> change()
246246
|> put_change(:scene_owned_file_id, new_scene_owned_file.owned_file_id)
247247
|> put_change(:model_owned_file_id, new_model_owned_file.owned_file_id)
248248
|> Repo.update!()
249-
249+
250250
for old_owned_file <- [old_scene_owned_file, old_model_owned_file] do
251251
OwnedFile.set_inactive(old_owned_file)
252252
Storage.rm_files_for_owned_file(old_owned_file)
253253
Repo.delete(old_owned_file)
254254
end
255255
rescue
256-
e ->
256+
e ->
257257
IO.warn("Failed to process scene due to an error: #{inspect(e)}")
258258
end
259259
end)
260-
261260
:ok
262261
end)
263262
end

lib/ret/storage.ex

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ defmodule Ret.Storage do
288288
_account,
289289
_require_token
290290
) do
291-
{:ok, owned_file}
291+
{:ok, owned_file}
292292
end
293293

294294
# Promoting a stored file to being owned has two side effects: the file is moved
@@ -310,11 +310,7 @@ defmodule Ret.Storage do
310310
"promotion_token" => actual_promotion_token
311311
} <-
312312
File.read!(meta_file_path) |> Poison.decode!(),
313-
{:ok} <-
314-
if(require_token,
315-
do: check_promotion_token(actual_promotion_token, promotion_token),
316-
else: {:ok}
317-
),
313+
{:ok} <- (if require_token, do: check_promotion_token(actual_promotion_token, promotion_token), else: {:ok}),
318314
{:ok} <- check_blob_file_key(blob_file_path, key)
319315
) do
320316
owned_file_params = %{

lib/ret/storage_used.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ defmodule Ret.StorageUsed do
2929
line = lines |> String.split("\n") |> Enum.at(1)
3030

3131
{:ok, [_FS, _kb, used, _Avail], _RestStr} =
32-
:io_lib.fread(~c"~s~d~d~d", line |> to_charlist)
32+
:io_lib.fread('~s~d~d~d', line |> to_charlist)
3333

3434
{:ok, [{:storage_used, used}]}
3535

lib/ret_web/controllers/api/v1/media_search_controller.ex

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ defmodule RetWeb.Api.V1.MediaSearchController do
33
use Retry
44

55
def index(conn, %{"source" => source, "filter" => "created", "user" => user} = params)
6-
when source in ["rooms"] do
7-
account = conn |> Guardian.Plug.current_resource()
8-
9-
if account && account.account_id == String.to_integer(user) do
10-
{:commit, results} =
11-
%Ret.MediaSearchQuery{
12-
source: "rooms",
13-
cursor: params["cursor"] || "1",
14-
user: account.account_id,
15-
filter: "created",
16-
q: params["q"]
17-
}
18-
|> Ret.MediaSearch.search()
6+
when source in ["rooms"] do
7+
account = conn |> Guardian.Plug.current_resource()
8+
9+
if account && account.account_id == String.to_integer(user) do
10+
{:commit, results} =
11+
%Ret.MediaSearchQuery{
12+
source: "rooms",
13+
cursor: params["cursor"] || "1",
14+
user: account.account_id,
15+
filter: "created",
16+
q: params["q"]
17+
}
18+
|> Ret.MediaSearch.search()
1919

20-
conn |> render("index.json", results: results)
21-
else
22-
conn |> send_resp(401, "You can only search created rooms for your own account.")
20+
conn |> render("index.json", results: results)
21+
else
22+
conn |> send_resp(401, "You can only search created rooms for your own account.")
23+
end
2324
end
24-
end
2525

2626
def index(conn, %{"source" => "rooms"} = params) do
2727
{:commit, results} =

0 commit comments

Comments
 (0)