aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-07-11 01:54:08 +1000
committerTerry Truong <terry06890@gmail.com>2022-07-11 01:54:08 +1000
commit5fe71ea7b9d9a5d2dc6e8e5ce5b9193629eed74d (patch)
tree3b8b9d7299540a812ec93e224f8fc71249a98860 /backend
parenta8f80a02b88055cfcb45664ce3a3d24c2b2da98c (diff)
Make backend dev server script serve the image files
Previously, image files in backend/data/img were moved to, or symlinked from, public/. This needed to be changed before each build, otherwise vite would end up copying gigabytes of images.
Diffstat (limited to 'backend')
-rwxr-xr-xbackend/server.py28
-rwxr-xr-xbackend/tilo.py2
-rw-r--r--backend/tolData/README.md (renamed from backend/data/README.md)0
-rwxr-xr-xbackend/tolData/addPickedNames.py (renamed from backend/data/addPickedNames.py)0
-rw-r--r--backend/tolData/dbpedia/README.md (renamed from backend/data/dbpedia/README.md)0
-rwxr-xr-xbackend/tolData/dbpedia/genDescData.py (renamed from backend/data/dbpedia/genDescData.py)0
-rw-r--r--backend/tolData/enwiki/README.md (renamed from backend/data/enwiki/README.md)0
-rwxr-xr-xbackend/tolData/enwiki/downloadImgLicenseInfo.py (renamed from backend/data/enwiki/downloadImgLicenseInfo.py)0
-rwxr-xr-xbackend/tolData/enwiki/downloadImgs.py (renamed from backend/data/enwiki/downloadImgs.py)0
-rwxr-xr-xbackend/tolData/enwiki/genDescData.py (renamed from backend/data/enwiki/genDescData.py)0
-rwxr-xr-xbackend/tolData/enwiki/genDumpIndexDb.py (renamed from backend/data/enwiki/genDumpIndexDb.py)0
-rwxr-xr-xbackend/tolData/enwiki/genImgData.py (renamed from backend/data/enwiki/genImgData.py)0
-rwxr-xr-xbackend/tolData/enwiki/lookupPage.py (renamed from backend/data/enwiki/lookupPage.py)0
-rw-r--r--backend/tolData/eol/README.md (renamed from backend/data/eol/README.md)0
-rwxr-xr-xbackend/tolData/eol/downloadImgs.py (renamed from backend/data/eol/downloadImgs.py)0
-rwxr-xr-xbackend/tolData/eol/genImagesListDb.sh (renamed from backend/data/eol/genImagesListDb.sh)0
-rwxr-xr-xbackend/tolData/eol/reviewImgs.py (renamed from backend/data/eol/reviewImgs.py)0
-rwxr-xr-xbackend/tolData/genDbpData.py (renamed from backend/data/genDbpData.py)0
-rwxr-xr-xbackend/tolData/genEnwikiDescData.py (renamed from backend/data/genEnwikiDescData.py)0
-rwxr-xr-xbackend/tolData/genEnwikiNameData.py (renamed from backend/data/genEnwikiNameData.py)0
-rwxr-xr-xbackend/tolData/genEolNameData.py (renamed from backend/data/genEolNameData.py)0
-rwxr-xr-xbackend/tolData/genImgs.py (renamed from backend/data/genImgs.py)0
-rwxr-xr-xbackend/tolData/genLinkedImgs.py (renamed from backend/data/genLinkedImgs.py)0
-rwxr-xr-xbackend/tolData/genOtolData.py (renamed from backend/data/genOtolData.py)0
-rwxr-xr-xbackend/tolData/genReducedTrees.py (renamed from backend/data/genReducedTrees.py)0
-rw-r--r--backend/tolData/otol/README.md (renamed from backend/data/otol/README.md)0
-rw-r--r--backend/tolData/pickedImgs/README.md (renamed from backend/data/pickedImgs/README.md)0
-rwxr-xr-xbackend/tolData/reviewImgsToGen.py (renamed from backend/data/reviewImgsToGen.py)0
28 files changed, 25 insertions, 5 deletions
diff --git a/backend/server.py b/backend/server.py
index a00ab7f..5e0b80f 100755
--- a/backend/server.py
+++ b/backend/server.py
@@ -1,18 +1,38 @@
#!/usr/bin/python3
-import sys
-from wsgiref.simple_server import make_server
+import sys, os
+from wsgiref import simple_server, util
+import mimetypes
from tilo import application
usageInfo = f"""
Usage: {sys.argv[0]}
-Runs a basic dev server that serves a WSGI script
+Runs a basic dev server that serves a WSGI script and image files
"""
if len(sys.argv) > 1:
print(usageInfo, file=sys.stderr)
sys.exit(1)
-with make_server('', 8000, application) as httpd:
+def wrappingApp(environ, start_response):
+ urlPath = environ["PATH_INFO"]
+ if urlPath.startswith("/data/"):
+ # Run WSGI script
+ return application(environ, start_response)
+ elif urlPath.startswith("/tolData/img/"):
+ # Serve image file
+ imgPath = os.path.join(os.getcwd(), urlPath[1:])
+ if os.path.exists(imgPath):
+ imgType = mimetypes.guess_type(imgPath)[0]
+ start_response("200 OK", [("Content-type", imgType)])
+ return util.FileWrapper(open(imgPath, "rb"))
+ else:
+ start_response("404 Not Found", [("Content-type", "text/plain")])
+ return [b"No image found"]
+ else:
+ start_response("404 Not Found", [("Content-type", "text/plain")])
+ return [b"Unrecognised path"]
+
+with simple_server.make_server('', 8000, wrappingApp) as httpd:
print("Serving HTTP on port 8000...")
httpd.serve_forever()
diff --git a/backend/tilo.py b/backend/tilo.py
index f2a177e..7b0f8aa 100755
--- a/backend/tilo.py
+++ b/backend/tilo.py
@@ -5,7 +5,7 @@ import urllib.parse
import sqlite3
import gzip, jsonpickle
-dbFile = "data/data.db"
+dbFile = "tolData/data.db"
DEFAULT_SUGG_LIM = 5
MAX_SUGG_LIM = 50
ROOT_NAME = "cellular organisms"
diff --git a/backend/data/README.md b/backend/tolData/README.md
index ba64114..ba64114 100644
--- a/backend/data/README.md
+++ b/backend/tolData/README.md
diff --git a/backend/data/addPickedNames.py b/backend/tolData/addPickedNames.py
index d56a0cb..d56a0cb 100755
--- a/backend/data/addPickedNames.py
+++ b/backend/tolData/addPickedNames.py
diff --git a/backend/data/dbpedia/README.md b/backend/tolData/dbpedia/README.md
index 8a08f20..8a08f20 100644
--- a/backend/data/dbpedia/README.md
+++ b/backend/tolData/dbpedia/README.md
diff --git a/backend/data/dbpedia/genDescData.py b/backend/tolData/dbpedia/genDescData.py
index d9e8a80..d9e8a80 100755
--- a/backend/data/dbpedia/genDescData.py
+++ b/backend/tolData/dbpedia/genDescData.py
diff --git a/backend/data/enwiki/README.md b/backend/tolData/enwiki/README.md
index 90d16c7..90d16c7 100644
--- a/backend/data/enwiki/README.md
+++ b/backend/tolData/enwiki/README.md
diff --git a/backend/data/enwiki/downloadImgLicenseInfo.py b/backend/tolData/enwiki/downloadImgLicenseInfo.py
index 399922e..399922e 100755
--- a/backend/data/enwiki/downloadImgLicenseInfo.py
+++ b/backend/tolData/enwiki/downloadImgLicenseInfo.py
diff --git a/backend/data/enwiki/downloadImgs.py b/backend/tolData/enwiki/downloadImgs.py
index 8fb605f..8fb605f 100755
--- a/backend/data/enwiki/downloadImgs.py
+++ b/backend/tolData/enwiki/downloadImgs.py
diff --git a/backend/data/enwiki/genDescData.py b/backend/tolData/enwiki/genDescData.py
index b0ca272..b0ca272 100755
--- a/backend/data/enwiki/genDescData.py
+++ b/backend/tolData/enwiki/genDescData.py
diff --git a/backend/data/enwiki/genDumpIndexDb.py b/backend/tolData/enwiki/genDumpIndexDb.py
index 3955885..3955885 100755
--- a/backend/data/enwiki/genDumpIndexDb.py
+++ b/backend/tolData/enwiki/genDumpIndexDb.py
diff --git a/backend/data/enwiki/genImgData.py b/backend/tolData/enwiki/genImgData.py
index dedfe14..dedfe14 100755
--- a/backend/data/enwiki/genImgData.py
+++ b/backend/tolData/enwiki/genImgData.py
diff --git a/backend/data/enwiki/lookupPage.py b/backend/tolData/enwiki/lookupPage.py
index 1a90851..1a90851 100755
--- a/backend/data/enwiki/lookupPage.py
+++ b/backend/tolData/enwiki/lookupPage.py
diff --git a/backend/data/eol/README.md b/backend/tolData/eol/README.md
index 8c527a8..8c527a8 100644
--- a/backend/data/eol/README.md
+++ b/backend/tolData/eol/README.md
diff --git a/backend/data/eol/downloadImgs.py b/backend/tolData/eol/downloadImgs.py
index 96bc085..96bc085 100755
--- a/backend/data/eol/downloadImgs.py
+++ b/backend/tolData/eol/downloadImgs.py
diff --git a/backend/data/eol/genImagesListDb.sh b/backend/tolData/eol/genImagesListDb.sh
index 87dd840..87dd840 100755
--- a/backend/data/eol/genImagesListDb.sh
+++ b/backend/tolData/eol/genImagesListDb.sh
diff --git a/backend/data/eol/reviewImgs.py b/backend/tolData/eol/reviewImgs.py
index ecdf7ab..ecdf7ab 100755
--- a/backend/data/eol/reviewImgs.py
+++ b/backend/tolData/eol/reviewImgs.py
diff --git a/backend/data/genDbpData.py b/backend/tolData/genDbpData.py
index df3a6be..df3a6be 100755
--- a/backend/data/genDbpData.py
+++ b/backend/tolData/genDbpData.py
diff --git a/backend/data/genEnwikiDescData.py b/backend/tolData/genEnwikiDescData.py
index d3f93ed..d3f93ed 100755
--- a/backend/data/genEnwikiDescData.py
+++ b/backend/tolData/genEnwikiDescData.py
diff --git a/backend/data/genEnwikiNameData.py b/backend/tolData/genEnwikiNameData.py
index 7ad61d1..7ad61d1 100755
--- a/backend/data/genEnwikiNameData.py
+++ b/backend/tolData/genEnwikiNameData.py
diff --git a/backend/data/genEolNameData.py b/backend/tolData/genEolNameData.py
index dd33ee0..dd33ee0 100755
--- a/backend/data/genEolNameData.py
+++ b/backend/tolData/genEolNameData.py
diff --git a/backend/data/genImgs.py b/backend/tolData/genImgs.py
index ecca8e0..ecca8e0 100755
--- a/backend/data/genImgs.py
+++ b/backend/tolData/genImgs.py
diff --git a/backend/data/genLinkedImgs.py b/backend/tolData/genLinkedImgs.py
index a8e1322..a8e1322 100755
--- a/backend/data/genLinkedImgs.py
+++ b/backend/tolData/genLinkedImgs.py
diff --git a/backend/data/genOtolData.py b/backend/tolData/genOtolData.py
index b5e0055..b5e0055 100755
--- a/backend/data/genOtolData.py
+++ b/backend/tolData/genOtolData.py
diff --git a/backend/data/genReducedTrees.py b/backend/tolData/genReducedTrees.py
index a921be4..a921be4 100755
--- a/backend/data/genReducedTrees.py
+++ b/backend/tolData/genReducedTrees.py
diff --git a/backend/data/otol/README.md b/backend/tolData/otol/README.md
index 4be2fd2..4be2fd2 100644
--- a/backend/data/otol/README.md
+++ b/backend/tolData/otol/README.md
diff --git a/backend/data/pickedImgs/README.md b/backend/tolData/pickedImgs/README.md
index dfe192b..dfe192b 100644
--- a/backend/data/pickedImgs/README.md
+++ b/backend/tolData/pickedImgs/README.md
diff --git a/backend/data/reviewImgsToGen.py b/backend/tolData/reviewImgsToGen.py
index de592f5..de592f5 100755
--- a/backend/data/reviewImgsToGen.py
+++ b/backend/tolData/reviewImgsToGen.py