Skip to content
Snippets Groups Projects
Commit 3dd195f8 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

The Tileserver can now serve the downloadable Areas for the App

parent 3eec0d12
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ class DownloadController extends Controller
public function listFiles($minLon, $minLat, $maxLon, $maxLat){
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, "127.0.0.1", 63825);
socket_connect($socket, env("TILESERVER_HOST"), env("TILESERVER_PORT"));
socket_write($socket, "list-files;$minLon;$minLat;$maxLon;$maxLat\n", strlen("list-files;$minLon;$minLat;$maxLon;$maxLat\n"));
......@@ -35,22 +35,26 @@ public function listFiles($minLon, $minLat, $maxLon, $maxLat){
public function downloadFiles($minLon, $minLat, $maxLon, $maxLat){
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, "127.0.0.1", 63825);
socket_connect($socket, env("TILESERVER_HOST"), env("TILESERVER_PORT"));
socket_write($socket, "download-files;$minLon;$minLat;$maxLon;$maxLat\n", strlen("download-files;$minLon;$minLat;$maxLon;$maxLat\n"));
$content = "";
$file = tempnam(sys_get_temp_dir(), "downloadable");
$handle = fopen($file, "w");
while(true){
$tmp = socket_read($socket, 4096);
if($tmp === FALSE) break;
if($tmp == "") break;
else $content .= $tmp;
if($tmp === FALSE || $tmp == "")
break;
else{
fwrite($handle, $tmp);
}
}
fclose($handle);
socket_close($socket);
# The result is a path to the Zip File that will get downloaded
if(file_exists($content)){
return response()->download($content, "offline-data.tar",
if(file_exists($file)){
return response()->download($file, "offline-data.tar",
[
"Content-Type" => "application/tar",
"Pragma" => "public",
......@@ -58,7 +62,7 @@ public function downloadFiles($minLon, $minLat, $maxLon, $maxLat){
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Content-Description" => "File Transfer",
"Content-Transfer-Encoding" => "binary",
"Content-Length" => sizeof($content)
"Content-Length" => filesize($file)
])->deleteFileAfterSend(true);
}else{
abort(404, "File not found");
......@@ -67,22 +71,26 @@ public function downloadFiles($minLon, $minLat, $maxLon, $maxLat){
public function downloadAssets(){
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, "127.0.0.1", 63825);
socket_connect($socket, env("TILESERVER_HOST"), env("TILESERVER_PORT"));
socket_write($socket, "download-assets\n", strlen("download-assets\n"));
$content = "";
$file = tempnam(sys_get_temp_dir(), "downloadable");
$handle = fopen($file, "w");
while(true){
$tmp = socket_read($socket, 4096);
if($tmp === FALSE) break;
if($tmp == "") break;
else $content .= $tmp;
if($tmp === FALSE || $tmp == "")
break;
else{
fwrite($handle, $tmp);
}
}
fclose($handle);
socket_close($socket);
# The result is a path to the Zip File that will get downloaded
if(file_exists($content)){
return response()->download($content, "asset-data.tar",
if(file_exists($file)){
return response()->download($file, "asset-data.tar",
[
"Content-Type" => "application/tar",
"Pragma" => "public",
......@@ -90,7 +98,7 @@ public function downloadAssets(){
"Cache-Control" => "must-revalidate, post-check=0, pre-check=0",
"Content-Description" => "File Transfer",
"Content-Transfer-Encoding" => "binary",
"Content-Length" => sizeof($content)
"Content-Length" => filesize($file)
])->deleteFileAfterSend(true);
}else{
abort(404, "File not found");
......
This diff is collapsed.
......@@ -19,4 +19,4 @@
"lodash": "^4.17.4",
"vue": "^2.5.7"
}
}
\ No newline at end of file
}
......@@ -123,9 +123,9 @@ Route::group(['prefix' => 'metager'], function () {
Route::get('tile_cache/{z}/{x}/{y}.png', function($z, $x, $y){
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, "127.0.0.1", 63825);
socket_connect($socket, env("TILESERVER_HOST"), env("TILESERVER_PORT"));
socket_write($socket, "$z;$x;$y\n", strlen("$z;$x,$y\n"));
socket_write($socket, "generate-tile;$z;$x;$y\n", strlen("generate-tile;$z;$x,$y\n"));
$content = "";
while(true){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment