1
0
mirror of https://github.com/devfake/flox.git synced 2024-11-15 14:42:31 +01:00
flox/backend/app/Services/Storage.php
Viktor Geringer 74f733710e Implement refresh data (#81)
* update translations

* split helper file

* implement refresh informations

* add tests

* update production files

* move refresh all to a seperate request

* update production files
2017-07-28 11:37:33 +02:00

79 lines
1.8 KiB
PHP

<?php
namespace App\Services;
use Illuminate\Support\Facades\Storage as LaravelStorage;
class Storage {
/**
* Save backup as json into /public/exports.
*
* @param $file
* @param $items
*/
public function saveExport($file, $items)
{
LaravelStorage::disk('export')->put($file, $items);
}
/**
* Create the export filename.
*
* @return string
*/
public function createExportFilename()
{
return 'flox--' . date('Y-m-d---H-i') . '.json';
}
/**
* Download poster and backdrop image files.
*
* @param $poster
* @param $backdrop
*/
public function downloadImages($poster, $backdrop)
{
if($poster) {
LaravelStorage::put($poster, file_get_contents(config('services.tmdb.poster') . $poster));
LaravelStorage::disk('subpage')->put($poster, file_get_contents(config('services.tmdb.poster_subpage') . $poster));
}
if($backdrop) {
LaravelStorage::disk('backdrop')->put($backdrop, file_get_contents(config('services.tmdb.backdrop') . $backdrop));
}
}
/**
* Delete poster and backdrop image files.
*
* @param $poster
* @param $backdrop
*/
public function removeImages($poster, $backdrop)
{
LaravelStorage::delete($poster);
LaravelStorage::disk('subpage')->delete($poster);
LaravelStorage::disk('backdrop')->delete($backdrop);
}
/**
* Parse language file.
*
* @return mixed
*/
public function parseLanguage()
{
$alternative = config('app.TRANSLATION');
$filename = strtolower($alternative) . '.json';
// Get english fallback
if( ! LaravelStorage::disk('languages')->exists($filename)) {
$filename = 'en.json';
}
return LaravelStorage::disk('languages')->get($filename);
}
}