- Add FileSharing API
This commit is contained in:
parent
f311c4fc7f
commit
50af8afb73
|
@ -14,6 +14,10 @@ Jusqu'a présent, les fonctionalités suivantes ont été implémentées :
|
|||
- AirMedia
|
||||
- FileSystem
|
||||
- FileSystem (Core)
|
||||
- FsTask
|
||||
- FsOperation
|
||||
- FsListing
|
||||
- FileSharing
|
||||
- Downloads
|
||||
- Download
|
||||
- Configuration
|
||||
|
@ -62,6 +66,10 @@ $SystemConfig = $System->getConfiguration();
|
|||
|
||||
Les exemples sont disponibles dans le repertoire `exemple`. Ils sont classés par services :
|
||||
- `AirMedia` : Exemple de lancement d'une video sur le Freebox Player
|
||||
- `FileSystem`
|
||||
- `fileSharing` : Un exemple de partage de fichier sur le net
|
||||
- `fsListing` : Un exemple de scan de repertoires de la freebox
|
||||
- `fsOperation` : Un exemple d'operations sur le fichiers (copies, déplacement, renommage, par2..)
|
||||
- `config`
|
||||
- `check_dns` : Un script pour récuperer la configuration courrante du DHCP
|
||||
- `DMZ` : Récupération de la confiugration de votre zone démilitarisée
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
/// Require Composer AutoLoader
|
||||
require_once '../../vendor/autoload.php';
|
||||
|
||||
/// Define our application
|
||||
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.filesystem', 'Freebox PHP API Example (FileSystem)', '1.0.0');
|
||||
$App->authorize();
|
||||
$App->openSession();
|
||||
|
||||
/// Scan files in root
|
||||
$FileSharingLinkService = new \alphayax\freebox\api\v3\services\FileSystem\FileSharingLink( $App);
|
||||
$Links = $FileSharingLinkService->getAll();
|
||||
var_dump( $Links);
|
||||
|
||||
$FileSharingLink = $FileSharingLinkService->create( '/Disque dur/Photos/vivi.jpg');
|
||||
var_dump( $FileSharingLink);
|
||||
|
||||
$Links = $FileSharingLinkService->getAll();
|
||||
var_dump( $Links);
|
||||
|
||||
$b = $FileSharingLinkService->deleteFromToken( $FileSharingLink->getToken());
|
||||
var_dump( $b);
|
||||
|
||||
$Links = $FileSharingLinkService->getAll();
|
||||
var_dump( $Links);
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\models\FileSystem;
|
||||
use alphayax\freebox\api\v3\Model;
|
||||
|
||||
/**
|
||||
* Class ShareLink
|
||||
* @package alphayax\freebox\api\v3\models\FileSystem
|
||||
*/
|
||||
class ShareLink extends Model {
|
||||
|
||||
/** @var string (Read-only) : The link unique sharing token */
|
||||
protected $token;
|
||||
|
||||
/** @var string (Read-only) : The root path of the share, if the path is a regular file, only this file will be shared */
|
||||
protected $path;
|
||||
|
||||
/** @var string (Read-only) : The readable name of the shared file/folder */
|
||||
protected $name;
|
||||
|
||||
/** @var int timestamp (Read-only) : Link expiration timestamp, 0 means no expiration. */
|
||||
protected $expire;
|
||||
|
||||
/** @var string (Read-only) : Full URL to use for remote access. If remote access is disabled, the field will be empty. */
|
||||
protected $fullurl;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getToken(){
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath(){
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getExpire(){
|
||||
return $this->expire;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFullurl(){
|
||||
return $this->fullurl;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
namespace alphayax\freebox\api\v3\services\FileSystem;
|
||||
use alphayax\freebox\api\v3\models\FileSystem\ShareLink;
|
||||
use alphayax\freebox\api\v3\Service;
|
||||
|
||||
|
||||
/**
|
||||
* Class FileSharingLink
|
||||
* @package alphayax\freebox\api\v3\services\FileSystem
|
||||
*/
|
||||
class FileSharingLink extends Service {
|
||||
|
||||
const API_SHARE_LINK = '/api/v3/share_link/';
|
||||
|
||||
/**
|
||||
* Retrieve a File Sharing link
|
||||
* @return ShareLink[]
|
||||
*/
|
||||
public function getAll(){
|
||||
$rest = $this->getAuthService( self::API_SHARE_LINK);
|
||||
$rest->GET();
|
||||
|
||||
$ApiReturn = $rest->getCurlResponse();
|
||||
$FileSharingLinks = [];
|
||||
$FileSharingLink_xs = @$ApiReturn['result'] ?: [];
|
||||
foreach( $FileSharingLink_xs as $fileSharingLink_x){
|
||||
$FileSharingLinks[] = new ShareLink( $fileSharingLink_x);
|
||||
}
|
||||
return $FileSharingLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $Token
|
||||
* @return ShareLink
|
||||
*/
|
||||
public function getFromToken( $Token){
|
||||
$rest = $this->getAuthService( self::API_SHARE_LINK . $Token);
|
||||
$rest->GET();
|
||||
|
||||
return new ShareLink( $rest->getCurlResponse()['result']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a File Sharing link
|
||||
* Deletes the ShareLink task with the given token, if the task was running, stop it.
|
||||
* No rollback is done, if a file as already been processed it will be left as is.
|
||||
* @param $Token
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteFromToken( $Token){
|
||||
$rest = $this->getAuthService( self::API_SHARE_LINK . $Token);
|
||||
$rest->DELETE();
|
||||
|
||||
return $rest->getCurlResponse()['success'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a File Sharing link
|
||||
* @param string $Path
|
||||
* @param int $expire
|
||||
* @param string $fullUrl
|
||||
* @return ShareLink
|
||||
*/
|
||||
public function create( $Path, $expire = 0, $fullUrl = ''){
|
||||
$Path_b64 = base64_encode( $Path);
|
||||
$expire = $expire ?: (time() + (60*60*24)); // If expire is not defined, default is 24h
|
||||
$rest = $this->getAuthService( self::API_SHARE_LINK);
|
||||
$rest->POST([
|
||||
'path' => $Path_b64,
|
||||
'expire' => $expire,
|
||||
'fullurl' => $fullUrl,
|
||||
]);
|
||||
|
||||
return new ShareLink( $rest->getCurlResponse()['result']);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue