You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.3 KiB
Clojure
125 lines
3.3 KiB
Clojure
(ns org.domaindrivenarchitecture.fed-poc.core
|
|
(:require [lambdaisland.souk.activitypub :as ap]
|
|
[lambdaisland.souk.json-ld :as ld]
|
|
[quoll.raphael.core :refer [parse]]
|
|
[org.domaindrivenarchitecture.fed-poc.common :as cm]
|
|
[clojure.spec.alpha :as s]
|
|
[orchestra.core :refer [defn-spec]]
|
|
[clojure.data.json :as json]
|
|
[clojure.inspector :as ins]
|
|
[hato.client :as hato]
|
|
[clojure.string :as st]
|
|
[clojure.walk :as walk]
|
|
[clojure.string :as str]
|
|
[lambdaisland.uri :as uri]))
|
|
|
|
(def team-url "https://social.meissa-gmbh.de/users/team")
|
|
(def outbox-url "https://social.meissa-gmbh.de/users/team/outbox")
|
|
(def like-url "https://www.w3.org/ns/activitystreams#Like")
|
|
(def name-url "https://www.w3.org/ns/activitystreams#name")
|
|
|
|
(def team-ld (:body (ld/json-get team-url)))
|
|
|
|
(def context-team (ld/expand-context (ld/fetch-context team-url)) )
|
|
(def context-like (ld/expand-context (ld/fetch-context like-url)))
|
|
|
|
(def team (ap/GET team-url))
|
|
|
|
(def parsed-rdf-syntax (parse (slurp cm/activitystreams-ttl)))
|
|
|
|
(defn type-string? [input]
|
|
(and (string? input)
|
|
(re-matches #"[A-Z]" (str (first input)))))
|
|
|
|
(defn url-string? [input]
|
|
(and (string? input)
|
|
(re-matches #"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)" input)))
|
|
|
|
(defn uri-string? [input]
|
|
(and (string? input)
|
|
(re-matches #"\w+:(\/?\/?)[^\s]+" input)))
|
|
|
|
(defn uri-vector? [input]
|
|
(and (every? #(uri-string? %) input)
|
|
(vector? input)))
|
|
|
|
(def context "@context")
|
|
(def type-string "type")
|
|
(def id-uri "id")
|
|
(def to-uri "to")
|
|
(def actor "actor")
|
|
(def object "object")
|
|
|
|
; Specs for a like
|
|
(s/def context uri-string?)
|
|
(s/def type-string type-string?)
|
|
(s/def id-uri uri-string?)
|
|
(s/def to-uri uri-vector?)
|
|
(s/def actor uri-string?)
|
|
(s/def object uri-string?)
|
|
|
|
(s/def ::to uri-vector?)
|
|
(s/def ::object string?)
|
|
(s/def ::from uri-string?)
|
|
|
|
(def like? (s/keys :req-un [context
|
|
type-string
|
|
to-uri
|
|
actor
|
|
object]))
|
|
|
|
(def like-data? (s/keys :req-un [::object ::from]))
|
|
|
|
(def activity-streams-context "https://www.w3.org/ns/activitystreams")
|
|
|
|
(def like-data
|
|
{:object "https://chatty.bla/ben/posts/234s23-2g34234-2hhj536"
|
|
:from "https://social.bla/alyssa"})
|
|
|
|
(defn generate-id-from-object [from]
|
|
(str from "out" "/" "sdfsd44243g324g3455"))
|
|
|
|
(defn-spec generate-like-map like?
|
|
[input-map like-data?]
|
|
(assoc {}
|
|
"@context" activity-streams-context
|
|
"id" (str (:from input-map) "#likes/" "RANDOMHASH")
|
|
"type" "Like"
|
|
"actor" (:from input-map)
|
|
"object" (:object input-map)))
|
|
|
|
(defn-spec write-json-ld string?
|
|
[input map?
|
|
filename string?]
|
|
(->
|
|
input
|
|
(json/write-str :escape-slash false)
|
|
(#(spit filename %))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; ToDo
|
|
; Prädikat das langString parsen/validieren kann, evtl auch für xsd:string
|
|
; Prädikat für Name und Person ausformulieren
|
|
|
|
|
|
|
|
|
|
;;(ins/inspect-tree team-ld)
|
|
;;(ins/inspect-tree team)
|
|
|
|
;(def xsd/string? string?)
|
|
;(defn rdf/langString? [value] (or (string? value)
|
|
; (regex mit @ )))
|
|
|
|
;(s/def ::activitystreams/name (s/or xsd/string?
|
|
; rdf/langString?)) |