Mercurial > libervia-backend
annotate sat/plugins/plugin_comp_ap_gateway/constants.py @ 3886:1f88ca90c3de
plugin XEP-0444: Message Reactions implementation:
rel 371
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 31 Aug 2022 17:07:03 +0200 |
parents | 59fbb66b2923 |
children | aa7197b67c26 |
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}" |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 CONTENT_TYPE_AP = "application/activity+json; charset=utf-8" |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 TYPE_ACTOR = "actor" |
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 TYPE_INBOX = "inbox" |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
25 TYPE_SHARED_INBOX = "shared_inbox" |
3728
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
26 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
|
27 TYPE_FOLLOWERS = "followers" |
125c7043b277
comp AP gateway: publish, (un)subscribe/(un)follow, public subscription/following/followers:
Goffi <goffi@goffi.org>
parents:
3745
diff
changeset
|
28 TYPE_FOLLOWING = "following" |
3682
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 TYPE_ITEM = "item" |
3792
865167c34b82
comp AP gateway: convert pubsub item retractation to AP `Delete` activity:
Goffi <goffi@goffi.org>
parents:
3784
diff
changeset
|
30 TYPE_TOMBSTONE = "Tombstone" |
3832
201a22bfbb74
component AP gateway: convert AP mention to XEP-0372 mentions:
Goffi <goffi@goffi.org>
parents:
3824
diff
changeset
|
31 TYPE_MENTION = "Mention" |
3865
59fbb66b2923
component AP gateway: handle XMPP attachments -> AP likes conversion:
Goffi <goffi@goffi.org>
parents:
3846
diff
changeset
|
32 TYPE_LIKE = "Like" |
3682
7c990aaa49d3
comp AP Gateway: ActivityPub Component first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 MEDIA_TYPE_AP = "application/activity+json" |
3846
cc13efdd8360
component AP gateway: return item when `item` URL is used:
Goffi <goffi@goffi.org>
parents:
3844
diff
changeset
|
34 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
|
35 NS_AP_PUBLIC = f"{NS_AP}#Public" |
3784
efc34a89e70b
comp AP gateway: message conversion:
Goffi <goffi@goffi.org>
parents:
3764
diff
changeset
|
36 # 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
|
37 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
|
38 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
|
39 "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
|
40 "POST": {"inbox"}, |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
41 } |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
42 # headers to check for signature |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
43 SIGN_HEADERS = { |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
44 # headers needed for all HTTP methods |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
45 None: [ |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
46 # 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
|
47 ("date", "(created)"), |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
48 ("digest", "(request-target)"), |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
49 ], |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
50 b"GET": ["host"], |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
51 b"POST": ["digest"] |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
52 } |
3728
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
53 PAGE_SIZE = 10 |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
54 HS2019 = "hs2019" |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
55 # delay after which a signed request is not accepted anymore |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
56 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
|
57 |
b15644cae50d
component AP gateway: JID/node ⟺ AP outbox conversion:
Goffi <goffi@goffi.org>
parents:
3684
diff
changeset
|
58 LRU_MAX_SIZE = 200 |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
59 ACTIVITY_TYPES = ( |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
60 "Accept", "Add", "Announce", "Arrive", "Block", "Create", "Delete", "Dislike", "Flag", |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
61 "Follow", "Ignore", "Invite", "Join", "Leave", "Like", "Listen", "Move", "Offer", |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
62 "Question", "Reject", "Read", "Remove", "TentativeReject", "TentativeAccept", |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
63 "Travel", "Undo", "Update", "View" |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
64 ) |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
65 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
|
66 ACTIVITY_OBJECT_MANDATORY = ( |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
67 "Create", "Update", "Delete", "Follow", "Add", "Remove", "Like", "Block", "Undo" |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
68 ) |
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
69 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
|
70 # 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
|
71 # must be lowercase |
3844
65e5718e7710
component AP gateway: `Announce` activity implementation:
Goffi <goffi@goffi.org>
parents:
3833
diff
changeset
|
72 ACTIVIY_NO_ACCOUNT_ALLOWED = ("create", "delete", "announce", "undo") |
3745
a8c7e5cef0cb
comp AP gateway: signature checking, caching and threads management:
Goffi <goffi@goffi.org>
parents:
3729
diff
changeset
|
73 # 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
|
74 COMMENTS_MAX_PARENTS = 100 |
3824
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
75 # maximum size of avatar, in bytes |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
76 MAX_AVATAR_SIZE = 1024 * 1024 * 5 |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
77 |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
78 # storage prefixes |
6329ee6b6df4
component AP: convert AP identity data to XMPP:
Goffi <goffi@goffi.org>
parents:
3793
diff
changeset
|
79 ST_AVATAR = "[avatar]" |