stable

Clone or download

Read-only

Implement tus protocol for Tracker REST API

First step to be able to attach files to an artifact with tus. 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 field 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 (and identical to the uploaded one) in the filesystem under /var/lib/tuleap/tracker/<field_id>. ``` <input type="file" id="myfile"> <script src="tus.js"></script> <script> document.getElementById('myfile').addEventListener('change', async (e) => { const field_id = 94; const file = e.target.files[0]; const post_response = await fetch(`/api/v1/tracker_fields/${field_id}/files`, { method: 'POST', credentials: 'same-origin', headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: file.name, file_size: file.size, file_type: file.type }) }); 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(" %s uploaded to %s", upload.file.name, upload.url); alert('Done'); } }); // Start the upload upload.start(); }); </script> ``` Part of story #12964: drag'n drop images in tracker text areas Change-Id: I244c0dc6d11b2d8dec124e5e0fd80b591fec497c

Modified Files

Name
M plugins/tracker/db/install.sql +8 −0 Go to diff View file
A plugins/tracker/db/mysql/updates/2019/201905090927_create_file_upload_table.php +44 −0 Go to diff View file
M plugins/tracker/db/uninstall.sql +1 −0 Go to diff View file
A plugins/tracker/include/REST/v1/CreatedFileRepresentation.php +34 −0 Go to diff View file
A plugins/tracker/include/REST/v1/FileCreator.php +85 −0 Go to diff View file
A plugins/tracker/include/REST/v1/FilePOSTRepresentation.php +39 −0 Go to diff View file
M plugins/tracker/include/REST/v1/TrackerFieldsResource.php +111 −20 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/EmptyFileToUploadFinisher.php +58 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/FileOngoingUploadDao.php +144 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/FileToUpload.php +45 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/FileToUploadCreator.php +135 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/Tus/FileBeingUploadedInformationProvider.php +90 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/Tus/FileDataStore.php +89 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/Tus/FileUploadCanceler.php +57 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/UploadCreationConflictException.php +30 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/UploadCreationException.php +25 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/UploadCreationFileMismatchException.php +29 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/UploadMaxSizeExceededException.php +33 −0 Go to diff View file
A plugins/tracker/include/Tracker/FormElement/Field/File/Upload/UploadPathAllocator.php +89 −0 Go to diff View file
M plugins/tracker/include/Tracker/FormElement/Tracker_FormElementFactory.class.php +8 −0 Go to diff View file
M plugins/tracker/include/Tracker/Tracker.class.php +1 −1 Go to diff View file
M plugins/tracker/include/trackerPlugin.class.php +35 −0 Go to diff View file
A plugins/tracker/phpunit/Tracker/FormElement/Field/File/Upload/EmptyFileToUploadFinisherTest.php +48 −0 Go to diff View file
A plugins/tracker/phpunit/Tracker/FormElement/Field/File/Upload/FileToUploadCreatorTest.php +211 −0 Go to diff View file
A plugins/tracker/phpunit/Tracker/FormElement/Field/File/Upload/Tus/FileBeingUploadedInformationProviderTest.php +94 −0 Go to diff View file
A plugins/tracker/phpunit/Tracker/FormElement/Field/File/Upload/Tus/FileUploadCancelerTest.php +73 −0 Go to diff View file
A plugins/tracker/phpunit/Tracker/FormElement/Field/File/Upload/UploadPathAllocatorTest.php +59 −0 Go to diff View file
M plugins/tracker/tests/rest/TrackerFields/TrackerFieldsTest.php +109 −4 Go to diff View file
M plugins/tracker/tests/rest/_fixtures/TrackerFields/project.xml +7 −0 Go to diff View file