Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
Photogrammetry use proxy server to speed up loading for who use proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
derekhe committed Nov 24, 2021
1 parent 686e8ff commit 06b7ebe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ threads = 200
server = mt1.google.com

[general]
warning = enabled
warning = disabled

3 changes: 2 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ def run(self):
try:
self.server_process = Process(
target=run_server,
args=(self.settings.cache_size, self.settings.proxy_url, self.settings.google_server))
args=(
self.settings.cache_size, self.settings.proxy_url, self.settings.google_server, get_hosts_origin_ips()))
self.server_process.start()
self.nginx_process = subprocess.Popen(
"nginx.exe", shell=True, cwd="./nginx")
Expand Down
10 changes: 9 additions & 1 deletion src/nginx.conf.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
worker_processes 1;
worker_processes 8;

error_log logs/error.log;
error_log logs/error.log notice;
Expand Down Expand Up @@ -75,6 +75,14 @@ http {
#bing_aerial# proxy_pass_request_headers on;
#bing_aerial# proxy_ssl_verify off;
#bing_aerial# access_log logs/localgoogle-access.log;
#bing_aerial# }

#bing_aerial# location ~* /tiles/mtx.*? {
#bing_aerial# proxy_pass http://localhost:39871;
#bing_aerial# proxy_pass_request_headers on;
#bing_aerial# proxy_set_header Host kh.ssl.ak.tiles.virtualearth.net;
#bing_aerial# proxy_ssl_verify off;
#bing_aerial# access_log logs/localgoogle-access.log;
#bing_aerial# }

location / {
Expand Down
28 changes: 25 additions & 3 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import urllib3
from PIL import Image, ImageEnhance, ImageStat
from diskcache import Cache
from flask import Flask, make_response, Response
from flask import Flask, make_response, Response, request

urllib3.disable_warnings()

__cache: Cache = None
__proxies = None
__google_server = "mt1.google.com"
__original_ips = None
app = Flask(__name__)


Expand Down Expand Up @@ -50,6 +51,26 @@ def calc_brightness(im):
return stat.rms[0]


@app.route('/tiles/mtx<dummy>')
def mtx(dummy=None):
print("Handing request to", request.url)
request_header = {}
for k, v in request.headers:
request_header[k] = v

print("Downloading from:", request.url)

url = request.url.replace(request.host, "kh.ssl.ak.tiles.virtualearth.net.edgekey.net").replace("http://","https://")

remote_response = requests.get(
url, proxies=__proxies, timeout=30, verify=False, headers=request_header)

response = make_response(remote_response.content)
for k, v in remote_response.headers.items():
response.headers[k] = v
return response


@app.route("/tiles/akh<path>")
def tiles(path):
quadkey = re.findall(r"(\d+).jpeg", path)[0]
Expand Down Expand Up @@ -98,11 +119,12 @@ def tiles(path):
return response


def run_server(cache_size, proxies, google_server):
global __cache, __proxies, __google_server
def run_server(cache_size, proxies, google_server, original_ips):
global __cache, __proxies, __google_server, __original_ips
__cache = Cache(
"./cache", size_limit=int(cache_size) * 1024 * 1024 * 1024, shards=10)
__proxies = {"https": proxies}
__google_server = google_server
__original_ips = original_ips

app.run(port=39871, host="0.0.0.0", threaded=True)

0 comments on commit 06b7ebe

Please sign in to comment.