Add Download File API
This commit is contained in:
parent
1f3c633558
commit
8fb0690885
|
@ -26,9 +26,10 @@ Jusqu'a présent, les fonctionalités suivantes ont été implémentées :
|
||||||
- FsListing
|
- FsListing
|
||||||
- FileUpload
|
- FileUpload
|
||||||
- FileSharing
|
- FileSharing
|
||||||
- Downloads
|
- DownloadStats
|
||||||
- Download (core)
|
- Download (core)
|
||||||
- Download Stats
|
- Download Stats
|
||||||
|
- Download Files
|
||||||
- Configuration
|
- Configuration
|
||||||
- Connection
|
- Connection
|
||||||
- Connection (Core)
|
- Connection (Core)
|
||||||
|
@ -122,6 +123,7 @@ Les exemples sont disponibles dans le repertoire `exemple`. Ils sont classés pa
|
||||||
- `PortForwarding` : Exemple d'ajout d'une redirection de port
|
- `PortForwarding` : Exemple d'ajout d'une redirection de port
|
||||||
- `System` : Affichage de la configuration système de la freebox
|
- `System` : Affichage de la configuration système de la freebox
|
||||||
- `download`
|
- `download`
|
||||||
|
- `Download` : Listage des téléchargement en cours, liste des fichiers d'un téléchargement et mise a jour de la priorité de téléchargement
|
||||||
- `dl_rss` : Un script qui parse les flux RSS et qui rajoute en téléchagement les items correspondant a une expression réguliere
|
- `dl_rss` : Un script qui parse les flux RSS et qui rajoute en téléchagement les items correspondant a une expression réguliere
|
||||||
|
|
||||||
|
|
2
TODO.md
2
TODO.md
|
@ -1,7 +1,7 @@
|
||||||
- Downloads
|
- Downloads
|
||||||
- ~~Download~~
|
- ~~Download~~
|
||||||
- ~~Download Stats~~
|
- ~~Download Stats~~
|
||||||
- Download Files
|
- ~~Download Files~~
|
||||||
- Download Trackers [UNSTABLE]
|
- Download Trackers [UNSTABLE]
|
||||||
- Download Peers [UNSTABLE]
|
- Download Peers [UNSTABLE]
|
||||||
- Download Blacklist [UNSTABLE]
|
- Download Blacklist [UNSTABLE]
|
||||||
|
|
|
@ -16,3 +16,14 @@ print_r( $Downloads);
|
||||||
/// Stats
|
/// Stats
|
||||||
$Stats = $DownloadService->getStats();
|
$Stats = $DownloadService->getStats();
|
||||||
print_r( $Stats);
|
print_r( $Stats);
|
||||||
|
|
||||||
|
/// Files
|
||||||
|
$Files = $DownloadService->getFilesFromId( $Downloads[0]->getId());
|
||||||
|
print_r( $Files);
|
||||||
|
|
||||||
|
/// Priority
|
||||||
|
$Success = $DownloadService->updateFilePriority( $Downloads[0]->getId(), $Files[0]->getId(), \alphayax\freebox\api\v3\symbols\Download\File\Priority::HIGH);
|
||||||
|
print_r( $Success);
|
||||||
|
$Files = $DownloadService->getFilesFromId( $Downloads[0]->getId());
|
||||||
|
print_r( $Files);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,138 @@
|
||||||
|
<?php
|
||||||
|
namespace alphayax\freebox\api\v3\models\Download;
|
||||||
|
use alphayax\freebox\api\v3\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class File
|
||||||
|
* @package alphayax\freebox\api\v3\models\Download
|
||||||
|
*/
|
||||||
|
class File extends Model {
|
||||||
|
|
||||||
|
/** @var string (Read-only) : opaque id */
|
||||||
|
protected $id;
|
||||||
|
|
||||||
|
/** @var int (Read-only) : id of the download task */
|
||||||
|
protected $task_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string (Read-only) : file path relative to the download dir
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
protected $path;
|
||||||
|
|
||||||
|
/** @var string (Read-only) : full filepath on the disk (encoded as in file system api) */
|
||||||
|
protected $filepath;
|
||||||
|
|
||||||
|
/** @var string (Read-only) : file name */
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
/** @var string (Read-only) : file mimetype */
|
||||||
|
protected $mimetype;
|
||||||
|
|
||||||
|
/** @var int (Read-only) : file size in bytes */
|
||||||
|
protected $size;
|
||||||
|
|
||||||
|
/** @var int (Read-only) : received bytes */
|
||||||
|
protected $rx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string (Read-only) : file download status
|
||||||
|
* @see alphayax\freebox\api\v3\symbols\Download\File\Status
|
||||||
|
*/
|
||||||
|
protected $status;
|
||||||
|
|
||||||
|
/** @var string : file download priority inside the download task */
|
||||||
|
protected $priority;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string (Read-only) : file error code in case status is error
|
||||||
|
* @see alphayax\freebox\api\v3\symbols\Download\File\Error
|
||||||
|
*/
|
||||||
|
protected $error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getTaskId() {
|
||||||
|
return $this->task_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function getPath() {
|
||||||
|
return $this->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getFilepath() {
|
||||||
|
return base64_decode( $this->filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName() {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getMimetype() {
|
||||||
|
return $this->mimetype;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getSize() {
|
||||||
|
return $this->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getRx() {
|
||||||
|
return $this->rx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getStatus() {
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPriority() {
|
||||||
|
return $this->priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $priority
|
||||||
|
*/
|
||||||
|
public function setPriority( $priority) {
|
||||||
|
$this->priority = $priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getError() {
|
||||||
|
return $this->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -141,5 +141,4 @@ class FileInfo extends Model {
|
||||||
return $this->filecount;
|
return $this->filecount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Download extends Service {
|
||||||
const API_DOWNLOAD_ERASE = '/api/v3/downloads/%s/erase/';
|
const API_DOWNLOAD_ERASE = '/api/v3/downloads/%s/erase/';
|
||||||
const API_DOWNLOAD_ADD = '/api/v3/downloads/add/';
|
const API_DOWNLOAD_ADD = '/api/v3/downloads/add/';
|
||||||
const API_DOWNLOAD_STATS = '/api/v3/downloads/stats';
|
const API_DOWNLOAD_STATS = '/api/v3/downloads/stats';
|
||||||
|
const API_DOWNLOAD_FILES = '/api/v3/downloads/%u/files';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the collection of all Download tasks
|
* Returns the collection of all Download tasks
|
||||||
|
@ -184,8 +185,6 @@ class Download extends Service {
|
||||||
return $rest->getCurlResponse()['result']['id'];
|
return $rest->getCurlResponse()['result']['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Download task with the given id
|
* Returns the Download task with the given id
|
||||||
* @return models\Download\Task
|
* @return models\Download\Task
|
||||||
|
@ -197,4 +196,39 @@ class Download extends Service {
|
||||||
return new models\Download\Stats\DownloadStats( $rest->getCurlResponse()['result']);
|
return new models\Download\Stats\DownloadStats( $rest->getCurlResponse()['result']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Download task with the given id
|
||||||
|
* @param int $taskId
|
||||||
|
* @return models\Download\File[]
|
||||||
|
*/
|
||||||
|
public function getFilesFromId( $taskId){
|
||||||
|
$Service = sprintf( self::API_DOWNLOAD_FILES, $taskId);
|
||||||
|
$rest = $this->getAuthService( $Service);
|
||||||
|
$rest->GET();
|
||||||
|
|
||||||
|
$DownloadFile_xs = @$rest->getCurlResponse()['result'] ?: [];
|
||||||
|
$DownloadFiles = [];
|
||||||
|
foreach( $DownloadFile_xs as $DownloadFile_x) {
|
||||||
|
$DownloadFiles[] = new models\Download\File( $DownloadFile_x);
|
||||||
|
}
|
||||||
|
return $DownloadFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $downloadTaskId
|
||||||
|
* @param string $FileId
|
||||||
|
* @param string $Priority
|
||||||
|
* @see alphayax\freebox\api\v3\symbols\Download\File\Priority
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function updateFilePriority( $downloadTaskId, $FileId, $Priority){
|
||||||
|
$Service = sprintf( self::API_DOWNLOAD_FILES, $downloadTaskId);
|
||||||
|
$rest = $this->getAuthService( $Service . DIRECTORY_SEPARATOR . $FileId);
|
||||||
|
$rest->PUT([
|
||||||
|
'priority' => $Priority,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $rest->getCurlResponse()['success'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
namespace alphayax\freebox\api\v3\symbols\Download\File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Symbol Priority
|
||||||
|
* @package alphayax\freebox\api\v3\symbols\Download\File
|
||||||
|
*/
|
||||||
|
interface Priority {
|
||||||
|
|
||||||
|
/** this file will not be downloaded */
|
||||||
|
const NO_DOWNLOAD = 'no_dl';
|
||||||
|
|
||||||
|
/** low priority */
|
||||||
|
const LOW = 'low';
|
||||||
|
|
||||||
|
/** default priority */
|
||||||
|
const NORMAL = 'normal';
|
||||||
|
|
||||||
|
/** high priority */
|
||||||
|
const HIGH = 'high';
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
namespace alphayax\freebox\api\v3\symbols\Download\File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Symbol Status
|
||||||
|
* @package alphayax\freebox\api\v3\symbols\Download\File
|
||||||
|
*/
|
||||||
|
interface Status {
|
||||||
|
|
||||||
|
/** file is queued for download */
|
||||||
|
const QUEUED = 'queued';
|
||||||
|
|
||||||
|
/** there was a problem with this file, see error to get the error code */
|
||||||
|
const ERROR = 'error';
|
||||||
|
|
||||||
|
/** file download is completed */
|
||||||
|
const DONE = 'done';
|
||||||
|
}
|
Loading…
Reference in New Issue