Browse Source

passage par la lib pour le wipe et le listing

master
Cabillot Julien 6 years ago
parent
commit
61d944c840
4 changed files with 84 additions and 42 deletions
  1. 71
      controller/status.php
  2. 23
      lib/Download.php
  3. 23
      lib/Stream.php
  4. 9
      templates/status.php

71
controller/status.php

@ -2,61 +2,56 @@
function getStatus()
{
$listAdded = [];
$listDownloading = [];
$listDownloaded = [];
$listDupp = [];
$db = DbMongo::get();
$coll = $db->download;
$listAdded = Download::listByState('added');
$listDownloading = Download::listByState('downloading');
$listDownloaded = Download::listByState('downloaded');
$listDupp = Download::listByState('dupp');
$streamFinished = Stream::listByState('finished');
$streamBegin = Stream::listByState('begin');
foreach ($coll->find(['cstate' => 'added']) as $element) {
$listAdded[] = $element;
}
foreach ($coll->find(['cstate' => 'downloading']) as $element) {
$listDownloading[] = $element;
}
foreach ($coll->find(['cstate' => 'downloaded']) as $element) {
$listDownloaded[] = $element;
}
foreach ($coll->find(['cstate' => 'dupp']) as $element) {
$listDupp[] = $element;
}
$coll = $db->stream;
$infos = PremiumizeMe::getStatus();
foreach ($coll->find(['cstate' => 'finished']) as $element) {
$streamFinished[] = $element;
$tmpRestant = $infos['expires']->diff(new DateTime());
$restant = '';
if ($tmpRestant->m !== 0) {
$restant .= $tmpRestant->m.'mois ';
}
foreach ($coll->find(['cstate' => 'begin']) as $element) {
$streamBegin[] = $element;
if ($tmpRestant->d !== 0) {
$restant .= $tmpRestant->d.'jours ';
}
$infos = PremiumizeMe::getStatus();
include dirname(__FILE__).'/../templates/status.php';
}
function cleanList()
{
// TODO : plus de verif
if (!isset($_GET['type']) || empty($_GET['type'])) {
echo json_encode('pas de type, exit');
exit();
}
// TODO : plus de verif
if (!isset($_GET['state']) || empty($_GET['state'])) {
echo json_encode('pas de state, exit');
exit();
}
$db = DbMongo::get();
$coll = $db->$_GET['type'];
$coll->remove(['cstate' => $_GET['state']]);
echo json_encode('ok');
if ($_GET['type'] === 'download') {
if (!in_array($_GET['state'], Download::$validStates)) {
echo json_encode('mauvais state, exit');
exit();
}
Download::clear($_GET['state']);
echo json_encode('ok');
} elseif ($_GET['type'] === 'stream') {
if (!in_array($_GET['state'], Stream::$validStates)) {
echo json_encode('mauvais state, exit');
exit();
}
Stream::clear($_GET['state']);
echo json_encode('ok');
} else {
echo json_encode('mauvais type, exit');
exit();
}
}

23
lib/Download.php

@ -6,6 +6,7 @@ class Download {
public $premURL;
public $filename;
public $cstate;
static public $validStates = ['added', 'downloaded', 'dupp'];
/**
* Retourne les infos sur le prochain fichier a telecharger
@ -170,4 +171,26 @@ class Download {
$toDownload = self::findNextJob();
$toDownload->get();
}
static function listByState($state)
{
$db = DbMongo::get();
$coll = $db->download;
$retour = [];
// TODO : lister statut possible
foreach ($coll->find(['cstate' => $state]) as $element) {
$retour[] = $element;
}
return $retour;
}
static function clear($state)
{
$db = DbMongo::get();
$coll = $db->download;
$coll->remove(['cstate' => $state]);
}
}

23
lib/Stream.php

@ -8,6 +8,7 @@ class Stream {
public $cstate;
public $url;
public $ip;
static public $validStates = ['begin', 'finished'];
function __construct($url, $premURL, $filename, $ip)
{
@ -98,4 +99,26 @@ class Stream {
['$push' => ['event' => $event]]
);
}
static function listByState($state)
{
$db = DbMongo::get();
$coll = $db->stream;
$retour = [];
// TODO : lister statut possible
foreach ($coll->find(['cstate' => $state]) as $element) {
$retour[] = $element;
}
return $retour;
}
static function clear($state)
{
$db = DbMongo::get();
$coll = $db->stream;
$coll->remove(['cstate' => $state]);
}
}

9
templates/status.php

@ -10,7 +10,8 @@
</head>
<body>
<div class="account">
Expiration : <?= $infos['expires']->format('H:i d.m.Y') ?><br>
<!-- TODO : ajouter jour restant -->
Expiration : <?= $infos['expires']->format('H:i d/m/Y') ?> (<?= $restant ?>)<br>
Traffic Restant : <?= intval($infos['trafficleft_gigabytes']) ?>Go (<?= intval($infos['fairuse_left'] * 100) ?>%)<br>
</div>
<div class="addMulti">
@ -45,7 +46,7 @@ if (!empty($listAdded)) {
?>
</tbody>
</table>
<input type="button" value="Wipe" onClick="javascript:wipe('dl', 'added'); ">
<input type="button" value="Wipe" onClick="javascript:wipe('download', 'added'); ">
</div>
<?php
}
@ -106,7 +107,7 @@ if (!empty($listDownloaded)) {
?>
</tbody>
</table>
<input type="button" value="Wipe" onClick="javascript:wipe('dl', 'downloaded');">
<input type="button" value="Wipe" onClick="javascript:wipe('download', 'downloaded');">
</div>
<?php
}
@ -137,7 +138,7 @@ if (!empty($listDupp)) {
?>
</tbody>
</table>
<input type="button" value="Wipe" onClick="javascript:wipe('dl', 'dupp');">
<input type="button" value="Wipe" onClick="javascript:wipe('download', 'dupp');">
</div>
<?php
}

Loading…
Cancel
Save