add publish date, add article type

This commit is contained in:
Inhji 2024-12-06 09:40:16 +01:00
parent 550ca0aacc
commit e1d37bdea0
5 changed files with 68 additions and 23 deletions

View file

@ -4,6 +4,7 @@ defmodule PlugIndie.Post do
:content, :content,
:like_of, :like_of,
:title, :title,
:type :type,
:published_at
] ]
end end

View file

@ -3,12 +3,23 @@ defmodule PlugIndie.Properties do
{:ok, type} = get_post_type(properties) {:ok, type} = get_post_type(properties)
content = get_content(properties) content = get_content(properties)
title = get_title(properties) title = get_title(properties)
published = is_published?(properties)
published_at = if published, do: DateTime.utc_now(), else: nil
case type do case type do
:note -> :note ->
{:ok, {:ok,
%PlugIndie.Post{ %PlugIndie.Post{
type: type, type: type,
published_at: published_at,
content: content
}}
:article ->
{:ok,
%PlugIndie.Post{
type: type,
published_at: published_at,
title: title, title: title,
content: content content: content
}} }}
@ -17,6 +28,7 @@ defmodule PlugIndie.Properties do
{:ok, {:ok,
%PlugIndie.Post{ %PlugIndie.Post{
type: type, type: type,
published_at: published_at,
title: title, title: title,
content: content, content: content,
bookmark_of: get_bookmarked_url(properties) bookmark_of: get_bookmarked_url(properties)
@ -26,6 +38,7 @@ defmodule PlugIndie.Properties do
{:ok, {:ok,
%PlugIndie.Post{ %PlugIndie.Post{
type: type, type: type,
published_at: published_at,
like_of: get_liked_url(properties) like_of: get_liked_url(properties)
}} }}
@ -42,9 +55,12 @@ defmodule PlugIndie.Properties do
Map.has_key?(properties, "bookmark-of") -> Map.has_key?(properties, "bookmark-of") ->
{:ok, :bookmark} {:ok, :bookmark}
Map.has_key?(properties, "content") -> Map.has_key?(properties, "content") and not Map.has_key?(properties, "name") ->
{:ok, :note} {:ok, :note}
Map.has_key?(properties, "content") and Map.has_key?(properties, "name") ->
{:ok, :article}
true -> true ->
{:ok, :unknown} {:ok, :unknown}
end end

View file

@ -60,15 +60,6 @@ defmodule PlugIndie.Token do
supported_scopes, supported_scopes,
own_hostname own_hostname
) do ) do
# {%{
# "client_id" => "https://indiepass.app/",
# "issued_at" => 1_733_382_601,
# "issued_by" => "https://tokens.indieauth.com/token",
# "me" => "https://blog.inhji.de/",
# "nonce" => 358_618_865,
# "scope" => "create update delete media read follow channels mute block"
# }, "create", ["create", "media"], "inhji.de"}
Logger.info("Host-URI: '#{host_uri}'") Logger.info("Host-URI: '#{host_uri}'")
Logger.info("ClientId: '#{client_id}'") Logger.info("ClientId: '#{client_id}'")
Logger.info("Scopes: '#{scope}'") Logger.info("Scopes: '#{scope}'")

View file

@ -12,21 +12,35 @@ defmodule PropertiesTest do
%PlugIndie.Post{ %PlugIndie.Post{
type: :note, type: :note,
content: "Hello World!" content: "Hello World!"
}} == parse(props) }} = parse(props)
end
test "parse/1 identifies an article" do
props = %{
"name" => ["My Title"],
"content" => ["Hello World!"]
}
assert {:ok,
%PlugIndie.Post{
type: :article,
content: "Hello World!",
title: "My Title"
}} = parse(props)
end end
test "parse/1 identifies a bookmark" do test "parse/1 identifies a bookmark" do
props = %{ props = %{
"content" => ["Hello World!"], "content" => ["100 Rabbits"],
"bookmark-of" => ["https://100r.co"] "bookmark-of" => ["https://100r.co"]
} }
assert {:ok, assert {:ok,
%PlugIndie.Post{ %PlugIndie.Post{
type: :bookmark, type: :bookmark,
content: "Hello World!", content: "100 Rabbits",
bookmark_of: "https://100r.co" bookmark_of: "https://100r.co"
}} == parse(props) }} = parse(props)
end end
test "parse/1 identifies a like" do test "parse/1 identifies a like" do
@ -38,6 +52,6 @@ defmodule PropertiesTest do
%PlugIndie.Post{ %PlugIndie.Post{
type: :like, type: :like,
like_of: "https://100r.co" like_of: "https://100r.co"
}} == parse(props) }} = parse(props)
end end
end end

View file

@ -39,13 +39,36 @@ defmodule TokenTest do
supported_scopes = ["create", "media"] supported_scopes = ["create", "media"]
hostname = "blog.inhji.de" hostname = "blog.inhji.de"
assert PlugIndie.Token.verify_token_response( assert :ok ==
PlugIndie.Token.verify_token_response(
body, body,
required_scope, required_scope,
supported_scopes, supported_scopes,
hostname hostname
) == )
:ok end
test "with mismatching hostname" do
body = %{
"client_id" => "https://indiepass.app/",
"issued_at" => 1_733_382_601,
"issued_by" => "https://tokens.indieauth.com/token",
"me" => "https://inhji.wtf/",
"nonce" => 358_618_865,
"scope" => "create update delete media read follow channels mute block"
}
required_scope = "create"
supported_scopes = ["create", "media"]
hostname = "blog.inhji.de"
assert {:error, _, _} =
PlugIndie.Token.verify_token_response(
body,
required_scope,
supported_scopes,
hostname
)
end end
end end
end end