mirror of https://gitlab.com/bashrc2/epicyon
Move announce button to its own method
parent
6b32fdb0a0
commit
3fbc75ae97
196
daemon.py
196
daemon.py
|
@ -4042,6 +4042,100 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'login shown done',
|
'login shown done',
|
||||||
'hashtag search')
|
'hashtag search')
|
||||||
|
|
||||||
|
def _announceButton(self, callingDomain: str, path: str,
|
||||||
|
baseDir: str,
|
||||||
|
cookie: str, proxyType: str,
|
||||||
|
httpPrefix: str,
|
||||||
|
domain: str, domainFull: str, port: int,
|
||||||
|
onionDomain: str, i2pDomain: str,
|
||||||
|
GETstartTime, GETtimings: {},
|
||||||
|
repeatPrivate: bool, debug: bool):
|
||||||
|
"""The announce/repeat button was pressed on a post
|
||||||
|
"""
|
||||||
|
pageNumber = 1
|
||||||
|
repeatUrl = path.split('?repeat=')[1]
|
||||||
|
if '?' in repeatUrl:
|
||||||
|
repeatUrl = repeatUrl.split('?')[0]
|
||||||
|
timelineBookmark = ''
|
||||||
|
if '?bm=' in path:
|
||||||
|
timelineBookmark = path.split('?bm=')[1]
|
||||||
|
if '?' in timelineBookmark:
|
||||||
|
timelineBookmark = timelineBookmark.split('?')[0]
|
||||||
|
timelineBookmark = '#' + timelineBookmark
|
||||||
|
if '?page=' in path:
|
||||||
|
pageNumberStr = path.split('?page=')[1]
|
||||||
|
if '?' in pageNumberStr:
|
||||||
|
pageNumberStr = pageNumberStr.split('?')[0]
|
||||||
|
if '#' in pageNumberStr:
|
||||||
|
pageNumberStr = pageNumberStr.split('#')[0]
|
||||||
|
if pageNumberStr.isdigit():
|
||||||
|
pageNumber = int(pageNumberStr)
|
||||||
|
timelineStr = 'inbox'
|
||||||
|
if '?tl=' in path:
|
||||||
|
timelineStr = path.split('?tl=')[1]
|
||||||
|
if '?' in timelineStr:
|
||||||
|
timelineStr = timelineStr.split('?')[0]
|
||||||
|
actor = path.split('?repeat=')[0]
|
||||||
|
self.postToNickname = getNicknameFromActor(actor)
|
||||||
|
if not self.postToNickname:
|
||||||
|
print('WARN: unable to find nickname in ' + actor)
|
||||||
|
self.server.GETbusy = False
|
||||||
|
actorAbsolute = \
|
||||||
|
httpPrefix + '://' + domainFull + actor
|
||||||
|
if callingDomain.endswith('.onion') and onionDomain:
|
||||||
|
actorAbsolute = 'http://' + onionDomain + actor
|
||||||
|
elif (callingDomain.endswith('.i2p') and i2pDomain):
|
||||||
|
actorAbsolute = 'http://' + i2pDomain + actor
|
||||||
|
self._redirect_headers(actorAbsolute + '/' + timelineStr +
|
||||||
|
'?page=' + str(pageNumber), cookie,
|
||||||
|
callingDomain)
|
||||||
|
return
|
||||||
|
if not self.server.session:
|
||||||
|
print('Starting new session during repeat button')
|
||||||
|
self.server.session = createSession(proxyType)
|
||||||
|
if not self.server.session:
|
||||||
|
print('ERROR: GET failed to create session ' +
|
||||||
|
'during repeat button')
|
||||||
|
self._404()
|
||||||
|
self.server.GETbusy = False
|
||||||
|
return
|
||||||
|
self.server.actorRepeat = path.split('?actor=')[1]
|
||||||
|
announceToStr = \
|
||||||
|
httpPrefix + '://' + domainFull + '/users/' + \
|
||||||
|
self.postToNickname + '/followers'
|
||||||
|
if not repeatPrivate:
|
||||||
|
announceToStr = 'https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
announceJson = \
|
||||||
|
createAnnounce(self.server.session,
|
||||||
|
baseDir,
|
||||||
|
self.server.federationList,
|
||||||
|
self.postToNickname,
|
||||||
|
domain, port,
|
||||||
|
announceToStr,
|
||||||
|
None, httpPrefix,
|
||||||
|
repeatUrl, False, False,
|
||||||
|
self.server.sendThreads,
|
||||||
|
self.server.postLog,
|
||||||
|
self.server.personCache,
|
||||||
|
self.server.cachedWebfingers,
|
||||||
|
debug,
|
||||||
|
self.server.projectVersion)
|
||||||
|
if announceJson:
|
||||||
|
self._postToOutboxThread(announceJson)
|
||||||
|
self.server.GETbusy = False
|
||||||
|
actorAbsolute = httpPrefix + '://' + domainFull + actor
|
||||||
|
if callingDomain.endswith('.onion') and onionDomain:
|
||||||
|
actorAbsolute = 'http://' + onionDomain + actor
|
||||||
|
elif callingDomain.endswith('.i2p') and i2pDomain:
|
||||||
|
actorAbsolute = 'http://' + i2pDomain + actor
|
||||||
|
self._redirect_headers(actorAbsolute + '/' +
|
||||||
|
timelineStr + '?page=' +
|
||||||
|
str(pageNumber) +
|
||||||
|
timelineBookmark, cookie, callingDomain)
|
||||||
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
'emoji search shown done',
|
||||||
|
'show announce')
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
callingDomain = self.server.domainFull
|
callingDomain = self.server.domainFull
|
||||||
if self.headers.get('Host'):
|
if self.headers.get('Host'):
|
||||||
|
@ -5217,98 +5311,20 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if htmlGET and '?repeatprivate=' in self.path:
|
if htmlGET and '?repeatprivate=' in self.path:
|
||||||
repeatPrivate = True
|
repeatPrivate = True
|
||||||
self.path = self.path.replace('?repeatprivate=', '?repeat=')
|
self.path = self.path.replace('?repeatprivate=', '?repeat=')
|
||||||
# announce/repeat from the web interface
|
# announce/repeat button was pressed
|
||||||
if htmlGET and '?repeat=' in self.path:
|
if htmlGET and '?repeat=' in self.path:
|
||||||
pageNumber = 1
|
self._announceButton(callingDomain, self.path,
|
||||||
repeatUrl = self.path.split('?repeat=')[1]
|
|
||||||
if '?' in repeatUrl:
|
|
||||||
repeatUrl = repeatUrl.split('?')[0]
|
|
||||||
timelineBookmark = ''
|
|
||||||
if '?bm=' in self.path:
|
|
||||||
timelineBookmark = self.path.split('?bm=')[1]
|
|
||||||
if '?' in timelineBookmark:
|
|
||||||
timelineBookmark = timelineBookmark.split('?')[0]
|
|
||||||
timelineBookmark = '#' + timelineBookmark
|
|
||||||
if '?page=' in self.path:
|
|
||||||
pageNumberStr = self.path.split('?page=')[1]
|
|
||||||
if '?' in pageNumberStr:
|
|
||||||
pageNumberStr = pageNumberStr.split('?')[0]
|
|
||||||
if '#' in pageNumberStr:
|
|
||||||
pageNumberStr = pageNumberStr.split('#')[0]
|
|
||||||
if pageNumberStr.isdigit():
|
|
||||||
pageNumber = int(pageNumberStr)
|
|
||||||
timelineStr = 'inbox'
|
|
||||||
if '?tl=' in self.path:
|
|
||||||
timelineStr = self.path.split('?tl=')[1]
|
|
||||||
if '?' in timelineStr:
|
|
||||||
timelineStr = timelineStr.split('?')[0]
|
|
||||||
actor = self.path.split('?repeat=')[0]
|
|
||||||
self.postToNickname = getNicknameFromActor(actor)
|
|
||||||
if not self.postToNickname:
|
|
||||||
print('WARN: unable to find nickname in ' + actor)
|
|
||||||
self.server.GETbusy = False
|
|
||||||
actorAbsolute = \
|
|
||||||
self.server.httpPrefix + '://' + \
|
|
||||||
self.server.domainFull+actor
|
|
||||||
if callingDomain.endswith('.onion') and \
|
|
||||||
self.server.onionDomain:
|
|
||||||
actorAbsolute = 'http://' + self.server.onionDomain + actor
|
|
||||||
elif (callingDomain.endswith('.i2p') and
|
|
||||||
self.server.i2pDomain):
|
|
||||||
actorAbsolute = 'http://' + self.server.i2pDomain + actor
|
|
||||||
self._redirect_headers(actorAbsolute + '/' + timelineStr +
|
|
||||||
'?page=' + str(pageNumber), cookie,
|
|
||||||
callingDomain)
|
|
||||||
return
|
|
||||||
if not self.server.session:
|
|
||||||
print('Starting new session during repeat button')
|
|
||||||
self.server.session = createSession(self.server.proxyType)
|
|
||||||
if not self.server.session:
|
|
||||||
print('ERROR: GET failed to create session ' +
|
|
||||||
'during repeat button')
|
|
||||||
self._404()
|
|
||||||
self.server.GETbusy = False
|
|
||||||
return
|
|
||||||
self.server.actorRepeat = self.path.split('?actor=')[1]
|
|
||||||
announceToStr = \
|
|
||||||
self.server.httpPrefix + '://' + \
|
|
||||||
self.server.domain + '/users/' + \
|
|
||||||
self.postToNickname + '/followers'
|
|
||||||
if not repeatPrivate:
|
|
||||||
announceToStr = 'https://www.w3.org/ns/activitystreams#Public'
|
|
||||||
announceJson = \
|
|
||||||
createAnnounce(self.server.session,
|
|
||||||
self.server.baseDir,
|
self.server.baseDir,
|
||||||
self.server.federationList,
|
cookie, self.server.proxyType,
|
||||||
self.postToNickname,
|
self.server.httpPrefix,
|
||||||
self.server.domain, self.server.port,
|
self.server.domain,
|
||||||
announceToStr,
|
self.server.domainFull,
|
||||||
None, self.server.httpPrefix,
|
self.server.port,
|
||||||
repeatUrl, False, False,
|
self.server.onionDomain,
|
||||||
self.server.sendThreads,
|
self.server.i2pDomain,
|
||||||
self.server.postLog,
|
GETstartTime, GETtimings,
|
||||||
self.server.personCache,
|
repeatPrivate,
|
||||||
self.server.cachedWebfingers,
|
self.server.debug)
|
||||||
self.server.debug,
|
|
||||||
self.server.projectVersion)
|
|
||||||
if announceJson:
|
|
||||||
self._postToOutboxThread(announceJson)
|
|
||||||
self.server.GETbusy = False
|
|
||||||
actorAbsolute = self.server.httpPrefix + '://' + \
|
|
||||||
self.server.domainFull + actor
|
|
||||||
if callingDomain.endswith('.onion') and \
|
|
||||||
self.server.onionDomain:
|
|
||||||
actorAbsolute = 'http://' + self.server.onionDomain + actor
|
|
||||||
elif (callingDomain.endswith('.i2p') and
|
|
||||||
self.server.i2pDomain):
|
|
||||||
actorAbsolute = 'http://' + self.server.i2pDomain + actor
|
|
||||||
self._redirect_headers(actorAbsolute + '/' +
|
|
||||||
timelineStr + '?page=' +
|
|
||||||
str(pageNumber) +
|
|
||||||
timelineBookmark, cookie, callingDomain)
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
|
||||||
'emoji search shown done',
|
|
||||||
'show announce')
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||||
|
|
Loading…
Reference in New Issue