Update
This commit is contained in:
parent
fa350aa551
commit
c531beadb7
11 changed files with 20 additions and 41 deletions
|
@ -7,7 +7,6 @@ defmodule Nulla.Models.InstanceSettings do
|
||||||
schema "instance_settings" do
|
schema "instance_settings" do
|
||||||
field :name, :string, default: "Nulla"
|
field :name, :string, default: "Nulla"
|
||||||
field :description, :string, default: "Freedom Social Network"
|
field :description, :string, default: "Freedom Social Network"
|
||||||
field :domain, :string, default: "localhost"
|
|
||||||
field :registration, :boolean, default: false
|
field :registration, :boolean, default: false
|
||||||
field :max_characters, :integer, default: 5000
|
field :max_characters, :integer, default: 5000
|
||||||
field :max_upload_size, :integer, default: 50
|
field :max_upload_size, :integer, default: 50
|
||||||
|
@ -22,7 +21,6 @@ defmodule Nulla.Models.InstanceSettings do
|
||||||
|> cast(attrs, [
|
|> cast(attrs, [
|
||||||
:name,
|
:name,
|
||||||
:description,
|
:description,
|
||||||
:domain,
|
|
||||||
:registration,
|
:registration,
|
||||||
:max_characters,
|
:max_characters,
|
||||||
:max_upload_size,
|
:max_upload_size,
|
||||||
|
@ -33,7 +31,6 @@ defmodule Nulla.Models.InstanceSettings do
|
||||||
|> validate_required([
|
|> validate_required([
|
||||||
:name,
|
:name,
|
||||||
:description,
|
:description,
|
||||||
:domain,
|
|
||||||
:registration,
|
:registration,
|
||||||
:max_characters,
|
:max_characters,
|
||||||
:max_upload_size,
|
:max_upload_size,
|
||||||
|
|
|
@ -69,7 +69,9 @@ defmodule Nulla.Models.Relation do
|
||||||
case get_relation(local_actor_id: local_actor_id, remote_actor_id: remote_actor_id) do
|
case get_relation(local_actor_id: local_actor_id, remote_actor_id: remote_actor_id) do
|
||||||
nil ->
|
nil ->
|
||||||
attrs =
|
attrs =
|
||||||
Keyword.merge([local_actor_id: local_actor_id, remote_actor_id: remote_actor_id], opts)
|
[local_actor_id: local_actor_id, remote_actor_id: remote_actor_id]
|
||||||
|
|> Keyword.merge(opts)
|
||||||
|
|> Enum.into(%{})
|
||||||
|
|
||||||
case create_relation(attrs) do
|
case create_relation(attrs) do
|
||||||
{:ok, relation} -> {:ok, relation}
|
{:ok, relation} -> {:ok, relation}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
defmodule Nulla.Utils do
|
defmodule Nulla.Utils do
|
||||||
alias Finch
|
|
||||||
|
|
||||||
def fetch_remote_actor(uri) do
|
def fetch_remote_actor(uri) do
|
||||||
headers = [
|
headers = [
|
||||||
{"Accept", "application/activity+json"},
|
{"Accept", "application/activity+json"},
|
||||||
|
|
|
@ -4,12 +4,10 @@ defmodule NullaWeb.ActorController do
|
||||||
alias Nulla.Models.Actor
|
alias Nulla.Models.Actor
|
||||||
alias Nulla.Models.Relation
|
alias Nulla.Models.Relation
|
||||||
alias Nulla.Models.Note
|
alias Nulla.Models.Note
|
||||||
alias Nulla.Models.InstanceSettings
|
|
||||||
|
|
||||||
def show(conn, %{"username" => username}) do
|
def show(conn, %{"username" => username}) do
|
||||||
format = Phoenix.Controller.get_format(conn)
|
format = Phoenix.Controller.get_format(conn)
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
domain = NullaWeb.Endpoint.host()
|
||||||
domain = instance_settings.domain
|
|
||||||
|
|
||||||
case Actor.get_actor(preferredUsername: username, domain: domain) do
|
case Actor.get_actor(preferredUsername: username, domain: domain) do
|
||||||
nil ->
|
nil ->
|
||||||
|
|
|
@ -39,7 +39,7 @@ defmodule NullaWeb.AuthController do
|
||||||
|> put_flash(:error, "Registration is disabled.")
|
|> put_flash(:error, "Registration is disabled.")
|
||||||
|> redirect(to: ~p"/")
|
|> redirect(to: ~p"/")
|
||||||
else
|
else
|
||||||
domain = instance_settings.domain
|
domain = NullaWeb.Endpoint.host()
|
||||||
hashed_password = Argon2.hash_pwd_salt(password)
|
hashed_password = Argon2.hash_pwd_salt(password)
|
||||||
|
|
||||||
{publicKeyPem, privateKeyPem} = Nulla.KeyGen.gen()
|
{publicKeyPem, privateKeyPem} = Nulla.KeyGen.gen()
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule NullaWeb.FollowController do
|
||||||
|
|
||||||
def following(conn, %{"username" => username, "page" => page_param}) do
|
def following(conn, %{"username" => username, "page" => page_param}) do
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
instance_settings = InstanceSettings.get_instance_settings!()
|
||||||
domain = instance_settings.domain
|
domain = NullaWeb.Endpoint.host()
|
||||||
limit = instance_settings.api_limit
|
limit = instance_settings.api_limit
|
||||||
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
||||||
total = Relation.count_following(actor.id)
|
total = Relation.count_following(actor.id)
|
||||||
|
@ -26,8 +26,7 @@ defmodule NullaWeb.FollowController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def following(conn, %{"username" => username}) do
|
def following(conn, %{"username" => username}) do
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
domain = NullaWeb.Endpoint.host()
|
||||||
domain = instance_settings.domain
|
|
||||||
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
||||||
total = Relation.count_following(actor.id)
|
total = Relation.count_following(actor.id)
|
||||||
|
|
||||||
|
@ -38,7 +37,7 @@ defmodule NullaWeb.FollowController do
|
||||||
|
|
||||||
def followers(conn, %{"username" => username, "page" => page_param}) do
|
def followers(conn, %{"username" => username, "page" => page_param}) do
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
instance_settings = InstanceSettings.get_instance_settings!()
|
||||||
domain = instance_settings.domain
|
domain = NullaWeb.Endpoint.host()
|
||||||
limit = instance_settings.api_limit
|
limit = instance_settings.api_limit
|
||||||
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
||||||
total = Relation.count_followers(actor.id)
|
total = Relation.count_followers(actor.id)
|
||||||
|
@ -57,8 +56,7 @@ defmodule NullaWeb.FollowController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def followers(conn, %{"username" => username}) do
|
def followers(conn, %{"username" => username}) do
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
domain = NullaWeb.Endpoint.host()
|
||||||
domain = instance_settings.domain
|
|
||||||
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
||||||
total = Relation.count_followers(actor.id)
|
total = Relation.count_followers(actor.id)
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
defmodule NullaWeb.HostmetaController do
|
defmodule NullaWeb.HostmetaController do
|
||||||
use NullaWeb, :controller
|
use NullaWeb, :controller
|
||||||
alias Nulla.Models.InstanceSettings
|
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
domain = NullaWeb.Endpoint.host()
|
||||||
domain = instance_settings.domain
|
|
||||||
|
|
||||||
xml = """
|
xml = """
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
|
@ -5,8 +5,7 @@ defmodule NullaWeb.NodeinfoController do
|
||||||
alias Nulla.Models.InstanceSettings
|
alias Nulla.Models.InstanceSettings
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
domain = NullaWeb.Endpoint.host()
|
||||||
domain = instance_settings.domain
|
|
||||||
|
|
||||||
json(conn, ActivityPub.nodeinfo(domain))
|
json(conn, ActivityPub.nodeinfo(domain))
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,14 +3,13 @@ defmodule NullaWeb.OutboxController do
|
||||||
alias Nulla.ActivityPub
|
alias Nulla.ActivityPub
|
||||||
alias Nulla.Models.Actor
|
alias Nulla.Models.Actor
|
||||||
alias Nulla.Models.Note
|
alias Nulla.Models.Note
|
||||||
alias Nulla.Models.InstanceSettings
|
|
||||||
|
|
||||||
def outbox(conn, %{"username" => username} = params) do
|
def outbox(conn, %{"username" => username} = params) do
|
||||||
|
domain = NullaWeb.Endpoint.host()
|
||||||
|
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
||||||
|
|
||||||
case Map.get(params, "page") do
|
case Map.get(params, "page") do
|
||||||
"true" ->
|
"true" ->
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
|
||||||
domain = instance_settings.domain
|
|
||||||
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
|
||||||
max_id = params["max_id"] && String.to_integer(params["max_id"])
|
max_id = params["max_id"] && String.to_integer(params["max_id"])
|
||||||
|
|
||||||
notes =
|
notes =
|
||||||
|
@ -42,9 +41,6 @@ defmodule NullaWeb.OutboxController do
|
||||||
)
|
)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
|
||||||
domain = instance_settings.domain
|
|
||||||
actor = Actor.get_actor(preferredUsername: username, domain: domain)
|
|
||||||
total = Note.get_total_notes_count(actor.id)
|
total = Note.get_total_notes_count(actor.id)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -2,21 +2,20 @@ defmodule NullaWeb.WebfingerController do
|
||||||
use NullaWeb, :controller
|
use NullaWeb, :controller
|
||||||
alias Nulla.ActivityPub
|
alias Nulla.ActivityPub
|
||||||
alias Nulla.Models.Actor
|
alias Nulla.Models.Actor
|
||||||
alias Nulla.Models.InstanceSettings
|
|
||||||
|
|
||||||
def index(conn, %{"resource" => resource}) do
|
def index(conn, %{"resource" => resource}) do
|
||||||
case Regex.run(~r/^acct:(.+)@(.+)$/, resource) do
|
case Regex.run(~r/^acct:(.+)@(.+)$/, resource) do
|
||||||
[_, username, domain] ->
|
[_, preferredUsername, actor_domain] ->
|
||||||
case Actor.get_actor(preferredUsername: username, domain: domain) do
|
case Actor.get_actor(preferredUsername: preferredUsername, domain: actor_domain) do
|
||||||
nil ->
|
nil ->
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("text/plain")
|
|> put_resp_content_type("text/plain")
|
||||||
|> send_resp(404, "")
|
|> send_resp(404, "")
|
||||||
|
|
||||||
%Actor{} = actor ->
|
%Actor{} = actor ->
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
domain = NullaWeb.Endpoint.host()
|
||||||
|
|
||||||
if domain == instance_settings.domain do
|
if actor_domain == domain do
|
||||||
json(conn, ActivityPub.webfinger(actor))
|
json(conn, ActivityPub.webfinger(actor))
|
||||||
else
|
else
|
||||||
conn
|
conn
|
||||||
|
|
|
@ -6,7 +6,6 @@ defmodule Nulla.Repo.Migrations.CreateInstanceSettings do
|
||||||
add :id, :integer, primary_key: true
|
add :id, :integer, primary_key: true
|
||||||
add :name, :string, default: "Nulla", null: false
|
add :name, :string, default: "Nulla", null: false
|
||||||
add :description, :text, default: "Freedom Social Network", null: false
|
add :description, :text, default: "Freedom Social Network", null: false
|
||||||
add :domain, :string, default: "localhost", null: false
|
|
||||||
add :registration, :boolean, default: false, null: false
|
add :registration, :boolean, default: false, null: false
|
||||||
add :max_characters, :integer, default: 5000, null: false
|
add :max_characters, :integer, default: 5000, null: false
|
||||||
add :max_upload_size, :integer, default: 50, null: false
|
add :max_upload_size, :integer, default: 50, null: false
|
||||||
|
@ -25,20 +24,15 @@ defmodule Nulla.Repo.Migrations.CreateInstanceSettings do
|
||||||
{public_key, private_key} = Nulla.KeyGen.gen()
|
{public_key, private_key} = Nulla.KeyGen.gen()
|
||||||
now = DateTime.utc_now()
|
now = DateTime.utc_now()
|
||||||
|
|
||||||
domain =
|
|
||||||
Application.get_env(:nulla, NullaWeb.Endpoint, [])
|
|
||||||
|> Keyword.get(:url, [])
|
|
||||||
|> Keyword.get(:host, "localhost")
|
|
||||||
|
|
||||||
esc = fn str -> "'#{String.replace(str, "'", "''")}'" end
|
esc = fn str -> "'#{String.replace(str, "'", "''")}'" end
|
||||||
|
|
||||||
sql = """
|
sql = """
|
||||||
INSERT INTO instance_settings (
|
INSERT INTO instance_settings (
|
||||||
id, name, description, domain, registration,
|
id, name, description, registration,
|
||||||
max_characters, max_upload_size, api_limit,
|
max_characters, max_upload_size, api_limit,
|
||||||
public_key, private_key, inserted_at, updated_at
|
public_key, private_key, inserted_at, updated_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
1, 'Nulla', 'Freedom Social Network', '#{domain}', false,
|
1, 'Nulla', 'Freedom Social Network', false,
|
||||||
5000, 50, 100,
|
5000, 50, 100,
|
||||||
#{esc.(public_key)}, #{esc.(private_key)},
|
#{esc.(public_key)}, #{esc.(private_key)},
|
||||||
'#{now}', '#{now}'
|
'#{now}', '#{now}'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue