Skip to content
Snippets Groups Projects
Commit a203a4a1 authored by Robin Appelman's avatar Robin Appelman
Browse files

add support to mount a specific folder from dropbox

parent 54695b11
No related branches found
No related tags found
No related merge requests found
...@@ -25,21 +25,25 @@ require_once 'Dropbox/autoload.php'; ...@@ -25,21 +25,25 @@ require_once 'Dropbox/autoload.php';
class OC_Filestorage_Dropbox extends OC_Filestorage_Common { class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
private $dropbox; private $dropbox;
private $root;
private $metaData = array(); private $metaData = array();
private static $tempFiles = array(); private static $tempFiles = array();
public function __construct($params) { public function __construct($params) {
if (isset($params['configured']) && $params['configured'] == 'true' && isset($params['app_key']) && isset($params['app_secret']) && isset($params['token']) && isset($params['token_secret'])) { if (isset($params['configured']) && $params['configured'] == 'true' && isset($params['app_key']) && isset($params['app_secret']) && isset($params['token']) && isset($params['token_secret'])) {
$this->root=isset($params['root'])?$params['root']:'';
$oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']); $oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']);
$oauth->setToken($params['token'], $params['token_secret']); $oauth->setToken($params['token'], $params['token_secret']);
$this->dropbox = new Dropbox_API($oauth, 'dropbox'); $this->dropbox = new Dropbox_API($oauth, 'dropbox');
$this->mkdir('');
} else { } else {
throw new Exception('Creating OC_Filestorage_Dropbox storage failed'); throw new Exception('Creating OC_Filestorage_Dropbox storage failed');
} }
} }
private function getMetaData($path, $list = false) { private function getMetaData($path, $list = false) {
$path = $this->root.$path;
if (!$list && isset($this->metaData[$path])) { if (!$list && isset($this->metaData[$path])) {
return $this->metaData[$path]; return $this->metaData[$path];
} else { } else {
...@@ -76,6 +80,7 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -76,6 +80,7 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} }
public function mkdir($path) { public function mkdir($path) {
$path = $this->root.$path;
try { try {
$this->dropbox->createFolder($path); $this->dropbox->createFolder($path);
return true; return true;
...@@ -144,6 +149,7 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -144,6 +149,7 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} }
public function unlink($path) { public function unlink($path) {
$path = $this->root.$path;
try { try {
$this->dropbox->delete($path); $this->dropbox->delete($path);
return true; return true;
...@@ -154,6 +160,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -154,6 +160,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} }
public function rename($path1, $path2) { public function rename($path1, $path2) {
$path1 = $this->root.$path1;
$path2 = $this->root.$path2;
try { try {
$this->dropbox->move($path1, $path2); $this->dropbox->move($path1, $path2);
return true; return true;
...@@ -164,6 +172,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -164,6 +172,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} }
public function copy($path1, $path2) { public function copy($path1, $path2) {
$path1 = $this->root.$path1;
$path2 = $this->root.$path2;
try { try {
$this->dropbox->copy($path1, $path2); $this->dropbox->copy($path1, $path2);
return true; return true;
...@@ -174,6 +184,7 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { ...@@ -174,6 +184,7 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
} }
public function fopen($path, $mode) { public function fopen($path, $mode) {
$path = $this->root.$path;
switch ($mode) { switch ($mode) {
case 'r': case 'r':
case 'rb': case 'rb':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment