From 45b6da6fff6185eba0b8d37bc713fbd540ffe962 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Fri, 1 Mar 2024 11:23:55 +0100 Subject: [PATCH 1/6] Add a search query for owned rooms --- lib/ret/media_search.ex | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/ret/media_search.ex b/lib/ret/media_search.ex index f47a3a57e..77413aadd 100644 --- a/lib/ret/media_search.ex +++ b/lib/ret/media_search.ex @@ -41,7 +41,7 @@ defmodule Ret.MediaSearch do @max_collection_face_count 200_000 # see sketchfab bug about max_filesizes params broken - # @max_file_size_bytes 20 * 1024 * 1024 + # @max_file_size_bytes 20 * 1024 * 1024 # @max_collection_file_size_bytes 100 * 1024 * 1024 def search(%Ret.MediaSearchQuery{ @@ -125,6 +125,10 @@ defmodule Ret.MediaSearch do public_rooms_search(cursor, q) end + def search(%Ret.MediaSearchQuery{source: "rooms", filter: "created", cursor: cursor, q: q}) do + created_rooms_search(cursor, q) + end + def search(%Ret.MediaSearchQuery{ source: "sketchfab", cursor: cursor, @@ -225,7 +229,7 @@ defmodule Ret.MediaSearch do downloadable: true, count: @page_size, max_face_count: @max_face_count, - # max_filesizes: "gltf:#{@max_file_size_bytes}", + # max_filesizes: "gltf:#{@max_file_size_bytes}", processing_status: :succeeded, cursor: cursor, categories: filter, @@ -547,6 +551,25 @@ defmodule Ret.MediaSearch do {:commit, results} end + defp created_rooms_search(cursor, _query) do + page_number = (cursor || "1") |> Integer.parse() |> elem(0) + + ecto_query = + from h in Hub, + preload: [ + scene: [:screenshot_owned_file], + scene_listing: [:scene, :screenshot_owned_file] + ], + order_by: [desc: :inserted_at] + + results = + ecto_query + |> Repo.paginate(%{page: page_number, page_size: @page_size}) + |> result_for_page(page_number, :my_rooms, &hub_to_entry/1) + + {:commit, results} + end + defp filter_by_hub_entry_mode(query, entry_mode) do from fav in query, join: hub in assoc(fav, :hub), From 1d506c957eb5316995bceae437795fecfe9071e9 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Fri, 29 Mar 2024 04:48:06 +0100 Subject: [PATCH 2/6] Revert "Add a search query for owned rooms" --- lib/ret/media_search.ex | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/lib/ret/media_search.ex b/lib/ret/media_search.ex index 77413aadd..f47a3a57e 100644 --- a/lib/ret/media_search.ex +++ b/lib/ret/media_search.ex @@ -41,7 +41,7 @@ defmodule Ret.MediaSearch do @max_collection_face_count 200_000 # see sketchfab bug about max_filesizes params broken - # @max_file_size_bytes 20 * 1024 * 1024 + # @max_file_size_bytes 20 * 1024 * 1024 # @max_collection_file_size_bytes 100 * 1024 * 1024 def search(%Ret.MediaSearchQuery{ @@ -125,10 +125,6 @@ defmodule Ret.MediaSearch do public_rooms_search(cursor, q) end - def search(%Ret.MediaSearchQuery{source: "rooms", filter: "created", cursor: cursor, q: q}) do - created_rooms_search(cursor, q) - end - def search(%Ret.MediaSearchQuery{ source: "sketchfab", cursor: cursor, @@ -229,7 +225,7 @@ defmodule Ret.MediaSearch do downloadable: true, count: @page_size, max_face_count: @max_face_count, - # max_filesizes: "gltf:#{@max_file_size_bytes}", + # max_filesizes: "gltf:#{@max_file_size_bytes}", processing_status: :succeeded, cursor: cursor, categories: filter, @@ -551,25 +547,6 @@ defmodule Ret.MediaSearch do {:commit, results} end - defp created_rooms_search(cursor, _query) do - page_number = (cursor || "1") |> Integer.parse() |> elem(0) - - ecto_query = - from h in Hub, - preload: [ - scene: [:screenshot_owned_file], - scene_listing: [:scene, :screenshot_owned_file] - ], - order_by: [desc: :inserted_at] - - results = - ecto_query - |> Repo.paginate(%{page: page_number, page_size: @page_size}) - |> result_for_page(page_number, :my_rooms, &hub_to_entry/1) - - {:commit, results} - end - defp filter_by_hub_entry_mode(query, entry_mode) do from fav in query, join: hub in assoc(fav, :hub), From 8d16470ff6a31db7f61fe074317aaf9dd1712a51 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Tue, 2 Apr 2024 11:16:41 +0200 Subject: [PATCH 3/6] Search created rooms --- lib/ret/media_search.ex | 33 +++++++++++++++++-- .../api/v1/media_search_controller.ex | 21 ++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/lib/ret/media_search.ex b/lib/ret/media_search.ex index f47a3a57e..03a4f615c 100644 --- a/lib/ret/media_search.ex +++ b/lib/ret/media_search.ex @@ -41,7 +41,7 @@ defmodule Ret.MediaSearch do @max_collection_face_count 200_000 # see sketchfab bug about max_filesizes params broken - # @max_file_size_bytes 20 * 1024 * 1024 + # @max_file_size_bytes 20 * 1024 * 1024 # @max_collection_file_size_bytes 100 * 1024 * 1024 def search(%Ret.MediaSearchQuery{ @@ -125,6 +125,16 @@ defmodule Ret.MediaSearch do public_rooms_search(cursor, q) end + def search(%Ret.MediaSearchQuery{ + source: "rooms", + filter: "created", + cursor: cursor, + user: account_id, + q: q + }) do + created_rooms_search(cursor, account_id, q) + end + def search(%Ret.MediaSearchQuery{ source: "sketchfab", cursor: cursor, @@ -225,7 +235,7 @@ defmodule Ret.MediaSearch do downloadable: true, count: @page_size, max_face_count: @max_face_count, - # max_filesizes: "gltf:#{@max_file_size_bytes}", + # max_filesizes: "gltf:#{@max_file_size_bytes}", processing_status: :succeeded, cursor: cursor, categories: filter, @@ -547,6 +557,25 @@ defmodule Ret.MediaSearch do {:commit, results} end + defp created_rooms_search(cursor, account_id, _query) do + page_number = (cursor || "1") |> Integer.parse() |> elem(0) + ecto_query = + from h in Hub, + where: h.created_by_account_id == ^account_id, + preload: [ + scene: [:screenshot_owned_file], + scene_listing: [:scene, :screenshot_owned_file] + ], + order_by: [desc: :inserted_at] + + results = + ecto_query + |> Repo.paginate(%{page: page_number, page_size: @page_size}) + |> result_for_page(page_number, :my_rooms, &hub_to_entry/1) + + {:commit, results} + end + defp filter_by_hub_entry_mode(query, entry_mode) do from fav in query, join: hub in assoc(fav, :hub), diff --git a/lib/ret_web/controllers/api/v1/media_search_controller.ex b/lib/ret_web/controllers/api/v1/media_search_controller.ex index b4885e3f3..f21ca1460 100644 --- a/lib/ret_web/controllers/api/v1/media_search_controller.ex +++ b/lib/ret_web/controllers/api/v1/media_search_controller.ex @@ -2,6 +2,27 @@ defmodule RetWeb.Api.V1.MediaSearchController do use RetWeb, :controller use Retry + def index(conn, %{"source" => source, "filter" => "created", "user" => user} = params) + when source in ["rooms"] do + account = conn |> Guardian.Plug.current_resource() + + if account && account.account_id == String.to_integer(user) do + {:commit, results} = + %Ret.MediaSearchQuery{ + source: "rooms", + cursor: params["cursor"] || "1", + user: account.account_id, + filter: "created", + q: params["q"] + } + |> Ret.MediaSearch.search() + + conn |> render("index.json", results: results) + else + conn |> send_resp(401, "You can only search created rooms for your own account.") + end + end + def index(conn, %{"source" => "rooms"} = params) do {:commit, results} = %Ret.MediaSearchQuery{ From c428d2d6a6f429be40dee04f0ec78d37111e7725 Mon Sep 17 00:00:00 2001 From: Taku Ito Date: Sun, 7 Apr 2024 20:52:18 +0900 Subject: [PATCH 4/6] Fix version of reverse_proxy_plug to 2.3.0 --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 32278ccd1..7f988b536 100644 --- a/mix.exs +++ b/mix.exs @@ -80,7 +80,7 @@ defmodule Ret.Mixfile do {:scrivener_ecto, "~> 2.0"}, {:ua_parser, "~> 1.5"}, {:download, git: "https://github.com/gfodor/download.git", branch: "reticulum/master"}, - {:reverse_proxy_plug, "~> 2.1"}, + {:reverse_proxy_plug, "2.3.0"}, {:inet_cidr, "~> 1.0"}, {:dns, "~> 2.2.0"}, {:oauther, "~> 1.1"}, From bfab4e9d0ba89ff60b33232f0ca80c1632363ceb Mon Sep 17 00:00:00 2001 From: Taku Ito Date: Sun, 7 Apr 2024 23:26:18 +0900 Subject: [PATCH 5/6] Update mix.lock --- mix.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.lock b/mix.lock index 09f929afd..c8ecd056a 100644 --- a/mix.lock +++ b/mix.lock @@ -71,7 +71,7 @@ "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, "recon": {:hex, :recon, "2.5.0", "2f7fcbec2c35034bade2f9717f77059dc54eb4e929a3049ca7ba6775c0bd66cd", [:mix, :rebar3], [], "hexpm", "72f3840fedd94f06315c523f6cecf5b4827233bed7ae3fe135b2a0ebeab5e196"}, "retry": {:hex, :retry, "0.15.0", "ba6aaeba92905a396c18c299a07e638947b2ba781e914f803202bc1b9ae867c3", [:mix], [], "hexpm", "93d3310bce78c0a30cc94610684340a14adfc9136856a3f662e4d9ce6013c784"}, - "reverse_proxy_plug": {:git, "https://github.com/mozillareality/reverse_proxy_plug.git", "271111467623ca1f45c3837b14c4ca0661db0f3e", [branch: "reticulum/master"]}, + "reverse_proxy_plug": {:hex, :reverse_proxy_plug, "2.3.0", "6830ae83b383576899826d09ac00328e559455de650c9f047a413f1b64de450d", [:mix], [{:cowboy, "~> 2.4", [hex: :cowboy, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.2 or ~> 2.0", [hex: :httpoison, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: false]}, {:tesla, "~> 1.4", [hex: :tesla, repo: "hexpm", optional: true]}], "hexpm", "eb0007fb8fc6a4a1627c62270e2713e99bea31883daac77c85d60dd10dcdfdc3"}, "scrivener": {:hex, :scrivener, "2.7.0", "fa94cdea21fad0649921d8066b1833d18d296217bfdf4a5389a2f45ee857b773", [:mix], [], "hexpm", "30da36a427f2519cf75993271fb7c5aad1759682a70f90d880a85c3d743d2c57"}, "scrivener_ecto": {:hex, :scrivener_ecto, "2.3.0", "057f9dd3c77315f0a470263c3565353860d0294404aed611b3524c6df9044189", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:scrivener, "~> 2.4", [hex: :scrivener, repo: "hexpm", optional: false]}], "hexpm", "dfa43ca660651da63239e5d4acbfd9c57c5759bbf3a2bdc16cd70777c9bc7e0d"}, "secure_random": {:hex, :secure_random, "0.5.1", "c5532b37c89d175c328f5196a0c2a5680b15ebce3e654da37129a9fe40ebf51b", [:mix], [], "hexpm", "1b9754f15e3940a143baafd19da12293f100044df69ea12db5d72878312ae6ab"}, From 033888882efdd27ea2b8e5db87e6107886310862 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Thu, 11 Apr 2024 17:54:49 +0200 Subject: [PATCH 6/6] Update README.md Add info about how to execute the iex command --- README.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fdd8e05cd..60f53678c 100644 --- a/README.md +++ b/README.md @@ -108,16 +108,26 @@ Navigate to that url in your browser to finish signing in. ### 6. Creating an Admin User -After you've started Reticulum for the first time you'll likely want to create an admin user. Assuming you want to make the first account the admin, this can be done in the iex console using the following code: - +After you've started Reticulum for the first time you'll likely want to create an admin user. Assuming you want to make the first account the admin, this can be done in the iex console: +1) Open the iex console. From the reticulum folder run: +``` +iex -S mix +``` +2) Then run the following code: ``` Ret.Account |> Ret.Repo.all() |> Enum.at(0) |> Ecto.Changeset.change(is_admin: true) |> Ret.Repo.update!() ``` +Make sure to run the Maybe try iex -S mix where the reticulum mix.exs file is. + ### 7. Enabling Room Features Rooms are created with restricted permissions by default, which means you can't spawn media objects. You can change this setting in the admin panel, or run the following code in the iex console: - +1) Open the iex console. From the reticulum folder run: +``` +iex -S mix +``` +2) Then run the following code: ``` Ret.AppConfig.set_config_value("features|permissive_rooms", true) ```