Skip to content

Commit

Permalink
fix API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
eliranwong committed Oct 29, 2024
1 parent 3716dbc commit 2554adb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/
setup(
name=package,
version="0.1.33",
version="0.1.34",
python_requires=">=3.8, <3.13",
description=f"UniqueBible App is a cross-platform & offline bible application, integrated with high-quality resources and unique features. Developers: Eliran Wong and Oliver Tseng",
long_description=long_description,
Expand Down
65 changes: 35 additions & 30 deletions uniquebible/util/RemoteHttpHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from uniquebible.util.GitHubRepoInfo import GitHubRepoInfo
from uniquebible.util.TextCommandParser import TextCommandParser
from uniquebible.util.RemoteCliMainWindow import RemoteCliMainWindow
from uniquebible.util.LocalCliHandler import LocalCliHandler
from uniquebible.util.TextUtil import TextUtil
from urllib.parse import urlparse, parse_qs
from uniquebible.util.FileUtil import FileUtil
from uniquebible.util.LanguageUtil import LanguageUtil
Expand Down Expand Up @@ -244,10 +244,15 @@ def runStartupPlugins(self):
def execPythonFile(self, script):
self.textCommandParser.parent.execPythonFile(script)

def updateData(self):
def updateData(self, plainOutput=False, allowPrivateData=False):
if plainOutput:
config.displayLanguage = "en_GB"
config.standardAbbreviation = "ENG"
self.path = re.sub("^/plain", "/index.html", self.path)
config.webHomePage = "{0}.html".format(config.webPrivateHomePage) if allowPrivateData else "index.html"
# Check language
# Traditional Chinese
if config.webPrivateHomePage and self.path.startswith("/{0}.html".format(config.webPrivateHomePage)):
elif config.webPrivateHomePage and self.path.startswith("/{0}.html".format(config.webPrivateHomePage)):
config.displayLanguage = "en_GB"
config.standardAbbreviation = "ENG"
config.webHomePage = "{0}.html".format(config.webPrivateHomePage)
Expand Down Expand Up @@ -330,38 +335,38 @@ def do_GET(self):
self.users.append(self.clientIP)
if self.clientIP == self.users[0]:
self.primaryUser = True
self.updateData()
if self.ignoreCommand(self.path):
print(f"Ignoring command: {self.path}")
self.blankPage()
return
elif self.path.startswith("/plain"):
query_components = parse_qs(urlparse(self.path).query)
# check query
query_components = parse_qs(urlparse(self.path).query)
private = query_components.get("private", [])
allowPrivateData = True if private and private[0].strip() == config.webPrivateHomePage else False
plainOutput = True if self.path.startswith("/plain?") else False
# update resource path
self.updateData(plainOutput=plainOutput, allowPrivateData=allowPrivateData)

if plainOutput:
cmd = query_components.get("cmd", [])
private = query_components.get("private", [])
if cmd:
# tweak configs
if private and private[0] == config.webPrivateHomePage:
marvelData = config.marvelData
config.marvelData = config.marvelDataPrivate
allowPrivateData = True
else:
allowPrivateData = False
addFavouriteToMultiRef = config.addFavouriteToMultiRef
config.addFavouriteToMultiRef = False
# output
self.commonHeader()
plainOutput = LocalCliHandler(allowPrivateData=allowPrivateData).getContent(cmd[0], False).strip()
self.wfile.write(bytes(plainOutput, "utf8"))
# restore user config
if allowPrivateData:
config.marvelData = marvelData
config.addFavouriteToMultiRef = addFavouriteToMultiRef
self.command = query_components["cmd"][0].strip()
self.command = self.command.replace("+", " ")
else:
self.blankPage()
self.command = "John 3:16-16"
# tweak configs
addFavouriteToMultiRef = config.addFavouriteToMultiRef
config.addFavouriteToMultiRef = False
# output
self.commonHeader()
_, content, _ = self.textCommandParser.parser(self.command, "http")
content = content.replace("<u><b>", "<u><b># ")
plainText = TextUtil.htmlToPlainText(content).strip()
self.wfile.write(bytes(plainText, "utf8"))
# restore user config
config.addFavouriteToMultiRef = addFavouriteToMultiRef
elif self.ignoreCommand(self.path):
print(f"Ignoring command: {self.path}")
self.blankPage()
return
elif self.path == "" or self.path == "/" or self.path.startswith("/index.html") or config.displayLanguage != "en_GB":
if self.primaryUser or not config.webPresentationMode:
query_components = parse_qs(urlparse(self.path).query)
if 'cmd' in query_components:
self.command = query_components["cmd"][0].strip()
self.command = self.command.replace("+", " ")
Expand Down

0 comments on commit 2554adb

Please sign in to comment.