M3 Integration fixes
This commit is contained in:
Regular → Executable
+16
-20
@@ -15,6 +15,10 @@ use Modules\Documentation\Models\DocumentationDocument;
|
||||
|
||||
class DocumentationController extends Controller
|
||||
{
|
||||
private const string STORAGE_DISK_CONFIG = 'documentation.storage_disk';
|
||||
|
||||
private const string UPLOAD_PATH_CONFIG = 'documentation.upload_path';
|
||||
|
||||
/**
|
||||
* Display the documentation dashboard and document list.
|
||||
*/
|
||||
@@ -170,7 +174,7 @@ class DocumentationController extends Controller
|
||||
{
|
||||
abort_if(blank($document->attachment_path), 404);
|
||||
|
||||
return Storage::disk($document->attachment_disk ?: config('documentation.storage_disk', 'public'))
|
||||
return Storage::disk($document->attachment_disk ?: config(self::STORAGE_DISK_CONFIG, 'public'))
|
||||
->download($document->attachment_path, $document->attachment_name);
|
||||
}
|
||||
|
||||
@@ -202,27 +206,19 @@ class DocumentationController extends Controller
|
||||
*/
|
||||
private function extractMarkdownBody(Request $request): ?string
|
||||
{
|
||||
if (! config('documentation.import_markdown_attachments', true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$file = $request->file('attachment');
|
||||
$canImport = config('documentation.import_markdown_attachments', true)
|
||||
&& $file !== null
|
||||
&& $this->isMarkdownUpload($request)
|
||||
&& $file->getSize() <= (int) config('documentation.max_markdown_import_bytes', 1048576);
|
||||
|
||||
if ($file === null || ! $this->isMarkdownUpload($request)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($file->getSize() > (int) config('documentation.max_markdown_import_bytes', 1048576)) {
|
||||
if (! $canImport) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$content = file_get_contents($file->getRealPath());
|
||||
|
||||
if ($content === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return trim($content);
|
||||
return $content === false ? null : trim($content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,8 +246,8 @@ class DocumentationController extends Controller
|
||||
private function storeAttachment(Request $request): array
|
||||
{
|
||||
$file = $request->file('attachment');
|
||||
$disk = config('documentation.storage_disk', 'public');
|
||||
$path = $file->store(config('documentation.upload_path', 'documentation'), $disk);
|
||||
$disk = config(self::STORAGE_DISK_CONFIG, 'public');
|
||||
$path = $file->store(config(self::UPLOAD_PATH_CONFIG, 'documentation'), $disk);
|
||||
|
||||
return [
|
||||
'attachment_disk' => $disk,
|
||||
@@ -271,14 +267,14 @@ class DocumentationController extends Controller
|
||||
return;
|
||||
}
|
||||
|
||||
$disk = config('documentation.storage_disk', 'public');
|
||||
$disk = config(self::STORAGE_DISK_CONFIG, 'public');
|
||||
|
||||
foreach ((array) $request->file('attachments') as $file) {
|
||||
if ($file === null || ! $file->isValid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $file->store(config('documentation.upload_path', 'documentation'), $disk);
|
||||
$path = $file->store(config(self::UPLOAD_PATH_CONFIG, 'documentation'), $disk);
|
||||
|
||||
$document->attachments()->create([
|
||||
'disk' => $disk,
|
||||
@@ -297,7 +293,7 @@ class DocumentationController extends Controller
|
||||
private function deleteAttachment(DocumentationDocument $document): void
|
||||
{
|
||||
if (filled($document->attachment_path)) {
|
||||
Storage::disk($document->attachment_disk ?: config('documentation.storage_disk', 'public'))->delete($document->attachment_path);
|
||||
Storage::disk($document->attachment_disk ?: config(self::STORAGE_DISK_CONFIG, 'public'))->delete($document->attachment_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user