mirror of https://gitlab.com/bashrc2/epicyon
Optionally limit skills searches to the instance
parent
7b6f2a6468
commit
8745f1e063
|
@ -2515,7 +2515,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
searchStr=searchStr.replace('*','').strip()
|
||||
skillStr= \
|
||||
htmlSkillsSearch(self.server.baseDir,searchStr, \
|
||||
self.server.domainFull, \
|
||||
self.server.instanceOnlySkillsSearch, \
|
||||
maxPostsInFeed)
|
||||
if skillStr:
|
||||
msg=skillStr.encode('utf-8')
|
||||
|
@ -3135,7 +3135,8 @@ def runDaemon(projectVersion, \
|
|||
noannounce=False,cw=False,ocapAlways=False, \
|
||||
useTor=False,maxReplies=64, \
|
||||
domainMaxPostsPerDay=8640,accountMaxPostsPerDay=8640, \
|
||||
allowDeletion=False,debug=False,unitTest=False) -> None:
|
||||
allowDeletion=False,debug=False,unitTest=False, \
|
||||
instanceOnlySkillsSearch=False) -> None:
|
||||
if len(domain)==0:
|
||||
domain='localhost'
|
||||
if '.' not in domain:
|
||||
|
@ -3187,6 +3188,7 @@ def runDaemon(projectVersion, \
|
|||
httpd.salts={}
|
||||
httpd.tokens={}
|
||||
httpd.tokensLookup={}
|
||||
httpd.instanceOnlySkillsSearch=instanceOnlySkillsSearch
|
||||
httpd.acceptedCaps=["inbox:write","objects:read"]
|
||||
if noreply:
|
||||
httpd.acceptedCaps.append('inbox:noreply')
|
||||
|
|
|
@ -129,6 +129,9 @@ parser.add_argument('-f','--federate', nargs='+',dest='federationList', \
|
|||
parser.add_argument("--debug", type=str2bool, nargs='?', \
|
||||
const=True, default=False, \
|
||||
help="Show debug messages")
|
||||
parser.add_argument("--instanceOnlySkillsSearch", type=str2bool, nargs='?', \
|
||||
const=True, default=False, \
|
||||
help="Skills searches only return results from this instance")
|
||||
parser.add_argument("--http", type=str2bool, nargs='?', \
|
||||
const=True, default=False, \
|
||||
help="Use http only")
|
||||
|
@ -1309,4 +1312,5 @@ runDaemon(__version__, \
|
|||
args.noannounce,args.cw,ocapAlways, \
|
||||
useTor,args.maxReplies, \
|
||||
args.domainMaxPostsPerDay,args.accountMaxPostsPerDay, \
|
||||
args.allowdeletion,debug,False)
|
||||
args.allowdeletion,debug,False, \
|
||||
args.instanceOnlySkillsSearch)
|
||||
|
|
6
tests.py
6
tests.py
|
@ -217,7 +217,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \
|
|||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||
useTor,maxReplies, \
|
||||
domainMaxPostsPerDay,accountMaxPostsPerDay, \
|
||||
allowDeletion,True,True)
|
||||
allowDeletion,True,True,False)
|
||||
|
||||
def createServerBob(path: str,domain: str,port: int,federationList: [], \
|
||||
hasFollows: bool,hasPosts :bool,ocapAlways :bool):
|
||||
|
@ -270,7 +270,7 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \
|
|||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||
useTor,maxReplies, \
|
||||
domainMaxPostsPerDay,accountMaxPostsPerDay, \
|
||||
allowDeletion,True,True)
|
||||
allowDeletion,True,True,False)
|
||||
|
||||
def createServerEve(path: str,domain: str,port: int,federationList: [], \
|
||||
hasFollows: bool,hasPosts :bool,ocapAlways :bool):
|
||||
|
@ -301,7 +301,7 @@ def createServerEve(path: str,domain: str,port: int,federationList: [], \
|
|||
runDaemon(__version__,"instanceId",False,path,domain,port,port, \
|
||||
httpPrefix,federationList, \
|
||||
noreply,nolike,nopics,noannounce,cw,ocapAlways, \
|
||||
useTor,maxReplies,allowDeletion,True,True)
|
||||
useTor,maxReplies,allowDeletion,True,True,False)
|
||||
|
||||
def testPostMessageBetweenServers():
|
||||
print('Testing sending message from one server to the inbox of another')
|
||||
|
|
|
@ -284,7 +284,7 @@ def htmlHashtagSearch(baseDir: str,hashtag: str,pageNumber: int,postsPerPage: in
|
|||
hashtagSearchForm+=htmlFooter()
|
||||
return hashtagSearchForm
|
||||
|
||||
def htmlSkillsSearch(baseDir: str,skillsearch: str,domainFull: str,postsPerPage: int) -> str:
|
||||
def htmlSkillsSearch(baseDir: str,skillsearch: str,instanceOnly: bool,postsPerPage: int) -> str:
|
||||
"""Show a page containing search results for a skill
|
||||
"""
|
||||
if skillsearch.startswith('*'):
|
||||
|
@ -321,36 +321,37 @@ def htmlSkillsSearch(baseDir: str,skillsearch: str,domainFull: str,postsPerPage:
|
|||
indexStr=skillLevelStr+';'+actor+';'+actorJson['name']+';'+actorJson['icon']['url']
|
||||
if indexStr not in results:
|
||||
results.append(indexStr)
|
||||
# search actor cache
|
||||
for subdir, dirs, files in os.walk(baseDir+'/cache/actors/'):
|
||||
for f in files:
|
||||
if not f.endswith('.json'):
|
||||
continue
|
||||
if '@' not in f:
|
||||
continue
|
||||
if f.startswith('inbox@'):
|
||||
continue
|
||||
actorFilename = os.path.join(subdir, f)
|
||||
with open(actorFilename, 'r') as fp:
|
||||
cachedActorJson=commentjson.load(fp)
|
||||
if cachedActorJson.get('actor'):
|
||||
actorJson=cachedActorJson['actor']
|
||||
if actorJson.get('id') and \
|
||||
actorJson.get('skills') and \
|
||||
actorJson.get('name') and \
|
||||
actorJson.get('icon'):
|
||||
actor=actorJson['id']
|
||||
for skillName,skillLevel in actorJson['skills'].items():
|
||||
skillName=skillName.lower()
|
||||
if skillName in skillsearch or skillsearch in skillName:
|
||||
skillLevelStr=str(skillLevel)
|
||||
if skillLevel<100:
|
||||
skillLevelStr='0'+skillLevelStr
|
||||
if skillLevel<10:
|
||||
skillLevelStr='0'+skillLevelStr
|
||||
indexStr=skillLevelStr+';'+actor+';'+actorJson['name']+';'+actorJson['icon']['url']
|
||||
if indexStr not in results:
|
||||
results.append(indexStr)
|
||||
if not instanceOnly:
|
||||
# search actor cache
|
||||
for subdir, dirs, files in os.walk(baseDir+'/cache/actors/'):
|
||||
for f in files:
|
||||
if not f.endswith('.json'):
|
||||
continue
|
||||
if '@' not in f:
|
||||
continue
|
||||
if f.startswith('inbox@'):
|
||||
continue
|
||||
actorFilename = os.path.join(subdir, f)
|
||||
with open(actorFilename, 'r') as fp:
|
||||
cachedActorJson=commentjson.load(fp)
|
||||
if cachedActorJson.get('actor'):
|
||||
actorJson=cachedActorJson['actor']
|
||||
if actorJson.get('id') and \
|
||||
actorJson.get('skills') and \
|
||||
actorJson.get('name') and \
|
||||
actorJson.get('icon'):
|
||||
actor=actorJson['id']
|
||||
for skillName,skillLevel in actorJson['skills'].items():
|
||||
skillName=skillName.lower()
|
||||
if skillName in skillsearch or skillsearch in skillName:
|
||||
skillLevelStr=str(skillLevel)
|
||||
if skillLevel<100:
|
||||
skillLevelStr='0'+skillLevelStr
|
||||
if skillLevel<10:
|
||||
skillLevelStr='0'+skillLevelStr
|
||||
indexStr=skillLevelStr+';'+actor+';'+actorJson['name']+';'+actorJson['icon']['url']
|
||||
if indexStr not in results:
|
||||
results.append(indexStr)
|
||||
|
||||
results.sort(reverse=True)
|
||||
|
||||
|
|
Loading…
Reference in New Issue