Support use on i2p addresses

main
Bob Mottram 2020-02-17 17:18:21 +00:00
parent afea4533b1
commit dfdf4c032e
6 changed files with 23 additions and 12 deletions

View File

@ -66,6 +66,7 @@ def addWebLinks(content: str) -> str:
for w in words:
if w.startswith('https://') or \
w.startswith('http://') or \
w.startswith('i2p://') or \
w.startswith('dat://'):
if w.endswith('.') or w.endswith(';'):
w=w[:-1]
@ -74,9 +75,11 @@ def addWebLinks(content: str) -> str:
markup+='<span class="invisible">https://</span>'
elif w.startswith('http://'):
markup+='<span class="invisible">http://</span>'
elif w.startswith('i2p://'):
markup+='<span class="invisible">i2p://</span>'
elif w.startswith('dat://'):
markup+='<span class="invisible">dat://</span>'
linkText=w.replace('https://','').replace('http://','').replace('dat://','')
linkText=w.replace('https://','').replace('http://','').replace('dat://','').replace('i2p://','')
# prevent links from becoming too long
if len(linkText)>maxLinkLength:
markup+='<span class="ellipsis">'+linkText[:maxLinkLength]+'</span>'
@ -276,6 +279,8 @@ def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str:
continue
elif 'http:' in wordStr:
continue
elif 'i2p:' in wordStr:
continue
elif 'dat:' in wordStr:
continue
if '<' in wordStr:
@ -396,6 +401,7 @@ def getMentionsFromHtml(htmlText: str,matchStr="<span class=\"h-card\"><a href=\
continue
actorStr=mentionStr.split('"')[0]
if actorStr.startswith('http') or \
actorStr.startswith('i2p') or \
actorStr.startswith('dat:'):
if actorStr not in mentions:
mentions.append(actorStr)

View File

@ -166,6 +166,9 @@ parser.add_argument("--http", type=str2bool, nargs='?', \
parser.add_argument("--dat", type=str2bool, nargs='?', \
const=True, default=False, \
help="Use dat protocol only")
parser.add_argument("--i2p", type=str2bool, nargs='?', \
const=True, default=False, \
help="Use i2p protocol only")
parser.add_argument("--tor", type=str2bool, nargs='?', \
const=True, default=False, \
help="Route via Tor")
@ -900,12 +903,14 @@ if args.ocap:
ocapAlways=args.ocap
if args.dat:
httpPrefix='dat'
if args.i2p:
httpPrefix='i2p'
if args.actor:
originalActor=args.actor
if '/@' in args.actor or '/users/' in args.actor or args.actor.startswith('http') or args.actor.startswith('dat'):
# format: https://domain/@nick
args.actor=args.actor.replace('https://','').replace('http://','').replace('dat://','').replace('/@','/users/')
args.actor=args.actor.replace('https://','').replace('http://','').replace('dat://','').replace('i2p://','').replace('/@','/users/')
if '/users/' not in args.actor and \
'/channel/' not in args.actor and \
'/profile/' not in args.actor:

View File

@ -1248,7 +1248,7 @@ def receiveAnnounce(recentPostsCache: {}, \
if debug:
print('DEBUG: "users", "channel" or "profile" missing in '+messageJson['type'])
return False
objectDomain=messageJson['object'].replace('https://','').replace('http://','').replace('dat://','')
objectDomain=messageJson['object'].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','')
if '/' in objectDomain:
objectDomain=objectDomain.split('/')[0]
if isBlockedDomain(baseDir,objectDomain):

View File

@ -175,17 +175,17 @@ def getDomainFromActor(actor: str) -> (str,int):
"""
port=None
if '/profile/' in actor:
domain = actor.split('/profile/')[0].replace('https://','').replace('http://','').replace('dat://','')
domain = actor.split('/profile/')[0].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','')
else:
if '/channel/' in actor:
domain = actor.split('/channel/')[0].replace('https://','').replace('http://','').replace('dat://','')
domain = actor.split('/channel/')[0].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','')
else:
if '/users/' not in actor:
domain = actor.replace('https://','').replace('http://','').replace('dat://','')
domain = actor.replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','')
if '/' in actor:
domain=domain.split('/')[0]
else:
domain = actor.split('/users/')[0].replace('https://','').replace('http://','').replace('dat://','')
domain = actor.split('/users/')[0].replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','')
if ':' in domain:
port=int(domain.split(':')[1])
domain=domain.split(':')[0]

View File

@ -24,11 +24,11 @@ def parseHandle(handle: str) -> (str,str):
return None, None
if '/@' in handle:
domain, nickname = \
handle.replace('https://','').replace('http://','').replace('dat://','').split('/@')
handle.replace('https://','').replace('http://','').replace('dat://','').replace('i2p://','').split('/@')
else:
if '/users/' in handle:
domain, nickname = \
handle.replace('https://','').replace('http://','').replace('dat://','').split('/users/')
handle.replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','').split('/users/')
else:
if '@' in handle:
nickname, domain = handle.split('@')

View File

@ -1819,7 +1819,7 @@ def addEmbeddedAudio(translate: {},content: str) -> str:
if not w.endswith(extension):
continue
if not (w.startswith('http') or w.startswith('dat:') or '/' in w):
if not (w.startswith('http') or w.startswith('dat:') or w.startswith('i2p:') or '/' in w):
continue
url=w
content+='<center><audio controls>'
@ -1858,7 +1858,7 @@ def addEmbeddedVideo(translate: {},content: str,width=400,height=300) -> str:
w=w[:-1]
if not w.endswith(extension):
continue
if not (w.startswith('http') or w.startswith('dat:') or '/' in w):
if not (w.startswith('http') or w.startswith('dat:') or w.startswith('i2p:') or '/' in w):
continue
url=w
content+='<center><video width="'+str(width)+'" height="'+str(height)+'" controls>'
@ -2492,7 +2492,7 @@ def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \
else:
titleStr+=' <img loading="lazy" title="'+translate['replying to']+'" alt="'+translate['replying to']+'" src="/'+iconsDir+'/reply.png" class="announceOrReply"/> <a href="'+postJsonObject['object']['inReplyTo']+'">@unknown</a>'
else:
postDomain=postJsonObject['object']['inReplyTo'].replace('https://','').replace('http://','').replace('dat://','')
postDomain=postJsonObject['object']['inReplyTo'].replace('https://','').replace('http://','').replace('dat://','').replace('i2p://','')
if '/' in postDomain:
postDomain=postDomain.split('/',1)[0]
if postDomain: