Skip to content

Commit

Permalink
MED-100: Fix resumable upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Apr 20, 2024
1 parent bfef526 commit 9fcc17c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion source/vimeo/amd/build/file_upload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion source/vimeo/amd/build/file_upload.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions source/vimeo/amd/src/file_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@ const upload = async(resource) => {
const file = document.querySelector('input[name="videofile"]').files[0];
const url = new URL(Config.wwwroot + '/admin/tool/mediatime/index.php');
let offset = 0;
let response;

url.searchParams.set('id', resource.id);

do {
const request = new Request(resource.uploadurl, {
body: file,
body: file.slice(Number(offset)),
headers: {
'Tus-Resumable': '1.0.0',
'Upload-Offset': String(offset),
'Content-Type': 'application/offset+octet-stream'
},
method: 'PATCH'
});
response = await fetch(request);
document.querySelector('.progress').style.width = (response.headers.get('Upload-Offset') / file.size * 100) + '%';
Log.debug(response.headers.get('Upload-Offset'));
} while (response.headers.get('Upload-Offset') < file.size);
const response = await fetch(request);
if (response.ok) {
offset = response.headers.get('Upload-Offset');
}
document.querySelector('.progress').style.width = ( offset / file.size * 100) + '%';
Log.debug(offset);
} while (offset < file.size);
window.location.href = url;
};

Expand Down
4 changes: 2 additions & 2 deletions source/vimeo/classes/external/create_token.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public static function execute($description, $filesize, $name, $tags, $title): a
'size' => $params['filesize'],
],
]);
$video = $api->request($video['uri'], [
$updatedvideo = $api->request($video['uri'], [
'name' => $params['title'],
'description' => $params['description'],
], 'PATCH')['body'];
$id = $DB->insert_record('tool_mediatime', [
'name' => $params['name'],
'source' => 'vimeo',
'content' => json_encode($video),
'content' => json_encode($updatedvideo),
'timecreated' => time(),
'timemodified' => time(),
'usermodified' => $USER->id,
Expand Down
2 changes: 2 additions & 0 deletions source/vimeo/lang/en/mediatimesrc_vimeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
$string['uploadnewfile'] = 'Upload new file';
$string['videofile'] = 'Video file';
$string['videofile_help'] = 'Choose to upload a new video, or choose to use an existing one that you select';
$string['videoupload'] = 'Vimeo video upload';
$string['videoupload_help'] = 'Add video file and click \'upload\'. The file will be uploaded from your computer to Vimeo with the information you entered on the previous form. The video will be viewable after Vimeo receives the file and has had time to process it.';
$string['vimeo:upload'] = 'Upload files to Vimeo';
$string['vimeo:viewall'] = 'View all files available';
$string['vimeofileaction'] = 'Vimeo file action';
Expand Down
2 changes: 2 additions & 0 deletions source/vimeo/templates/file_upload.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
}}
<form id="upload_resource_form" method="post" action=".">
<div class="container-fluid">
<h3>{{# str }} videoupload, mediatimesrc_vimeo {{/ str }}</h3>
<p>{{# str }} videoupload_help, mediatimesrc_vimeo {{/ str }}</p>
<input type="hidden" name="create" value="" >
<input type="hidden" name="source" value="vimeo" >
<input type="hidden" name="filesize" value="" >
Expand Down

0 comments on commit 9fcc17c

Please sign in to comment.