Skip to content

Commit c1e1ab4

Browse files
committed
Make /files/primary return only file and /download shouldn't download w/o primary file
1 parent 47a4767 commit c1e1ab4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

backend/app/Http/Controllers/FileController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,14 @@ function downloadLatestFileVersion(Request $request, Mod $mod) {
419419
/**
420420
* Get Primary File
421421
*
422-
* Returns the primary file of the mod (the primary download)
422+
* Returns the primary file of the mod or the only file
423423
*/
424424
public function getPrimaryFile(Request $request, Mod $mod) {
425-
if ($mod->download_type == 'file') {
426-
return $mod->downloadRelation;
425+
$file = $mod->download;
426+
if (!$file instanceof File) {
427+
abort(404);
427428
}
429+
return $file;
428430
}
429431

430432
/**

backend/app/Http/Controllers/ModController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,14 +679,12 @@ public function report(Request $request, Mod $mod)
679679
* @group Files
680680
*/
681681
public function downloadPrimaryFile(Mod $mod) {
682-
$file = $mod->downloadRelation;
683-
if (!$file instanceof File) {
684-
$file = $mod->files()->firstOrFail();
685-
}
682+
$file = $mod->download;
683+
686684
if (isset($file)) {
687685
return redirect($file->downloadUrl);
688686
} else {
689-
return abort(404, 'Mod has no files!');
687+
return abort(404, 'Mod has no files or has no primary file');
690688
}
691689
}
692690

0 commit comments

Comments
 (0)