Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit a5814c4

Browse files
committed
add map download
1 parent 5c534e0 commit a5814c4

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api\V1\Maps;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\Storage;
8+
9+
class DownloadController extends Controller
10+
{
11+
public function __invoke(string $game, string $map)
12+
{
13+
$path = $game . '/' . $map;
14+
if(!Storage::exists($path)) {
15+
abort(404);
16+
}
17+
return Storage::download($path);
18+
}
19+
}

app/Http/Controllers/Api/V1/Maps/SearchController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __invoke(SearchMapRequest $request)
2929
$out = 'Use the /map command to select or suggest the map on CnCNet (you must be inside of a game room)<br /><br /><br /><br />';
3030

3131
foreach ($result as $map) {
32-
$out .= $map['date'] . ' &emsp;/map ' . $map['hash'] . '&emsp; <A href="./' . $map['game'] . '/' . $map['hash'] . '.zip' . '">' .
32+
$out .= $map['date'] . ' &emsp;/map ' . $map['hash'] . '&emsp; <a href="'.url('/').'/' . $map['game'] . '/' . $map['hash'] . '.zip' . '">' .
3333
strip_tags($map['name']) .
3434
'</a><br /><br />';
3535
}

routes/api.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3+
use App\Http\Controllers\Api\V1\Maps\DownloadController;
34
use Illuminate\Http\Request;
45
use Illuminate\Support\Facades\Route;
56

67
Route::post('/upload', \App\Http\Controllers\Api\V1\Maps\UploadController::class);
7-
Route::get('/search', \App\Http\Controllers\Api\V1\Maps\SearchController::class)->middleware('throttle:map_search');
8+
Route::get('/search', \App\Http\Controllers\Api\V1\Maps\SearchController::class)->middleware('throttle:map_search');
9+
Route::get('/{game}/{map}', DownloadController::class);

routes/web.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
<?php
22

33
use Illuminate\Support\Facades\Route;
4-
5-
Route::post('/upload', \App\Http\Controllers\Api\V1\Maps\UploadController::class);

tests/Feature/DownloadTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use Illuminate\Foundation\Testing\RefreshDatabase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use Illuminate\Support\Facades\Storage;
8+
use Tests\TestCase;
9+
10+
class DownloadTest extends TestCase
11+
{
12+
/**
13+
* A basic feature test example.
14+
*/
15+
public function test_map_download(): void
16+
{
17+
Storage::fake();
18+
Storage::put('yr/889ca47cfcbe6005eac846ed1dcd14a1eefe6fa3.zip', Storage::disk('tests')->get('yr/889ca47cfcbe6005eac846ed1dcd14a1eefe6fa3.zip'));
19+
20+
$response = $this->get('/yr/889ca47cfcbe6005eac846ed1dcd14a1eefe6fa3.zip');
21+
22+
$response->assertStatus(200);
23+
$response->assertHeader('Content-Type', 'application/zip');
24+
}
25+
}

0 commit comments

Comments
 (0)