mirror of https://gitlab.com/bashrc2/epicyon
Bookmarks search
parent
501885f5bb
commit
ea588262ef
38
daemon.py
38
daemon.py
|
@ -2852,7 +2852,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
elif searchStr.startswith('!'):
|
elif searchStr.startswith('!'):
|
||||||
# your post history search
|
# your post history search
|
||||||
nickname = getNicknameFromActor(actorStr)
|
nickname = getNicknameFromActor(actorStr)
|
||||||
searchStr = searchStr.replace('!', '').strip()
|
searchStr = searchStr.replace('!', '', 1).strip()
|
||||||
historyStr = \
|
historyStr = \
|
||||||
htmlHistorySearch(self.server.cssCache,
|
htmlHistorySearch(self.server.cssCache,
|
||||||
self.server.translate,
|
self.server.translate,
|
||||||
|
@ -2874,7 +2874,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.showPublishedDateOnly,
|
self.server.showPublishedDateOnly,
|
||||||
self.server.peertubeInstances,
|
self.server.peertubeInstances,
|
||||||
self.server.allowLocalNetworkAccess,
|
self.server.allowLocalNetworkAccess,
|
||||||
self.server.themeName)
|
self.server.themeName, 'outbox')
|
||||||
if historyStr:
|
if historyStr:
|
||||||
msg = historyStr.encode('utf-8')
|
msg = historyStr.encode('utf-8')
|
||||||
msglen = len(msg)
|
msglen = len(msg)
|
||||||
|
@ -2883,6 +2883,40 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._write(msg)
|
self._write(msg)
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
|
elif searchStr.startswith('-'):
|
||||||
|
# bookmark search
|
||||||
|
nickname = getNicknameFromActor(actorStr)
|
||||||
|
searchStr = searchStr.replace('-', '', 1).strip()
|
||||||
|
bookmarksStr = \
|
||||||
|
htmlHistorySearch(self.server.cssCache,
|
||||||
|
self.server.translate,
|
||||||
|
baseDir,
|
||||||
|
httpPrefix,
|
||||||
|
nickname,
|
||||||
|
domain,
|
||||||
|
searchStr,
|
||||||
|
maxPostsInFeed,
|
||||||
|
pageNumber,
|
||||||
|
self.server.projectVersion,
|
||||||
|
self.server.recentPostsCache,
|
||||||
|
self.server.maxRecentPosts,
|
||||||
|
self.server.session,
|
||||||
|
self.server.cachedWebfingers,
|
||||||
|
self.server.personCache,
|
||||||
|
port,
|
||||||
|
self.server.YTReplacementDomain,
|
||||||
|
self.server.showPublishedDateOnly,
|
||||||
|
self.server.peertubeInstances,
|
||||||
|
self.server.allowLocalNetworkAccess,
|
||||||
|
self.server.themeName, 'bookmarks')
|
||||||
|
if bookmarksStr:
|
||||||
|
msg = bookmarksStr.encode('utf-8')
|
||||||
|
msglen = len(msg)
|
||||||
|
self._login_headers('text/html',
|
||||||
|
msglen, callingDomain)
|
||||||
|
self._write(msg)
|
||||||
|
self.server.POSTbusy = False
|
||||||
|
return
|
||||||
elif ('@' in searchStr or
|
elif ('@' in searchStr or
|
||||||
('://' in searchStr and
|
('://' in searchStr and
|
||||||
hasUsersPath(searchStr))):
|
hasUsersPath(searchStr))):
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
"View": "View",
|
"View": "View",
|
||||||
"Stop blocking": "Stop blocking",
|
"Stop blocking": "Stop blocking",
|
||||||
"Enter an emoji name to search for": "Enter an emoji name to search for",
|
"Enter an emoji name to search for": "Enter an emoji name to search for",
|
||||||
"Enter an address, shared item, !history, #hashtag, *skill or :emoji: to search for": "Enter an address, shared item, !history, #hashtag, *skill or :emoji: to search for",
|
"Enter an address, shared item, !history, #hashtag, *skill or :emoji: to search for": "Enter an address, shared item, -bookmark, !history, #hashtag, *skill or :emoji: to search for",
|
||||||
"Go Back": "◀",
|
"Go Back": "◀",
|
||||||
"Moderation Information": "Moderation Information",
|
"Moderation Information": "Moderation Information",
|
||||||
"Suspended accounts": "Suspended accounts",
|
"Suspended accounts": "Suspended accounts",
|
||||||
|
|
56
utils.py
56
utils.py
|
@ -1678,6 +1678,59 @@ def isNewsPost(postJsonObject: {}) -> bool:
|
||||||
return postJsonObject.get('news')
|
return postJsonObject.get('news')
|
||||||
|
|
||||||
|
|
||||||
|
def _searchVirtualBoxPosts(baseDir: str, nickname: str, domain: str,
|
||||||
|
searchStr: str, maxResults: int,
|
||||||
|
boxName: str) -> []:
|
||||||
|
"""Searches through a virtual box, which is typically an index on the inbox
|
||||||
|
"""
|
||||||
|
indexFilename = \
|
||||||
|
baseDir + '/accounts/' + nickname + '@' + domain + '/' + \
|
||||||
|
boxName + '.index'
|
||||||
|
if boxName == 'bookmarks':
|
||||||
|
boxName = 'inbox'
|
||||||
|
path = baseDir + '/accounts/' + nickname + '@' + domain + '/' + boxName
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
return []
|
||||||
|
|
||||||
|
searchStr = searchStr.lower().strip()
|
||||||
|
|
||||||
|
if '+' in searchStr:
|
||||||
|
searchWords = searchStr.split('+')
|
||||||
|
for index in range(len(searchWords)):
|
||||||
|
searchWords[index] = searchWords[index].strip()
|
||||||
|
print('SEARCH: ' + str(searchWords))
|
||||||
|
else:
|
||||||
|
searchWords = [searchStr]
|
||||||
|
|
||||||
|
res = []
|
||||||
|
with open(indexFilename, 'r') as indexFile:
|
||||||
|
postFilename = 'start'
|
||||||
|
while postFilename:
|
||||||
|
postFilename = indexFile.readline()
|
||||||
|
if not postFilename:
|
||||||
|
break
|
||||||
|
if '.json' not in postFilename:
|
||||||
|
break
|
||||||
|
postFilename = path + '/' + postFilename.strip()
|
||||||
|
if not os.path.isfile(postFilename):
|
||||||
|
continue
|
||||||
|
with open(postFilename, 'r') as postFile:
|
||||||
|
data = postFile.read().lower()
|
||||||
|
|
||||||
|
notFound = False
|
||||||
|
for keyword in searchWords:
|
||||||
|
if keyword not in data:
|
||||||
|
notFound = True
|
||||||
|
break
|
||||||
|
if notFound:
|
||||||
|
continue
|
||||||
|
|
||||||
|
res.append(postFilename)
|
||||||
|
if len(res) >= maxResults:
|
||||||
|
return res
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
def searchBoxPosts(baseDir: str, nickname: str, domain: str,
|
def searchBoxPosts(baseDir: str, nickname: str, domain: str,
|
||||||
searchStr: str, maxResults: int,
|
searchStr: str, maxResults: int,
|
||||||
boxName='outbox') -> []:
|
boxName='outbox') -> []:
|
||||||
|
@ -1686,6 +1739,9 @@ def searchBoxPosts(baseDir: str, nickname: str, domain: str,
|
||||||
"""
|
"""
|
||||||
path = baseDir + '/accounts/' + nickname + '@' + domain + '/' + boxName
|
path = baseDir + '/accounts/' + nickname + '@' + domain + '/' + boxName
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
|
if os.path.isfile(path + '.index'):
|
||||||
|
return _searchVirtualBoxPosts(baseDir, nickname, domain,
|
||||||
|
searchStr, maxResults, boxName)
|
||||||
return []
|
return []
|
||||||
searchStr = searchStr.lower().strip()
|
searchStr = searchStr.lower().strip()
|
||||||
|
|
||||||
|
|
|
@ -536,7 +536,7 @@ def htmlHistorySearch(cssCache: {}, translate: {}, baseDir: str,
|
||||||
showPublishedDateOnly: bool,
|
showPublishedDateOnly: bool,
|
||||||
peertubeInstances: [],
|
peertubeInstances: [],
|
||||||
allowLocalNetworkAccess: bool,
|
allowLocalNetworkAccess: bool,
|
||||||
themeName: str) -> str:
|
themeName: str, boxName: str) -> str:
|
||||||
"""Show a page containing search results for your post history
|
"""Show a page containing search results for your post history
|
||||||
"""
|
"""
|
||||||
if historysearch.startswith('!'):
|
if historysearch.startswith('!'):
|
||||||
|
@ -546,7 +546,7 @@ def htmlHistorySearch(cssCache: {}, translate: {}, baseDir: str,
|
||||||
|
|
||||||
boxFilenames = \
|
boxFilenames = \
|
||||||
searchBoxPosts(baseDir, nickname, domain,
|
searchBoxPosts(baseDir, nickname, domain,
|
||||||
historysearch, postsPerPage)
|
historysearch, postsPerPage, boxName)
|
||||||
|
|
||||||
cssFilename = baseDir + '/epicyon-profile.css'
|
cssFilename = baseDir + '/epicyon-profile.css'
|
||||||
if os.path.isfile(baseDir + '/epicyon.css'):
|
if os.path.isfile(baseDir + '/epicyon.css'):
|
||||||
|
@ -560,10 +560,13 @@ def htmlHistorySearch(cssCache: {}, translate: {}, baseDir: str,
|
||||||
# add the page title
|
# add the page title
|
||||||
domainFull = getFullDomain(domain, port)
|
domainFull = getFullDomain(domain, port)
|
||||||
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||||
|
historySearchTitle = '🔍 ' + translate['Your Posts']
|
||||||
|
if boxName == 'tlbookmarks':
|
||||||
|
historySearchTitle = '🔍 ' + translate['Bookmarks']
|
||||||
|
|
||||||
historySearchForm += \
|
historySearchForm += \
|
||||||
'<center><h1><a href="' + actor + '/search">' + \
|
'<center><h1><a href="' + actor + '/search">' + \
|
||||||
translate['Your Posts'] + \
|
historySearchTitle + '</a></h1></center>'
|
||||||
'</a></h1></center>'
|
|
||||||
|
|
||||||
if len(boxFilenames) == 0:
|
if len(boxFilenames) == 0:
|
||||||
historySearchForm += \
|
historySearchForm += \
|
||||||
|
|
Loading…
Reference in New Issue