Bookmarks search

merge-requests/30/head
Bob Mottram 2021-05-03 23:31:06 +01:00
parent 501885f5bb
commit ea588262ef
4 changed files with 100 additions and 7 deletions

View File

@ -2852,7 +2852,7 @@ class PubServer(BaseHTTPRequestHandler):
elif searchStr.startswith('!'):
# your post history search
nickname = getNicknameFromActor(actorStr)
searchStr = searchStr.replace('!', '').strip()
searchStr = searchStr.replace('!', '', 1).strip()
historyStr = \
htmlHistorySearch(self.server.cssCache,
self.server.translate,
@ -2874,7 +2874,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.showPublishedDateOnly,
self.server.peertubeInstances,
self.server.allowLocalNetworkAccess,
self.server.themeName)
self.server.themeName, 'outbox')
if historyStr:
msg = historyStr.encode('utf-8')
msglen = len(msg)
@ -2883,6 +2883,40 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg)
self.server.POSTbusy = False
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
('://' in searchStr and
hasUsersPath(searchStr))):

View File

@ -90,7 +90,7 @@
"View": "View",
"Stop blocking": "Stop blocking",
"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": "◀",
"Moderation Information": "Moderation Information",
"Suspended accounts": "Suspended accounts",

View File

@ -1678,6 +1678,59 @@ def isNewsPost(postJsonObject: {}) -> bool:
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,
searchStr: str, maxResults: int,
boxName='outbox') -> []:
@ -1686,6 +1739,9 @@ def searchBoxPosts(baseDir: str, nickname: str, domain: str,
"""
path = baseDir + '/accounts/' + nickname + '@' + domain + '/' + boxName
if not os.path.isdir(path):
if os.path.isfile(path + '.index'):
return _searchVirtualBoxPosts(baseDir, nickname, domain,
searchStr, maxResults, boxName)
return []
searchStr = searchStr.lower().strip()

View File

@ -536,7 +536,7 @@ def htmlHistorySearch(cssCache: {}, translate: {}, baseDir: str,
showPublishedDateOnly: bool,
peertubeInstances: [],
allowLocalNetworkAccess: bool,
themeName: str) -> str:
themeName: str, boxName: str) -> str:
"""Show a page containing search results for your post history
"""
if historysearch.startswith('!'):
@ -546,7 +546,7 @@ def htmlHistorySearch(cssCache: {}, translate: {}, baseDir: str,
boxFilenames = \
searchBoxPosts(baseDir, nickname, domain,
historysearch, postsPerPage)
historysearch, postsPerPage, boxName)
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
@ -560,10 +560,13 @@ def htmlHistorySearch(cssCache: {}, translate: {}, baseDir: str,
# add the page title
domainFull = getFullDomain(domain, port)
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
historySearchTitle = '🔍 ' + translate['Your Posts']
if boxName == 'tlbookmarks':
historySearchTitle = '🔍 ' + translate['Bookmarks']
historySearchForm += \
'<center><h1><a href="' + actor + '/search">' + \
translate['Your Posts'] + \
'</a></h1></center>'
historySearchTitle + '</a></h1></center>'
if len(boxFilenames) == 0:
historySearchForm += \