This repository was archived by the owner on Mar 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +48
-4
lines changed
app/Http/Controllers/Api/V1/Maps Expand file tree Collapse file tree 5 files changed +48
-4
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 ' ] . '  /map ' . $ map ['hash ' ] . '  <A href=". / ' . $ map ['game ' ] . '/ ' . $ map ['hash ' ] . '.zip ' . '"> ' .
32+ $ out .= $ map ['date ' ] . '  /map ' . $ map ['hash ' ] . '  <a href=" ' . url ( ' / ' ). ' / ' . $ map ['game ' ] . '/ ' . $ map ['hash ' ] . '.zip ' . '"> ' .
3333 strip_tags ($ map ['name ' ]) .
3434 '</a><br /><br /> ' ;
3535 }
Original file line number Diff line number Diff line change 11<?php
22
3+ use App \Http \Controllers \Api \V1 \Maps \DownloadController ;
34use Illuminate \Http \Request ;
45use Illuminate \Support \Facades \Route ;
56
67Route::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);
Original file line number Diff line number Diff line change 11<?php
22
33use Illuminate \Support \Facades \Route ;
4-
5- Route::post ('/upload ' , \App \Http \Controllers \Api \V1 \Maps \UploadController::class);
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments