mix format
This commit is contained in:
parent
f3c35e8e55
commit
385afb9308
6 changed files with 77 additions and 46 deletions
|
@ -89,7 +89,9 @@ defmodule Nulla.ActivityPub do
|
|||
def note(domain, note) do
|
||||
attachment =
|
||||
case note.media_attachments do
|
||||
[] -> []
|
||||
[] ->
|
||||
[]
|
||||
|
||||
attachments ->
|
||||
[
|
||||
attachment:
|
||||
|
@ -151,8 +153,16 @@ defmodule Nulla.ActivityPub do
|
|||
)
|
||||
end
|
||||
|
||||
@spec following(String.t(), Nulla.Models.User.t(), Integer.t(), List.t(), Integer.t(), Integer.t()) :: Jason.OrderedObject.t()
|
||||
def following(domain, user, total, following_list, page, offset) when is_integer(page) and page > 0 do
|
||||
@spec following(
|
||||
String.t(),
|
||||
Nulla.Models.User.t(),
|
||||
Integer.t(),
|
||||
List.t(),
|
||||
Integer.t(),
|
||||
Integer.t()
|
||||
) :: Jason.OrderedObject.t()
|
||||
def following(domain, user, total, following_list, page, offset)
|
||||
when is_integer(page) and page > 0 do
|
||||
data = [
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
id: "https://#{domain}/@#{user.username}/following?page=#{page}",
|
||||
|
@ -194,8 +204,16 @@ defmodule Nulla.ActivityPub do
|
|||
)
|
||||
end
|
||||
|
||||
@spec followers(String.t(), Nulla.Models.User.t(), Integer.t(), List.t(), Integer.t(), Integer.t()) :: Jason.OrderedObject.t()
|
||||
def followers(domain, user, total, followers_list, page, offset) when is_integer(page) and page > 0 do
|
||||
@spec followers(
|
||||
String.t(),
|
||||
Nulla.Models.User.t(),
|
||||
Integer.t(),
|
||||
List.t(),
|
||||
Integer.t(),
|
||||
Integer.t()
|
||||
) :: Jason.OrderedObject.t()
|
||||
def followers(domain, user, total, followers_list, page, offset)
|
||||
when is_integer(page) and page > 0 do
|
||||
data = [
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
id: "https://#{domain}/@#{user.username}/followers?page=#{page}",
|
||||
|
|
|
@ -5,8 +5,11 @@ defmodule Nulla.KeyGen do
|
|||
{:RSAPrivateKey, :"two-prime", n, e, _d, _p, _q, _dp, _dq, _qi, _other} = rsa_key
|
||||
public_key = {:RSAPublicKey, n, e}
|
||||
|
||||
private_entry = {:PrivateKeyInfo, :public_key.der_encode(:RSAPrivateKey, rsa_key), :not_encrypted}
|
||||
public_entry = {:SubjectPublicKeyInfo, :public_key.der_encode(:RSAPublicKey, public_key), :not_encrypted}
|
||||
private_entry =
|
||||
{:PrivateKeyInfo, :public_key.der_encode(:RSAPrivateKey, rsa_key), :not_encrypted}
|
||||
|
||||
public_entry =
|
||||
{:SubjectPublicKeyInfo, :public_key.der_encode(:RSAPublicKey, public_key), :not_encrypted}
|
||||
|
||||
private_pem = :public_key.pem_encode([private_entry])
|
||||
public_pem = :public_key.pem_encode([public_entry])
|
||||
|
|
|
@ -32,15 +32,17 @@ defmodule Nulla.Utils do
|
|||
offset = (page - 1) * per_page
|
||||
|
||||
query =
|
||||
from [f, u] in
|
||||
from(f in Follow,
|
||||
join: u in User, on: u.id == f.target_id,
|
||||
from(
|
||||
[f, u] in from(f in Follow,
|
||||
join: u in User,
|
||||
on: u.id == f.target_id,
|
||||
where: f.user_id == ^user_id,
|
||||
order_by: [asc: u.inserted_at],
|
||||
offset: ^offset,
|
||||
limit: ^per_page,
|
||||
select: u
|
||||
)
|
||||
)
|
||||
|
||||
users = Repo.all(query)
|
||||
|
||||
|
@ -73,7 +75,8 @@ defmodule Nulla.Utils do
|
|||
query =
|
||||
from f in Follow,
|
||||
where: f.target_id == ^user_id,
|
||||
join: u in User, on: u.id == f.user_id,
|
||||
join: u in User,
|
||||
on: u.id == f.user_id,
|
||||
order_by: [asc: u.inserted_at],
|
||||
offset: ^offset,
|
||||
limit: ^per_page,
|
||||
|
|
|
@ -11,11 +11,13 @@ defmodule NullaWeb.FollowController do
|
|||
offset = instance_settings.offset
|
||||
user = User.get_user_by_username!(username)
|
||||
total = Utils.count_following_by_username!(user.username)
|
||||
|
||||
page =
|
||||
case Integer.parse(page_param) do
|
||||
{int, _} when int > 0 -> int
|
||||
_ -> 1
|
||||
end
|
||||
|
||||
following_list = Utils.get_following_users_by_username!(user.username, page)
|
||||
|
||||
conn
|
||||
|
@ -40,11 +42,13 @@ defmodule NullaWeb.FollowController do
|
|||
offset = instance_settings.offset
|
||||
user = User.get_user_by_username!(username)
|
||||
total = Utils.count_followers_by_username!(user.username)
|
||||
|
||||
page =
|
||||
case Integer.parse(page_param) do
|
||||
{int, _} when int > 0 -> int
|
||||
_ -> 1
|
||||
end
|
||||
|
||||
followers_list = Utils.get_followers_by_username!(user.username, page)
|
||||
|
||||
conn
|
||||
|
|
|
@ -21,11 +21,14 @@ defmodule Nulla.Repo.Migrations.CreateInstanceSettings do
|
|||
execute(fn ->
|
||||
{public_key, private_key} = Nulla.KeyGen.generate_keys()
|
||||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
|
||||
domain =
|
||||
Application.get_env(:nulla, NullaWeb.Endpoint, [])
|
||||
|> Keyword.get(:url, [])
|
||||
|> Keyword.get(:host, "localhost")
|
||||
|
||||
esc = fn str -> "'#{String.replace(str, "'", "''")}'" end
|
||||
|
||||
sql = """
|
||||
INSERT INTO instance_settings (
|
||||
name, description, domain, registration,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue