Improved partial content implementation

Fixed issue #27
This commit is contained in:
Sergio Brighenti 2019-04-10 21:28:40 +02:00
parent 86ee13a491
commit 5f274cb493
5 changed files with 21 additions and 18 deletions

View file

@ -31,7 +31,7 @@ class ThemeController extends Controller
{
if (!is_writable('static/bootstrap/css/bootstrap.min.css')) {
$this->session->alert(lang('cannot_write_file'), 'danger');
return redirect($response, route('system'));
return redirect($response, 'system');
}
file_put_contents('static/bootstrap/css/bootstrap.min.css', file_get_contents($request->getParam('css')));

View file

@ -26,7 +26,7 @@ class UploadController extends Controller
$json = [
'message' => null,
'version' => PLATFORM_VERSION
'version' => PLATFORM_VERSION,
];
if ($this->settings['maintenance'] && !$this->database->query('SELECT `id`, `is_admin` FROM `users` WHERE `id` = ? LIMIT 1', [$this->session->get('user_id')])->fetch()->is_admin) {
@ -369,7 +369,15 @@ class UploadController extends Controller
$end = ($end > $stream->getSize() - 1) ? $stream->getSize() - 1 : $end;
$stream->seek($start);
$buffer = 16384;
header("Content-Type: $mime");
header('Content-Length: ' . ($end - $start + 1));
header('Accept-Ranges: bytes');
header("Content-Range: bytes $start-$end/{$stream->getSize()}");
http_response_code(206);
ob_end_clean();
$buffer = 16348;
$readed = $start;
while ($readed < $end) {
if ($readed + $buffer > $end) {
@ -379,11 +387,7 @@ class UploadController extends Controller
$readed += $buffer;
}
return $response->withHeader('Content-Type', $mime)
->withHeader('Content-Length', $end - $start + 1)
->withHeader('Accept-Ranges', 'bytes')
->withHeader('Content-Range', "bytes $start-$end/{$stream->getSize()}")
->withStatus(206);
exit(0);
}
return $response->withHeader('Content-Type', $mime)

View file

@ -1,6 +1,6 @@
{
"name": "sergix44/xbackbone",
"version": "2.5",
"version": "2.5.1",
"description": "A lightweight ShareX PHP backend",
"type": "project",
"require": {

4
composer.lock generated
View file

@ -1,10 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "79d2941e9db0718ad1f2766ff912f324",
"content-hash": "1ad298d75b7e5c96f85c2c32a24e2502",
"packages": [
{
"name": "container-interop/container-interop",

13
package-lock.json generated
View file

@ -1,5 +1,4 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"@babel/runtime": {
@ -1577,18 +1576,18 @@
"integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==",
"dev": true
},
"string-template": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/string-template/-/string-template-0.2.1.tgz",
"integrity": "sha1-QpMuWYo1LQH8IuwzZ9nYTuxsmt0=",
"dev": true
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
},
"string-template": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/string-template/-/string-template-0.2.1.tgz",
"integrity": "sha1-QpMuWYo1LQH8IuwzZ9nYTuxsmt0=",
"dev": true
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",