#123: The setting tab now only lists compatible storages. Added support for IAnalysisQueueSource to the LocalFileSystemSource driver
This commit is contained in:
parent
95e79f2d28
commit
07fa9639b5
@ -3,6 +3,7 @@
|
|||||||
namespace App\AlbumSources;
|
namespace App\AlbumSources;
|
||||||
|
|
||||||
use App\Album;
|
use App\Album;
|
||||||
|
use App\Helpers\FileHelper;
|
||||||
use App\Helpers\MiscHelper;
|
use App\Helpers\MiscHelper;
|
||||||
use App\Photo;
|
use App\Photo;
|
||||||
use App\Services\PhotoService;
|
use App\Services\PhotoService;
|
||||||
@ -13,7 +14,7 @@ use Symfony\Component\HttpFoundation\File\File;
|
|||||||
* Driver for managing files on the local filesystem.
|
* Driver for managing files on the local filesystem.
|
||||||
* @package App\AlbumSources
|
* @package App\AlbumSources
|
||||||
*/
|
*/
|
||||||
class LocalFilesystemSource extends AlbumSourceBase implements IAlbumSource
|
class LocalFilesystemSource extends AlbumSourceBase implements IAlbumSource, IAnalysisQueueSource
|
||||||
{
|
{
|
||||||
public function deleteAlbumContents()
|
public function deleteAlbumContents()
|
||||||
{
|
{
|
||||||
@ -120,4 +121,86 @@ class LocalFilesystemSource extends AlbumSourceBase implements IAlbumSource
|
|||||||
|
|
||||||
rmdir($directory);
|
rmdir($directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a photo to be analysed from the storage source
|
||||||
|
* @param string $queueToken Queue token holding the photo
|
||||||
|
* @param string $fileName Filename of the photo to download
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function deleteItemFromAnalysisQueue($queueToken, $fileName)
|
||||||
|
{
|
||||||
|
$queueFolder = $this->getQueuePath($queueToken);
|
||||||
|
$filePath = $this->getQueueItemPath($queueToken, $fileName);
|
||||||
|
@unlink($filePath);
|
||||||
|
|
||||||
|
// Delete the parent folder if empty
|
||||||
|
FileHelper::deleteIfEmpty($queueFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads a photo to be analysed from the storage source to a temporary file
|
||||||
|
* @param string $queueToken Queue token holding the photo
|
||||||
|
* @param string $fileName Filename of the photo to download
|
||||||
|
* @return string Path to the photo that was downloaded
|
||||||
|
*/
|
||||||
|
public function fetchItemFromAnalysisQueue($queueToken, $fileName)
|
||||||
|
{
|
||||||
|
// Don't actually need to download anything as it's already local
|
||||||
|
return $this->getQueueItemPath($queueToken, $fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads a new file to the analysis queue specified by queue token.
|
||||||
|
*
|
||||||
|
* @param string $sourceFilePath Path to the file to upload to the analysis queue
|
||||||
|
* @param string $queueToken Queue token to hold the photo
|
||||||
|
* @param string $overrideFilename Use a specific filename, or false to set a specific name
|
||||||
|
* @return string Path to the file
|
||||||
|
*/
|
||||||
|
public function uploadToAnalysisQueue($sourceFilePath, $queueToken, $overrideFilename = null)
|
||||||
|
{
|
||||||
|
$uploadedFile = new File($sourceFilePath);
|
||||||
|
|
||||||
|
$tempFilename = $this->getQueueItemPath(
|
||||||
|
$queueToken,
|
||||||
|
is_null($overrideFilename) ? MiscHelper::randomString(20) : basename($overrideFilename)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Only add an extension if an override filename was not given, assume this is present
|
||||||
|
if (is_null($overrideFilename))
|
||||||
|
{
|
||||||
|
$extension = $uploadedFile->guessExtension();
|
||||||
|
if (!is_null($extension))
|
||||||
|
{
|
||||||
|
$tempFilename .= '.' . $extension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploadedFile->move(dirname($tempFilename), basename($tempFilename));
|
||||||
|
return $tempFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getQueueItemPath($queueToken, $fileName)
|
||||||
|
{
|
||||||
|
return join(DIRECTORY_SEPARATOR, [$this->getQueuePath($queueToken), $fileName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getQueuePath($queueUid)
|
||||||
|
{
|
||||||
|
$path = join(DIRECTORY_SEPARATOR, [
|
||||||
|
dirname(dirname(__DIR__)),
|
||||||
|
'storage',
|
||||||
|
'app',
|
||||||
|
'analysis-queue',
|
||||||
|
str_replace(['.', '/', '\\'], '', $queueUid)
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!file_exists($path))
|
||||||
|
{
|
||||||
|
@mkdir($path, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
}
|
}
|
@ -16,10 +16,49 @@ class AnalysisQueueHelper
|
|||||||
{
|
{
|
||||||
$queueStorage = Storage::find(UserConfig::get('analysis_queue_storage_location'));
|
$queueStorage = Storage::find(UserConfig::get('analysis_queue_storage_location'));
|
||||||
|
|
||||||
|
$queueSource = self::createStorageSource($queueStorage);
|
||||||
|
if (is_null($queueSource))
|
||||||
|
{
|
||||||
|
throw new \Exception(sprintf('Queue storage \'%s\' does not support the analysis queue', $queueStorage->name));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $queueSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of compatible storage sources for the analysis queue.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getCompatibleStorages()
|
||||||
|
{
|
||||||
|
$storageSources = [];
|
||||||
|
|
||||||
|
foreach (Storage::where('is_active', true)->orderBy('name')->get() as $storage)
|
||||||
|
{
|
||||||
|
$queueSource = self::createStorageSource($storage);
|
||||||
|
|
||||||
|
if (is_null($queueSource))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$storageSources[$storage->id] = $storage->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $storageSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function createStorageSource(Storage $queueStorage)
|
||||||
|
{
|
||||||
$fullClassName = sprintf('App\AlbumSources\%s', $queueStorage->source);
|
$fullClassName = sprintf('App\AlbumSources\%s', $queueStorage->source);
|
||||||
|
|
||||||
/** @var IAnalysisQueueSource $source */
|
/** @var IAnalysisQueueSource $source */
|
||||||
$source = new $fullClassName;
|
$source = new $fullClassName;
|
||||||
|
if (!$source instanceof IAnalysisQueueSource)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$source->setConfiguration($queueStorage);
|
$source->setConfiguration($queueStorage);
|
||||||
|
|
||||||
return $source;
|
return $source;
|
||||||
|
@ -7,6 +7,7 @@ use App\Configuration;
|
|||||||
use App\Facade\Theme;
|
use App\Facade\Theme;
|
||||||
use App\Facade\UserConfig;
|
use App\Facade\UserConfig;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
|
use App\Helpers\AnalysisQueueHelper;
|
||||||
use App\Helpers\ConfigHelper;
|
use App\Helpers\ConfigHelper;
|
||||||
use App\Helpers\DbHelper;
|
use App\Helpers\DbHelper;
|
||||||
use App\Helpers\MiscHelper;
|
use App\Helpers\MiscHelper;
|
||||||
@ -370,11 +371,7 @@ class DefaultController extends Controller
|
|||||||
$themeNamesLookup = UserConfig::allowedThemeNames();
|
$themeNamesLookup = UserConfig::allowedThemeNames();
|
||||||
|
|
||||||
// Storage sources for the Image Processing tab
|
// Storage sources for the Image Processing tab
|
||||||
$storageSources = [];
|
$storageSources = AnalysisQueueHelper::getCompatibleStorages();
|
||||||
foreach (Storage::where('is_active', true)->orderBy('name')->get() as $storage)
|
|
||||||
{
|
|
||||||
$storageSources[$storage->id] = $storage->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Theme::render('admin.settings', [
|
return Theme::render('admin.settings', [
|
||||||
'config' => $config,
|
'config' => $config,
|
||||||
|
@ -201,7 +201,7 @@
|
|||||||
<p>@lang('admin.settings.analysis_queue_storage_intro')</p>
|
<p>@lang('admin.settings.analysis_queue_storage_intro')</p>
|
||||||
<p>@lang('admin.settings.analysis_queue_storage_intro_2')</p>
|
<p>@lang('admin.settings.analysis_queue_storage_intro_2')</p>
|
||||||
|
|
||||||
<div class="alert alert-warning mb-5">
|
<div class="alert alert-warning mb-4">
|
||||||
<p class="mb-0">@lang('admin.settings.analysis_queue_storage_warning')</p>
|
<p class="mb-0">@lang('admin.settings.analysis_queue_storage_warning')</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user