Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign and allow people to upload in the multiple locations #31

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7ee9ba4
Handle translation
NastuzziSamy Feb 5, 2018
8a3c86a
Merge pull request #14 from NastuzziSamy/master
e-alfred Feb 7, 2018
494f898
Updated ng-flow version (2.7.7), fixed regex for character sanitation
e-alfred Feb 7, 2018
96f42df
Improved santitation of directory paths
e-alfred Feb 7, 2018
434dfed
Fix deprecated API call \OCP\addNavigationEntry()
e-alfred Feb 12, 2018
5003da0
Remove deprecated PHP requirements
e-alfred Feb 12, 2018
b253fb0
Remove deprecated file appinfo/version
e-alfred Feb 12, 2018
31bb5aa
Added German translation
e-alfred Feb 13, 2018
6636bbd
Bump supported version and remove Owncloud
e-alfred Feb 14, 2018
bdb2657
Improve translations
e-alfred Feb 14, 2018
0a467c1
Create pl.js
mzary Mar 3, 2018
1e0b525
Create pl.json
mzary Mar 3, 2018
2d85345
Merge pull request #19 from mzary/patch-1
e-alfred Mar 5, 2018
3b97d1f
Merge pull request #18 from mzary/patch-2
e-alfred Mar 5, 2018
dee4e37
Add files via upload
Mar 5, 2018
f0c6bee
add one string
Mar 5, 2018
b8c83d8
better ..
Mar 5, 2018
e83920a
Merge pull request #21 from CHazz/master
e-alfred Mar 7, 2018
259120f
Fixed missing "Select folder" translation
e-alfred Mar 7, 2018
d8bc52e
Add issue template
e-alfred Mar 12, 2018
1cf3a59
Update fr.js
Larsene Mar 22, 2018
7a4441b
Update fr.json
Larsene Mar 22, 2018
c522af6
Merge pull request #27 from Larsene/patch-1
e-alfred Mar 26, 2018
6ac767f
Merge pull request #28 from Larsene/patch-2
e-alfred Mar 26, 2018
7df5374
Removed deprecated \OCP\Util methods
e-alfred Mar 26, 2018
0f843fe
Remove deprecated methods
e-alfred Mar 26, 2018
3aec537
Merge remote-tracking branch 'origin/master'
NastuzziSamy Apr 24, 2018
603b35a
Redesign
NastuzziSamy Apr 24, 2018
919129d
Preparation of the location feature
NastuzziSamy Apr 24, 2018
12ec459
Possibility to upload in diferent locations in the same time
NastuzziSamy Apr 24, 2018
0dfd866
Add me as author and update the version
NastuzziSamy Apr 24, 2018
2d53cc0
Merge branch 'master' into master
NastuzziSamy Apr 24, 2018
fab627e
Merge branch 'master' into master
NastuzziSamy Apr 25, 2018
c40285a
Merge remote-tracking branch 'e-alfred/master'
NastuzziSamy Oct 21, 2018
0766698
Fix deprecated calls for NC14+ compatibliity
e-alfred Jan 4, 2019
43f3b0b
Merge branch 'master' into master
e-alfred Jan 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions ajax/locations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
// Restrict access // ToDo: Enabled for current user?
if (!\OCP\User::isLoggedIn() || !\OCP\App::isEnabled('flowupload')) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have to change this function because both calls are deprecated.

\OC_Response::setStatus(403);
}

function getAllLocations() {
// ToDo: Return locations from database
return array(
array(
'id' => 0,
'location' => '/flowupload/',
'pause' => 0,
'uploading' => 0,
'completed' => 0,
'aborted' => 0
)
);
}

function addNewLocation($location) {
// ToDo: Add to database
$location = preg_replace('/(\.\.\/|~|\/\/)/i', '', '/'.$location.'/');
$location = preg_replace('/[^a-z0-9äöüß \(\)\.\-_\/]/i', '', $location);
$location = trim($location);

return $location;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$_POST = json_decode(file_get_contents('php://input'), true);

if (isset($_POST['location']) && \OC\Files\Filesystem::isValidPath($_POST['location'])) {
$locations = getAllLocations();

foreach ($locations as $location) {
if ($location['location'] === $_POST['location']) {
\OC_Response::setStatus(409);
die();
}
}

\OC_Response::setStatus(201);

$location = addNewLocation($_POST['location']);

echo json_encode(array(
'id' => preg_replace('#/#', '', $location),
'location' => $location,
'pause' => 0,
'uploading' => 0,
'completed' => 0,
'aborted' => 0
));
}
else {
\OC_Response::setStatus(400);
}

die();
}

echo json_encode(array(
"locations" => getAllLocations()
));
?>
3 changes: 2 additions & 1 deletion ajax/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// Directory definitions
$userhome = OC_User::getHome(OC_User::getUser());
$temp = $userhome.'/.flowupload_tmp/';
$result = '/flowupload/';
$result = $_REQUEST['target'] ?? '/flowupload/';
$result = '/'.$result.'/';

