package activitypub_client

  1. Overview
  2. Docs

Source file conf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(*********************************************************************************)
(*                OCaml-ActivityPub                                              *)
(*                                                                               *)
(*    Copyright (C) 2023-2024 INRIA All rights reserved.                         *)
(*    Author: Maxence Guesdon, INRIA Saclay                                      *)
(*                                                                               *)
(*    This program is free software; you can redistribute it and/or modify       *)
(*    it under the terms of the GNU Lesser General Public License version        *)
(*    3 as published by the Free Software Foundation.                            *)
(*                                                                               *)
(*    This program is distributed in the hope that it will be useful,            *)
(*    but WITHOUT ANY WARRANTY; without even the implied warranty of             *)
(*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *)
(*    GNU General Public License for more details.                               *)
(*                                                                               *)
(*    You should have received a copy of the GNU General Public License          *)
(*    along with this program; if not, write to the Free Software                *)
(*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA                   *)
(*    02111-1307  USA                                                            *)
(*                                                                               *)
(*    Contact: maxence.guesdon@inria.fr                                          *)
(*                                                                               *)
(*********************************************************************************)

(** Client configuration *)

module AP = Activitypub

let iri_map_wrapper w =
  let to_json ?with_doc map =
    let f iri json acc =
      (Iri.to_string iri, w.Ocf.Wrapper.to_json json) :: acc
    in
    `Assoc (Iri.Map.fold f map [])
  in
  let from_json ?def = function
  | `Assoc l ->
      begin
        let f map (key, json) =
          let v = w.Ocf.Wrapper.from_json json in
          Iri.Map.add (Iri.of_string key) v map
        in
        List.fold_left f Iri.Map.empty l
      end
  | json -> Ocf.invalid_value json
  in
  Ocf.Wrapper.make to_json from_json

(** Configuration to act as an actor. *)
type actor = {
    jsonld_cache_dir : string option [@ocf Ocf.Wrapper.option AP.Utils.filename_wrapper, None]
      (** directory to cache json-ld contexts *) ;

    cache_dir : string option [@ocf Ocf.Wrapper.option AP.Utils.filename_wrapper, None]
      (** directory to cache remote resources *) ;

    cache_delay : int [@ocf Ocf.Wrapper.int, 3600] (** cache validity delay *) ;

    mutable token : string option [@ocf Ocf.Wrapper.(option string), None ]
     (** token used to authenticate to server *) ;

    media_post_iri : Iri.t option [@ocf Ocf.Wrapper.(option AP.Utils.iri_wrapper), None ]
      (** IRI used to post attachment files, retrieving IRIs to use in activities *) ;
  } [@@ocf]

(** A configuration of a client can handle multiple actors. *)
type t = {
  actors : actor Iri.Map.t [@ocf iri_map_wrapper actor_wrapper, Iri.Map.empty ] ;
} [@@ocf]