forked from panakour/oc-backup-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDropbox.php
40 lines (32 loc) · 1.09 KB
/
Dropbox.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php namespace PanaKour\Backup;
use Illuminate\Support\Facades\Config;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client;
use Spatie\FlysystemDropbox\DropboxAdapter;
class Dropbox
{
protected $client;
protected $adapter;
protected $fileSystem;
protected $path;
public function __construct()
{
$accessToken = Config::get('filesystems.disks.dropbox.authorizationToken') ? Config::get('filesystems.disks.dropbox.authorizationToken') : '';
$this->client = new Client($accessToken);
$this->adapter = new DropboxAdapter($this->client);
$this->fileSystem = new Filesystem($this->adapter);
if (isset($this->fileSystem->listContents()[0])) {
$this->path = $this->fileSystem->listContents()[0]['path'];
}
}
public function getBackups()
{
return $this->fileSystem->listContents($this->path);
}
public function downloadBackup($baseName)
{
$file = $this->adapter->read($this->path.'/'.$baseName)['contents'];
header("Content-Type: application/zip");
echo $file;
}
}