remote upload api update 2

This commit is contained in:
Čarodej
2022-05-03 08:10:50 +02:00
parent aca289b5a6
commit 2e61cee49c
3 changed files with 43 additions and 24 deletions

View File

@@ -37,7 +37,7 @@ class RemoteUploadFileController extends Controller
if (isNotBroadcasting()) {
($this->getContentFromExternalSource)($request->all(), $user);
return response()->json($successMessage);
return response()->json($successMessage, 201);
}
// Add links to the upload queue
@@ -48,6 +48,6 @@ class RemoteUploadFileController extends Controller
return response()->json([
'type' => 'success',
'message' => 'Files were successfully added to the upload queue.',
]);
], 201);
}
}

View File

@@ -15,11 +15,13 @@ class UploadFilesRemotelyForUploadRequestController
) {
}
/**
* @throws FileNotFoundException
*/
public function __invoke(RemoteUploadRequest $request, UploadRequest $uploadRequest)
{
$successMessage = [
'type' => 'success',
'message' => 'Files was successfully uploaded.',
];
// Get upload request root folder query
$folder = Folder::where('id', $uploadRequest->id);
@@ -33,19 +35,25 @@ class UploadFilesRemotelyForUploadRequestController
$request->merge(['parent_id' => $uploadRequest->id]);
}
// Get content from external sources
if (isBroadcasting()) {
($this->getContentFromExternalSource)
->onQueue()
->execute($request->all(), $uploadRequest->user);
} else {
($this->getContentFromExternalSource)($request->all(), $uploadRequest->user);
}
// Set timestamp for auto filling
cache()->set("auto-filling.$uploadRequest->id", now()->toString());
return response('Files were successfully added to the upload queue', 201);
// If it isn't broadcasting, download files immediately in the request
if (isNotBroadcasting()) {
($this->getContentFromExternalSource)($request->all(), $uploadRequest->user);
return response()->json($successMessage, 201);
}
// Add links to the upload queue
($this->getContentFromExternalSource)
->onQueue()
->execute($request->all(), $uploadRequest->user);
return response()->json([
'type' => 'success',
'message' => 'Files were successfully added to the upload queue.',
], 201);
}
/**

View File

@@ -1,7 +1,7 @@
<?php
namespace Domain\RemoteUpload\Controllers;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use Domain\Sharing\Models\Share;
use App\Http\Controllers\Controller;
use Domain\RemoteUpload\Requests\RemoteUploadRequest;
@@ -18,8 +18,13 @@ class VisitorRemoteUploadFileController extends Controller
) {
}
public function __invoke(RemoteUploadRequest $request, ?Share $shared = null): Response|array
public function __invoke(RemoteUploadRequest $request, ?Share $shared = null): JsonResponse
{
$successMessage = [
'type' => 'success',
'message' => 'Files was successfully uploaded.',
];
// Check ability to access protected share record
($this->protectShareRecord)($shared);
@@ -31,15 +36,21 @@ class VisitorRemoteUploadFileController extends Controller
// Check access to requested directory
($this->verifyAccessToItem)($request->input('parent_id'), $shared);
// Get content from external sources
if (isBroadcasting()) {
($this->getContentFromExternalSource)
->onQueue()
->execute($request->all(), $shared->user);
} else {
// If it isn't broadcasting, download files immediately in the request
if (isNotBroadcasting()) {
($this->getContentFromExternalSource)($request->all(), $shared->user);
return response()->json($successMessage, 201);
}
return response('Files were successfully added to the upload queue', 201);
// Add links to the upload queue
($this->getContentFromExternalSource)
->onQueue()
->execute($request->all(), $shared->user);
return response()->json([
'type' => 'success',
'message' => 'Files were successfully added to the upload queue.',
], 201);
}
}