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,
:like_of,
:title,
:type
:type,
:published_at
]
end

View file

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

View file

@ -60,15 +60,6 @@ defmodule PlugIndie.Token do
supported_scopes,
own_hostname
) 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("ClientId: '#{client_id}'")
Logger.info("Scopes: '#{scope}'")

View file

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

View file

@ -39,13 +39,36 @@ defmodule TokenTest do
supported_scopes = ["create", "media"]
hostname = "blog.inhji.de"
assert PlugIndie.Token.verify_token_response(
assert :ok ==
PlugIndie.Token.verify_token_response(
body,
required_scope,
supported_scopes,
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