mirror of https://gitlab.com/bashrc2/epicyon
Pinned post endpoint
parent
402206b85c
commit
2b1bb3e82f
34
daemon.py
34
daemon.py
|
@ -68,6 +68,8 @@ from person import removeAccount
|
||||||
from person import canRemovePost
|
from person import canRemovePost
|
||||||
from person import personSnooze
|
from person import personSnooze
|
||||||
from person import personUnsnooze
|
from person import personUnsnooze
|
||||||
|
from posts import outboxMessageCreateWrap
|
||||||
|
from posts import getPinnedPostAsJson
|
||||||
from posts import pinPost
|
from posts import pinPost
|
||||||
from posts import jsonPinPost
|
from posts import jsonPinPost
|
||||||
from posts import undoPinnedPost
|
from posts import undoPinnedPost
|
||||||
|
@ -10150,7 +10152,34 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if '/users/' in self.path:
|
if '/users/' in self.path:
|
||||||
usersInPath = True
|
usersInPath = True
|
||||||
|
|
||||||
if usersInPath and self.path.endswith('/collections/featured'):
|
if not htmlGET and \
|
||||||
|
usersInPath and self.path.endswith('/pinned'):
|
||||||
|
nickname = self.path.split('/users/')[1]
|
||||||
|
if '/' in nickname:
|
||||||
|
nickname = nickname.split('/')[0]
|
||||||
|
pinnedPostJson = \
|
||||||
|
getPinnedPostAsJson(self.server.baseDir,
|
||||||
|
self.server.httpPrefix,
|
||||||
|
nickname, self.server.domain,
|
||||||
|
self.server.domainFull)
|
||||||
|
messageJson = {}
|
||||||
|
if pinnedPostJson:
|
||||||
|
messageJson = \
|
||||||
|
outboxMessageCreateWrap(self.server.httpPrefix,
|
||||||
|
nickname,
|
||||||
|
self.server.domain,
|
||||||
|
self.server.port,
|
||||||
|
pinnedPostJson)
|
||||||
|
msg = json.dumps(messageJson,
|
||||||
|
ensure_ascii=False).encode('utf-8')
|
||||||
|
msglen = len(msg)
|
||||||
|
self._set_headers('application/json',
|
||||||
|
msglen, None, callingDomain)
|
||||||
|
self._write(msg)
|
||||||
|
return
|
||||||
|
|
||||||
|
if not htmlGET and \
|
||||||
|
usersInPath and self.path.endswith('/collections/featured'):
|
||||||
nickname = self.path.split('/users/')[1]
|
nickname = self.path.split('/users/')[1]
|
||||||
if '/' in nickname:
|
if '/' in nickname:
|
||||||
nickname = nickname.split('/')[0]
|
nickname = nickname.split('/')[0]
|
||||||
|
@ -10162,7 +10191,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.domainFull)
|
self.server.domainFull)
|
||||||
return
|
return
|
||||||
|
|
||||||
if usersInPath and self.path.endswith('/collections/featuredTags'):
|
if not htmlGET and \
|
||||||
|
usersInPath and self.path.endswith('/collections/featuredTags'):
|
||||||
self._getFeaturedTagsCollection(callingDomain,
|
self._getFeaturedTagsCollection(callingDomain,
|
||||||
self.path,
|
self.path,
|
||||||
self.server.httpPrefix,
|
self.server.httpPrefix,
|
||||||
|
|
27
posts.py
27
posts.py
|
@ -1298,14 +1298,13 @@ def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None:
|
||||||
os.remove(pinnedFilename)
|
os.remove(pinnedFilename)
|
||||||
|
|
||||||
|
|
||||||
def jsonPinPost(baseDir: str, httpPrefix: str,
|
def getPinnedPostAsJson(baseDir: str, httpPrefix: str,
|
||||||
nickname: str, domain: str,
|
nickname: str, domain: str,
|
||||||
domainFull: str) -> {}:
|
domainFull: str) -> {}:
|
||||||
"""Returns a pinned post as json
|
"""Returns the pinned profile post as json
|
||||||
"""
|
"""
|
||||||
accountDir = baseDir + '/accounts/' + nickname + '@' + domain
|
accountDir = baseDir + '/accounts/' + nickname + '@' + domain
|
||||||
pinnedFilename = accountDir + '/pinToProfile.txt'
|
pinnedFilename = accountDir + '/pinToProfile.txt'
|
||||||
itemsList = []
|
|
||||||
pinnedPostJson = {}
|
pinnedPostJson = {}
|
||||||
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||||
if os.path.isfile(pinnedFilename):
|
if os.path.isfile(pinnedFilename):
|
||||||
|
@ -1338,7 +1337,23 @@ def jsonPinPost(baseDir: str, httpPrefix: str,
|
||||||
'type': 'Note',
|
'type': 'Note',
|
||||||
'url': actor.replace('/users/', '/@') + '/pinned'
|
'url': actor.replace('/users/', '/@') + '/pinned'
|
||||||
}
|
}
|
||||||
itemsList = [pinnedPostJson]
|
return pinnedPostJson
|
||||||
|
|
||||||
|
|
||||||
|
def jsonPinPost(baseDir: str, httpPrefix: str,
|
||||||
|
nickname: str, domain: str,
|
||||||
|
domainFull: str) -> {}:
|
||||||
|
"""Returns a pinned post as json
|
||||||
|
"""
|
||||||
|
pinnedPostJson = \
|
||||||
|
getPinnedPostAsJson(baseDir, httpPrefix,
|
||||||
|
nickname, domain,
|
||||||
|
domainFull)
|
||||||
|
itemsList = []
|
||||||
|
if pinnedPostJson:
|
||||||
|
itemsList = [pinnedPostJson]
|
||||||
|
|
||||||
|
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||||
return {
|
return {
|
||||||
'@context': [
|
'@context': [
|
||||||
'https://www.w3.org/ns/activitystreams',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
|
|
Loading…
Reference in New Issue