blue-twilight/app/AlbumSources/OpenStackSource.php

130 lines
3.8 KiB
PHP
Raw Normal View History

<?php
namespace App\AlbumSources;
use App\Photo;
use OpenCloud\OpenStack;
use Symfony\Component\HttpFoundation\File\File;
/**
* Driver for managing files on the local filesystem.
* @package App\AlbumSources
*/
class OpenStackSource extends AlbumSourceBase implements IAlbumSource
{
/**
* Deletes an entire album's media contents.
* @return void
*/
public function deleteAlbumContents()
{
// TODO: Implement deleteAlbumContents() method.
}
/**
* Deletes a thumbnail file for a photo.
* @param Photo $photo Photo to delete the thumbnail from.
* @param string $thumbnail Thumbnail to delete (or null to delete the original.)
* @return void
*/
public function deleteThumbnail(Photo $photo, $thumbnail = null)
{
// TODO: Implement deleteThumbnail() method.
}
/**
* Gets the name of this album source.
* @return string
*/
public function getName()
{
return 'global.album_sources.openstack';
}
/**
* Gets the absolute path to the given photo file.
* @param Photo $photo Photo to get the path to.
* @param string $thumbnail Thumbnail to get the image to.
* @return string
*/
public function getPathToPhoto(Photo $photo, $thumbnail = null)
{
// TODO: Implement getPathToPhoto() method.
}
/**
* Gets the absolute URL to the given photo file.
* @param Photo $photo Photo to get the URL to.
* @param string $thumbnail Thumbnail to get the image to.
* @return string
*/
public function getUrlToPhoto(Photo $photo, $thumbnail = null)
{
return sprintf(
'%s/%s/%s/%s',
'https://photos-dev-898b0644.cdn.memsites.com',
$this->album->url_alias,
is_null($thumbnail) ? $this->getOriginalsFolder() : $thumbnail,
$photo->storage_file_name
);
}
public function saveOriginal(Photo $photo, $tempFilename)
{
$this->saveThumbnail($photo, $tempFilename, $this->getOriginalsFolder());
}
/**
* Saves a generated thumbnail to its permanent location.
* @param Photo $photo Photo the thumbnail relates to.
* @param string $tempFilename Filename containing the thumbnail.
* @param string $thumbnail Name of the thumbnail.
* @return mixed
*/
public function saveThumbnail(Photo $photo, $tempFilename, $thumbnail)
{
$container = $this->getContainer();
$container->uploadObject(
sprintf('%s/%s/%s', $this->album->url_alias, $thumbnail, $photo->storage_file_name),
fopen($tempFilename, 'r+')
);
}
/**
* Saves an uploaded file to the container and returns the filename.
* @param File $uploadedFile The photo uploaded
* @param string $overrideFilename Specific file name to use, or null to randomly generate one.
* @return File
*/
public function saveUploadedPhoto(File $uploadedFile, $overrideFilename = null)
{
// TODO: Implement saveUploadedPhoto() method.
}
private function getClient()
{
return new OpenStack($this->configuration->auth_url, [
'username' => $this->configuration->username,
'password' => decrypt($this->configuration->password),
'tenantName' => $this->configuration->tenant_name,
]);
}
private function getContainer()
{
return $this->getStorageService()->getContainer($this->configuration->container_name);
}
private function getOriginalsFolder()
{
return '_originals';
}
private function getStorageService()
{
return $this->getClient()->objectStoreService(
$this->configuration->service_name,
$this->configuration->service_region,
'publicURL'
);
}
}