From 693609e0951d07a4c95e45217a4f86ea4acdd2c7 Mon Sep 17 00:00:00 2001 From: 3nprob <3nprob@3nprob> Date: Wed, 10 Feb 2021 20:19:38 +0900 Subject: [PATCH] Vendorize js and css dependencies --- scripts/obwatch/ob-watcher.py | 28 +- scripts/obwatch/orderbook.html | 4 +- scripts/obwatch/vendor/bootstrap.min.css | 5 + scripts/obwatch/vendor/sorttable.js | 495 +++++++++++++++++++++++ 4 files changed, 524 insertions(+), 8 deletions(-) create mode 100644 scripts/obwatch/vendor/bootstrap.min.css create mode 100644 scripts/obwatch/vendor/sorttable.js diff --git a/scripts/obwatch/ob-watcher.py b/scripts/obwatch/ob-watcher.py index d4f02b8..1595da9 100755 --- a/scripts/obwatch/ob-watcher.py +++ b/scripts/obwatch/ob-watcher.py @@ -277,18 +277,19 @@ class OrderbookPageRequestHeader(http.server.SimpleHTTPRequestHandler): self.path, query = self.path.split('?', 1) if '?' in self.path else ( self.path, '') args = parse_qs(query) - pages = ['/', '/ordersize', '/depth', '/orderbook.json'] + pages = ['/', '/ordersize', '/depth', '/orderbook.json', '/vendor/sorttable.js', '/vendor/bootstrap.min.css'] if self.path not in pages: return - fd = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), - 'orderbook.html'), 'r') - orderbook_fmt = fd.read() - fd.close() alert_msg = '' + replacements = {} if jm_single().joinmarket_alert[0]: alert_msg = '
JoinMarket Alert Message:
' + \ jm_single().joinmarket_alert[0] if self.path == '/': + fd = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), + 'orderbook.html'), 'r') + orderbook_fmt = fd.read() + fd.close() btc_unit = args['btcunit'][ 0] if 'btcunit' in args else sorted_units[0] rel_unit = args['relunit'][ @@ -312,6 +313,10 @@ class OrderbookPageRequestHeader(http.server.SimpleHTTPRequestHandler): table_heading + ordertable + '\n') } elif self.path == '/ordersize': + fd = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), + 'orderbook.html'), 'r') + orderbook_fmt = fd.read() + fd.close() replacements = { 'PAGETITLE': 'JoinMarket Browser Interface', 'MAINHEADING': 'Order Sizes', @@ -321,6 +326,10 @@ class OrderbookPageRequestHeader(http.server.SimpleHTTPRequestHandler): elif self.path.startswith('/depth'): # if self.path[6] == '?': # quantity = + fd = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), + 'orderbook.html'), 'r') + orderbook_fmt = fd.read() + fd.close() cj_amounts = [10 ** cja for cja in range(4, 12, 1)] mainbody = [self.create_depth_chart(cja, args) \ for cja in cj_amounts] + \ @@ -333,14 +342,21 @@ class OrderbookPageRequestHeader(http.server.SimpleHTTPRequestHandler): 'MAINBODY': '
'.join(mainbody) } elif self.path == '/orderbook.json': - replacements = {} orderbook_fmt = json.dumps(self.create_orderbook_obj()) + elif self.path.startswith('/vendor/') and not '..' in self.path: + fd = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), self.path[1:]), 'r') + orderbook_fmt = fd.read() + fd.close() orderbook_page = orderbook_fmt for key, rep in iteritems(replacements): orderbook_page = orderbook_page.replace(key, rep) self.send_response(200) if self.path.endswith('.json'): self.send_header('Content-Type', 'application/json') + elif self.path.endswith('.js'): + self.send_header('Content-Type', 'application/javascript') + elif self.path.endswith('.css'): + self.send_header('Content-Type', 'text/css') else: self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(orderbook_page)) diff --git a/scripts/obwatch/orderbook.html b/scripts/obwatch/orderbook.html index 5129c65..f2554f9 100644 --- a/scripts/obwatch/orderbook.html +++ b/scripts/obwatch/orderbook.html @@ -4,8 +4,8 @@ PAGETITLE - - + +