// Initialize uploader
$config = new \Flow\Config();
Expand Down
3 changes: 2 additions & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<id>flowupload</id>
<name>Flow Upload</name>
<description>Provides functions to upload large files with your HTML5-Browser.</description>
<version>0.0.7</version>
<version>0.1.0</version>
<licence>AGPL</licence>
<author>Patrick Schwarz</author>
<author>e-alfred</author>
<author>NastuzziSamy</author>
<category>tools</category>
<website>https://github.com/e-alfred/flowupload</website>
<repository>https://github.com/e-alfred/flowupload</repository>
Expand Down
5 changes: 4 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
->actionInclude('flowupload/index.php');

$this->create('flowupload_ajax_upload', 'ajax/upload.php')
->actionInclude('flowupload/ajax/upload.php');
->actionInclude('flowupload/ajax/upload.php');

$this->create('flowupload_ajax_locations', 'ajax/locations.php')
->actionInclude('flowupload/ajax/locations.php');
12 changes: 12 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
\OCP\Util::addScript('flowupload', 'angular');
\OCP\Util::addScript('flowupload', 'ng-flow-standalone');
\OCP\Util::addScript('flowupload', 'app');
\OCP\Util::addScript('flowupload', 'script');
\OCP\Util::addStyle('flowupload', 'bootstrap-combined');

$locations = array(
array(
'id' => 0,
'location' => '/flowupload/',
'nbrInPause' => 0,
'nbrUploading' => 0,
'nbrCompleted' => 0,
'nbrAborted' => 0,
)
);

$tpl = new OCP\Template("flowupload", "main", "user");
$tpl->printPage();
143 changes: 124 additions & 19 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,135 @@
'use strict';

/**
* The main app module
* @name app
* @type {angular.Module}
*/
var app = angular.module('app', ['flow'])
.config(['flowFactoryProvider', function (flowFactoryProvider) {
flowFactoryProvider.defaults = {
target: 'ajax/upload.php',
permanentErrors: [403, 404, 500, 501],
maxChunkRetries: 2,
chunkRetryInterval: 5000,
simultaneousUploads: 4
};
flowFactoryProvider.on('catchAll', function (event) {
console.log('catchAll', arguments);
});
* The main app module
* @name app
* @type {angular.Module}
*/
var app = angular.module('app', ['flow']).config(['flowFactoryProvider', function (flowFactoryProvider) {
flowFactoryProvider.defaults = {
target: 'ajax/upload.php',
permanentErrors: [403, 404, 500, 501],
maxChunkRetries: 2,
chunkRetryInterval: 5000,
simultaneousUploads: 4
};
flowFactoryProvider.on('catchAll', function ($event, file) {
if ($event === 'fileAdded')
console.log(file);
});
}]);

app.filter('bytes', function() {
app.filter('bytes', function () {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || bytes == 0 || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;

var units = ['bytes', 'kB', 'MB', 'GB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
number = Math.floor(Math.log(bytes) / Math.log(1024));

return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
});
});

app.controller('location', function ($scope) {
$scope.init = function (id, name) {
$scope.locationId = id;
$scope.locationName = name;
}

$scope.seeUploads = function ($event, type) {
$event.stopPropagation();
$event.preventDefault();

console.log($scope);

$('#locations li.active').removeClass('active');

$($event.currentTarget).addClass('active');
};

$scope.beforeUploading = {
query: function (flowFile, flowChunk) {
// function will be called for every request
console.log('File', flowFile);
console.log('Chunk', flowChunk);
return {
//id: $scope.locationId
// Temporary:
target: $scope.locationName
};
}
};
});

app.controller('flow', function ($scope) {
$scope.locationId = 0;

$scope.$on('changeLocation', function (event, id, $flow) {
$scope.locationId = id;
$scope.$flow = $flow;

console.log(id);
console.log($flow);
});
});

app.controller('locations', function ($rootScope, $scope, $http) {
$scope.isOpen = false;

$scope.reloadLocations = function () {
setTimeout(function () {
if ($scope.locationId === undefined)
$($($('.locations')[0]).find('a')).click();
else
$($('#location-' + $scope.locationId).find('a')).click();
}, 100);
}

$scope.setLocation = function (id, $flow) {
$rootScope.$broadcast('changeLocation', id, $flow);
$scope.$flow = $flow;
$scope.locationId = id;

$('.locations').each(function () {
if ($(this).attr('id') === 'location-' + id)
$(this).addClass('open');
else
$(this).removeClass('open');
}
);
}

$scope.getLocations = function () {
$http({
method: "GET",
url: "ajax/locations.php"
}).then(function mySuccess(response) {
$scope.locations = response.data.locations;

$scope.locationId = $scope.locations[0].id;
}, function myError(response) {
$scope.locations = {};
}
);
};

$scope.addNewLocation = function () {
$http({
method : "POST",
url : "ajax/locations.php",
data : {
location: $('#newLocationName').val()
}
}).then(function mySuccess(response) {
$('#newLocationName').val('');

$scope.locationId = response.data.id;
$scope.locations.push(response.data);
}, function myError(response) {
$scope.locations = {};
});
};

$scope.getLocations();
});
Loading