stable

Clone or download

Read-only

Implements Tus protocol for FRS REST API

You can now use tus client to upload file in the FRS through REST API. Implementation note ------------------- The specificity of fileforge is that it depends on the utilitary script fileforge.pl to be able to create files in folders owned by root (fileforge has sticky bit). However fileforge.pl need the real filename in the upload directory to be able to move it. Therefore this patch is introducing the filename in the TusFileInformation to allow FRS implementation to be able to create file with real filename instead of just the id. I'm not really proud of that, but I couldn't find a better way without breaking the current implementation. Other options would be: - update fileforge.pl to not rely on the filename in the upload directory - update access rights in /var/lib/tuleap/ftp/tuleap directory so that codendiadm/tuleapadm can create files without having to rely on an external script with sticky bit This can be done in a dedicated changeset. How to test ----------- To test you can use the following snippet. You will have to provide the path to the tus.js client library and update the release id to match your environment. Upload information (progress) is displayed on the devtools console. When the upload is done you can assert that the file is present in the release through the web UI. Note: after 1 second, the upload is automatically aborted (see timeout at the end of the script), so that we can test the abort. In this case, there isn't any leftovers in /var/tmp/frs/ongoin-upload dir. ```html <input type="file" id="myfile"> <script src="tus.js"></script> <script> document.getElementById('myfile').addEventListener('change', async (e) => { const release_id = 1; const file = e.target.files[0]; const post_response = await fetch('/api/v1/frs_files', { method: 'POST', credentials: 'same-origin', headers: { "Content-Type": "application/json" }, body: JSON.stringify({ release_id, name: file.name, file_size: file.size }) }); const post_response_body = await post_response.json(); const upload_href = post_response_body["upload_href"]; // Create a new tus upload const upload = new tus.Upload(file, { uploadUrl: upload_href, retryDelays: [0, 3000, 5000], metadata: { filename: file.name, filetype: file.type }, onError: function(error) { console.log("Failed because: " + error); }, onProgress: function(bytesUploaded, bytesTotal) { const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2); console.log(bytesUploaded, bytesTotal, percentage + "%"); }, onSuccess: function() { console.log("Download %s from %s", upload.file.name, upload.url); alert('Done'); } }); // Start the upload upload.start(); setTimeout(() => { upload.abort(); }, 1000); }); </script> ``` Part of story #12813: upload files with FRS REST API Change-Id: I253b4190115548d2da727e64417a86c43b87054a

Modified Files

Name
M plugins/docman/include/REST/v1/DocmanItemCreator.php +1 −1 Go to diff View file
M plugins/docman/include/REST/v1/EmptyFileToUploadFinisher.php +3 −3 Go to diff View file
M plugins/docman/include/Upload/Document/DocumentBeingUploadedInformationProvider.php +6 −6 Go to diff View file
M plugins/docman/include/Upload/Version/VersionBeingUploadedInformationProvider.php +5 −4 Go to diff View file
M plugins/docman/phpunit/Upload/Document/DocumentBeingUploadedInformationProviderTest.php +4 −2 Go to diff View file
M plugins/docman/phpunit/Upload/Document/DocumentUploadCleanerTest.php +2 −2 Go to diff View file
M plugins/docman/phpunit/Upload/Document/DocumentUploadFinisherTest.php +3 −4 Go to diff View file
M plugins/docman/phpunit/Upload/Document/DocumentUploadPathAllocatorTest.php +2 −2 Go to diff View file
M plugins/docman/phpunit/Upload/Version/VersionBeingUploadedInformationProviderTest.php +4 −2 Go to diff View file
M plugins/docman/phpunit/Upload/Version/VersionUploadCleanerTest.php +2 −2 Go to diff View file
M plugins/docman/phpunit/Upload/Version/VersionUploadFinisherTest.php +3 −3 Go to diff View file
M plugins/docman/phpunit/Upload/Version/VersionUploadPathAllocatorTest.php +2 −2 Go to diff View file
M plugins/frs/include/FRS/Upload/FileOngoingUploadDao.php +28 −2 Go to diff View file
M plugins/frs/include/FRS/Upload/FileToUpload.php +1 −1 Go to diff View file
A plugins/frs/include/FRS/Upload/Tus/FileBeingUploadedInformationProvider.php +87 −0 Go to diff View file
A plugins/frs/include/FRS/Upload/Tus/FileDataStore.php +95 −0 Go to diff View file
A plugins/frs/include/FRS/Upload/Tus/FileUploadCanceler.php +63 −0 Go to diff View file
A plugins/frs/include/FRS/Upload/Tus/FileUploadFinisher.php +157 −0 Go to diff View file
A plugins/frs/include/FRS/Upload/Tus/ToBeCreatedFRSFileBuilder.php +50 −0 Go to diff View file
A plugins/frs/include/FRS/Upload/UploadPathAllocator.php +40 −0 Go to diff View file
M plugins/frs/include/frsPlugin.class.php +67 −5 Go to diff View file
M plugins/frs/phpunit/FRS/Upload/FileToUploadCreatorTest.php +2 −2 Go to diff View file
A plugins/frs/phpunit/FRS/Upload/Tus/FileBeingUploadedInformationProviderTest.php +86 −0 Go to diff View file
A plugins/frs/phpunit/FRS/Upload/Tus/FileUploadCancelerTest.php +74 −0 Go to diff View file
A plugins/frs/phpunit/FRS/Upload/Tus/FileUploadFinisherTest.php +192 −0 Go to diff View file
A plugins/frs/phpunit/FRS/Upload/UploadPathAllocatorTest.php +39 −0 Go to diff View file
M plugins/frs/tests/rest/FRS/FileTest.php +71 −14 Go to diff View file
M plugins/webdav/tests/WebDAVFRSFileTest.php +4 −5 Go to diff View file
M plugins/webdav/tests/WebDAVFRSReleaseTest.php +5 −6 Go to diff View file
M src/common/Tus/TusFileInformation.php +1 −0 Go to diff View file
R plugins/docman/include/Upload/DocumentAlreadyUploadedInformation.php Go to diff View file
M src/common/Upload/FileBeingUploadedInformation.php +16 −11 Go to diff View file
M src/common/Upload/FileUploadController.php +5 −8 Go to diff View file
M src/common/dao/FRSLogDao.class.php +8 −19 Go to diff View file
M src/common/frs/FRSFileFactory.class.php +8 −5 Go to diff View file
M src/common/frs/FRSLog.class.php +6 −6 Go to diff View file
R plugins/docman/phpunit/Upload/DocumentBeingUploadedLockerTest.php Go to diff View file
M tests/phpunit/common/Upload/FileBeingUploadedWriterTest.php +2 −2 Go to diff View file
M tests/rest/bin/setup.sh +1 −1 Go to diff View file
M tests/simpletest/common/backend/BackendSystemTest.php +2 −3 Go to diff View file
M tests/simpletest/common/system_event/include/SystemEvent_COMPUTE_MD5SUM_Test.php +10 −12 Go to diff View file