forked from indymedia/epicyon
Support use on i2p addresses
parent
afea4533b1
commit
dfdf4c032e
|
@ -66,6 +66,7 @@ def addWebLinks(content: str) -> str:
|
||||||
for w in words:
|
for w in words:
|
||||||
if w.startswith('https://') or \
|
if w.startswith('https://') or \
|
||||||
w.startswith('http://') or \
|
w.startswith('http://') or \
|
||||||
|
w.startswith('i2p://') or \
|
||||||
w.startswith('dat://'):
|
w.startswith('dat://'):
|
||||||
if w.endswith('.') or w.endswith(';'):
|
if w.endswith('.') or w.endswith(';'):
|
||||||
w=w[:-1]
|
w=w[:-1]
|
||||||
|
@ -74,9 +75,11 @@ def addWebLinks(content: str) -> str:
|
||||||
markup+='<span class="invisible">https://</span>'
|
markup+='<span class="invisible">https://</span>'
|
||||||
elif w.startswith('http://'):
|
elif w.startswith('http://'):
|
||||||
markup+='<span class="invisible">http://</span>'
|
markup+='<span class="invisible">http://</span>'
|
||||||
|
elif w.startswith('i2p://'):
|
||||||
|
markup+='<span class="invisible">i2p://</span>'
|
||||||
elif w.startswith('dat://'):
|
elif w.startswith('dat://'):
|
||||||
markup+='<span class="invisible">dat://</span>'
|
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
|
# prevent links from becoming too long
|
||||||
if len(linkText)>maxLinkLength:
|
if len(linkText)>maxLinkLength:
|
||||||
markup+='<span class="ellipsis">'+linkText[:maxLinkLength]+'</span>'
|
markup+='<span class="ellipsis">'+linkText[:maxLinkLength]+'</span>'
|
||||||
|
@ -276,6 +279,8 @@ def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str:
|
||||||
continue
|
continue
|
||||||
elif 'http:' in wordStr:
|
elif 'http:' in wordStr:
|
||||||
continue
|
continue
|
||||||
|
elif 'i2p:' in wordStr:
|
||||||
|
continue
|
||||||
elif 'dat:' in wordStr:
|
elif 'dat:' in wordStr:
|
||||||
continue
|
continue
|
||||||
if '<' in wordStr:
|
if '<' in wordStr:
|
||||||
|
@ -396,6 +401,7 @@ def getMentionsFromHtml(htmlText: str,matchStr="<span class=\"h-card\"><a href=\
|
||||||
continue
|
continue
|
||||||
actorStr=mentionStr.split('"')[0]
|
actorStr=mentionStr.split('"')[0]
|
||||||
if actorStr.startswith('http') or \
|
if actorStr.startswith('http') or \
|
||||||
|
actorStr.startswith('i2p') or \
|
||||||
actorStr.startswith('dat:'):
|
actorStr.startswith('dat:'):
|
||||||
if actorStr not in mentions:
|
if actorStr not in mentions:
|
||||||
mentions.append(actorStr)
|
mentions.append(actorStr)
|
||||||
|
|
|
@ -166,6 +166,9 @@ parser.add_argument("--http", type=str2bool, nargs='?', \
|
||||||
parser.add_argument("--dat", type=str2bool, nargs='?', \
|
parser.add_argument("--dat", type=str2bool, nargs='?', \
|
||||||
const=True, default=False, \
|
const=True, default=False, \
|
||||||
help="Use dat protocol only")
|
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='?', \
|
parser.add_argument("--tor", type=str2bool, nargs='?', \
|
||||||
const=True, default=False, \
|
const=True, default=False, \
|
||||||
help="Route via Tor")
|
help="Route via Tor")
|
||||||
|
@ -900,12 +903,14 @@ if args.ocap:
|
||||||
ocapAlways=args.ocap
|
ocapAlways=args.ocap
|
||||||
if args.dat:
|
if args.dat:
|
||||||
httpPrefix='dat'
|
httpPrefix='dat'
|
||||||
|
if args.i2p:
|
||||||
|
httpPrefix='i2p'
|
||||||
|
|
||||||
if args.actor:
|
if args.actor:
|
||||||
originalActor=args.actor
|
originalActor=args.actor
|
||||||
if '/@' in args.actor or '/users/' in args.actor or args.actor.startswith('http') or args.actor.startswith('dat'):
|
if '/@' in args.actor or '/users/' in args.actor or args.actor.startswith('http') or args.actor.startswith('dat'):
|
||||||
# format: https://domain/@nick
|
# 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 \
|
if '/users/' not in args.actor and \
|
||||||
'/channel/' not in args.actor and \
|
'/channel/' not in args.actor and \
|
||||||
'/profile/' not in args.actor:
|
'/profile/' not in args.actor:
|
||||||
|
|
2
inbox.py
2
inbox.py
|
@ -1248,7 +1248,7 @@ def receiveAnnounce(recentPostsCache: {}, \
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: "users", "channel" or "profile" missing in '+messageJson['type'])
|
print('DEBUG: "users", "channel" or "profile" missing in '+messageJson['type'])
|
||||||
return False
|
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:
|
if '/' in objectDomain:
|
||||||
objectDomain=objectDomain.split('/')[0]
|
objectDomain=objectDomain.split('/')[0]
|
||||||
if isBlockedDomain(baseDir,objectDomain):
|
if isBlockedDomain(baseDir,objectDomain):
|
||||||
|
|
8
utils.py
8
utils.py
|
@ -175,17 +175,17 @@ def getDomainFromActor(actor: str) -> (str,int):
|
||||||
"""
|
"""
|
||||||
port=None
|
port=None
|
||||||
if '/profile/' in actor:
|
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:
|
else:
|
||||||
if '/channel/' in actor:
|
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:
|
else:
|
||||||
if '/users/' not in actor:
|
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:
|
if '/' in actor:
|
||||||
domain=domain.split('/')[0]
|
domain=domain.split('/')[0]
|
||||||
else:
|
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:
|
if ':' in domain:
|
||||||
port=int(domain.split(':')[1])
|
port=int(domain.split(':')[1])
|
||||||
domain=domain.split(':')[0]
|
domain=domain.split(':')[0]
|
||||||
|
|
|
@ -24,11 +24,11 @@ def parseHandle(handle: str) -> (str,str):
|
||||||
return None, None
|
return None, None
|
||||||
if '/@' in handle:
|
if '/@' in handle:
|
||||||
domain, nickname = \
|
domain, nickname = \
|
||||||
handle.replace('https://','').replace('http://','').replace('dat://','').split('/@')
|
handle.replace('https://','').replace('http://','').replace('dat://','').replace('i2p://','').split('/@')
|
||||||
else:
|
else:
|
||||||
if '/users/' in handle:
|
if '/users/' in handle:
|
||||||
domain, nickname = \
|
domain, nickname = \
|
||||||
handle.replace('https://','').replace('http://','').replace('dat://','').split('/users/')
|
handle.replace('https://','').replace('http://','').replace('i2p://','').replace('dat://','').split('/users/')
|
||||||
else:
|
else:
|
||||||
if '@' in handle:
|
if '@' in handle:
|
||||||
nickname, domain = handle.split('@')
|
nickname, domain = handle.split('@')
|
||||||
|
|
|
@ -1819,7 +1819,7 @@ def addEmbeddedAudio(translate: {},content: str) -> str:
|
||||||
if not w.endswith(extension):
|
if not w.endswith(extension):
|
||||||
continue
|
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
|
continue
|
||||||
url=w
|
url=w
|
||||||
content+='<center><audio controls>'
|
content+='<center><audio controls>'
|
||||||
|
@ -1858,7 +1858,7 @@ def addEmbeddedVideo(translate: {},content: str,width=400,height=300) -> str:
|
||||||
w=w[:-1]
|
w=w[:-1]
|
||||||
if not w.endswith(extension):
|
if not w.endswith(extension):
|
||||||
continue
|
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
|
continue
|
||||||
url=w
|
url=w
|
||||||
content+='<center><video width="'+str(width)+'" height="'+str(height)+'" controls>'
|
content+='<center><video width="'+str(width)+'" height="'+str(height)+'" controls>'
|
||||||
|
@ -2492,7 +2492,7 @@ def individualPostAsHtml(recentPostsCache: {},maxRecentPosts: int, \
|
||||||
else:
|
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>'
|
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:
|
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:
|
if '/' in postDomain:
|
||||||
postDomain=postDomain.split('/',1)[0]
|
postDomain=postDomain.split('/',1)[0]
|
||||||
if postDomain:
|
if postDomain:
|
||||||
|
|
Loading…
Reference in New Issue