Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_comp_ap_gateway/constants.py @ 4322:00837fa13e5a default tip @
tools (common/template), cli (call/gui): use font-awesome instead of fontello:
following change in Libervia Media, code has been updated to use font-awesome now instead
of fontello.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Oct 2024 22:42:17 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3682
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia ActivityPub Gateway |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 IMPORT_NAME = "ap-gateway" |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 CONF_SECTION = f"component {IMPORT_NAME}" |
4105
ec9bed9df74f
compoent AP gateway: add forgotten contant
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
22 CONTENT_TYPE_WEBFINGER = "application/jrd+json; charset=utf-8" |
3682
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 CONTENT_TYPE_AP = "application/activity+json; charset=utf-8" |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 TYPE_ACTOR = "actor" |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 TYPE_INBOX = "inbox" |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
26 TYPE_SHARED_INBOX = "shared_inbox" |
3728
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
27 TYPE_OUTBOX = "outbox" |
3764
125c7043b277
comp AP gateway: publish, (un)subscribe/(un)follow, public subscription/following/followers:
Goffi <goffi@goffi.org>
parents:
3745
diff
changeset
|
28 TYPE_FOLLOWERS = "followers" |
125c7043b277
comp AP gateway: publish, (un)subscribe/(un)follow, public subscription/following/followers:
Goffi <goffi@goffi.org>
parents:
3745
diff
changeset
|
29 TYPE_FOLLOWING = "following" |
3682
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 TYPE_ITEM = "item" |
3792
865167c34b82
comp AP gateway: convert pubsub item retractation to AP `Delete` activity:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
31 TYPE_TOMBSTONE = "Tombstone" |
3832
201a22bfbb74
component AP gateway: convert AP mention to XEP-0372 mentions:
Goffi <goffi@goffi.org>
parents:
3824
diff
changeset
|
32 TYPE_MENTION = "Mention" |
3865
59fbb66b2923
component AP gateway: handle XMPP attachments -> AP likes conversion:
Goffi <goffi@goffi.org>
parents:
3846
diff
changeset
|
33 TYPE_LIKE = "Like" |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
34 TYPE_REACTION = "EmojiReact" |
3904 | 35 TYPE_EVENT = "Event" |
36 TYPE_JOIN = "Join" | |
37 TYPE_LEAVE = "Leave" | |
4109
7067b0d73183
component AP gateway: fix AP media type in GET and POST requests headers
Goffi <goffi@goffi.org>
parents:
4105
diff
changeset
|
38 MEDIA_TYPE_AP = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' |
7067b0d73183
component AP gateway: fix AP media type in GET and POST requests headers
Goffi <goffi@goffi.org>
parents:
4105
diff
changeset
|
39 MEDIA_TYPE_AP_ALT = "application/activity+json" |
3846
cc13efdd8360
component AP gateway: return item when `item` URL is used:
Goffi <goffi@goffi.org>
parents:
3844
diff
changeset
|
40 NS_AP = "https://www.w3.org/ns/activitystreams" |
cc13efdd8360
component AP gateway: return item when `item` URL is used:
Goffi <goffi@goffi.org>
parents:
3844
diff
changeset
|
41 NS_AP_PUBLIC = f"{NS_AP}#Public" |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3764
diff
changeset
|
42 # 3 values can be used, see https://www.w3.org/TR/activitypub/#public-addressing |
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3764
diff
changeset
|
43 PUBLIC_TUPLE = (NS_AP_PUBLIC, "as:Public", "Public") |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
44 AP_REQUEST_TYPES = { |
3764
125c7043b277
comp AP gateway: publish, (un)subscribe/(un)follow, public subscription/following/followers:
Goffi <goffi@goffi.org>
parents:
3745
diff
changeset
|
45 "GET": {TYPE_ACTOR, TYPE_OUTBOX, TYPE_FOLLOWERS, TYPE_FOLLOWING}, |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
46 "POST": {"inbox"}, |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
47 } |
4012
d538b07cddf3
plugin AP gateway: fix exception on HEAD requests
Goffi <goffi@goffi.org>
parents:
3904
diff
changeset
|
48 AP_REQUEST_TYPES["HEAD"] = AP_REQUEST_TYPES["GET"] |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
49 # headers to check for signature |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
50 SIGN_HEADERS = { |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
51 # headers needed for all HTTP methods |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
52 None: [ |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
53 # tuples are equivalent headers/pseudo headers, one of them must be present |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
54 ("date", "(created)"), |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
55 ("digest", "(request-target)"), |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
56 ], |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
57 b"GET": ["host"], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
58 b"POST": ["digest"], |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
59 } |
3728
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
60 PAGE_SIZE = 10 |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
61 HS2019 = "hs2019" |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
62 # delay after which a signed request is not accepted anymore |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
63 SIGN_EXP = 12 * 60 * 60 # 12 hours (same value as for Mastodon) |
3728
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
64 |
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
65 LRU_MAX_SIZE = 200 |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
66 ACTIVITY_TYPES = ( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
67 "Accept", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
68 "Add", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
69 "Announce", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
70 "Arrive", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
71 "Block", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
72 "Create", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
73 "Delete", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
74 "Dislike", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
75 "Flag", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
76 "Follow", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
77 "Ignore", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
78 "Invite", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
79 "Join", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
80 "Leave", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
81 "Like", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
82 "Listen", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
83 "Move", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
84 "Offer", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
85 "Question", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
86 "Reject", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
87 "Read", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
88 "Remove", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
89 "TentativeReject", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
90 "TentativeAccept", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
91 "Travel", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
92 "Undo", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
93 "Update", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
94 "View", |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
95 # non-standard activities |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
96 "EmojiReact", |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
97 ) |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
98 ACTIVITY_TYPES_LOWER = [a.lower() for a in ACTIVITY_TYPES] |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
99 ACTIVITY_OBJECT_MANDATORY = ( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
100 "Create", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
101 "Update", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
102 "Delete", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
103 "Follow", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
104 "Add", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
105 "Remove", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
106 "Like", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
107 "Block", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
108 "Undo", |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
109 ) |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
110 ACTIVITY_TARGET_MANDATORY = ("Add", "Remove") |
3793
b5c9021020df
component AP gateway: convert `Delete` AP activities to corresponding Pubsub `retract`:
Goffi <goffi@goffi.org>
parents:
3792
diff
changeset
|
111 # activities which can be used with Shared Inbox (i.e. with no account specified) |
b5c9021020df
component AP gateway: convert `Delete` AP activities to corresponding Pubsub `retract`:
Goffi <goffi@goffi.org>
parents:
3792
diff
changeset
|
112 # must be lowercase |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
113 ACTIVIY_NO_ACCOUNT_ALLOWED = ( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
114 "create", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
115 "update", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
116 "delete", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
117 "announce", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
118 "undo", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
119 "like", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
120 "emojireact", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
121 "join", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4109
diff
changeset
|
122 "leave", |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
123 ) |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
124 # maximum number of parents to retrieve when comments_max_depth option is set |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
125 COMMENTS_MAX_PARENTS = 100 |
3824
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
126 # maximum size of avatar, in bytes |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
127 MAX_AVATAR_SIZE = 1024 * 1024 * 5 |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
128 |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
129 # storage prefixes |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
130 ST_AVATAR = "[avatar]" |
3888
aa7197b67c26
component AP gateway: AP <=> XMPP reactions conversions:
Goffi <goffi@goffi.org>
parents:
3865
diff
changeset
|
131 ST_AP_CACHE = "[AP_item_cache]" |