Skip to content

Commit

Permalink
Merge pull request #347 from rexxars/uuid-image-identifiers
Browse files Browse the repository at this point in the history
UUID image identifiers
  • Loading branch information
rexxars committed Sep 28, 2015
2 parents 702176b + fc91def commit adef026
Show file tree
Hide file tree
Showing 58 changed files with 694 additions and 323 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"ext-imagick": ">=3.0.1",
"symfony/http-foundation": "~2.4.0",
"symfony/event-dispatcher": "~2.4.0",
"symfony/console": "~2.4.0"
"symfony/console": "~2.4.0",
"rhumsaa/uuid": "~2.8"
},
"require-dev": {
"mikey179/vfsStream": "~1.0",
Expand Down
69 changes: 68 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions library/Imbo/EventListener/AccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function subscribe(EventInterface $event) {
* {@inheritdoc}
*/
public function checkAccess(EventInterface $event) {
if ($event->hasArgument('skipAccessControl') &&
$event->getArgument('skipAccessControl') === true) {
return;
}

$request = $event->getRequest();
$response = $event->getResponse();
$accessControl = $event->getAccessControl();
Expand Down
2 changes: 1 addition & 1 deletion library/Imbo/EventListener/DatabaseOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function insertImage(EventInterface $event) {

$event->getDatabase()->insertImage(
$request->getUser(),
$request->getImage()->getChecksum(),
$request->getImage()->getImageIdentifier(),
$request->getImage()
);
}
Expand Down
2 changes: 1 addition & 1 deletion library/Imbo/EventListener/ExifMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function save(EventInterface $event) {
$database = $event->getDatabase();

$user = $request->getUser();
$imageIdentifier = $request->getImage()->getChecksum();
$imageIdentifier = $request->getImage()->getImageIdentifier();

try {
$database->updateMetadata(
Expand Down
2 changes: 1 addition & 1 deletion library/Imbo/EventListener/ImageVariations.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function generateVariations(EventInterface $event) {
$request = $event->getRequest();
$user = $request->getUser();
$originalImage = $request->getImage();
$imageIdentifier = $originalImage->getChecksum();
$imageIdentifier = $originalImage->getImageIdentifier();
$originalWidth = $originalImage->getWidth();

// Fetch parameters specified in the Imbo configuration related to what sort of variations
Expand Down
9 changes: 4 additions & 5 deletions library/Imbo/EventListener/ResponseSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ public function send(EventInterface $event) {
$imageIdentifier = null;

if ($image = $request->getImage()) {
// The request has an image. This means that an image was just added. Use the image's
// checksum
$imageIdentifier = $image->getChecksum();
// The request has an image. This means that an image was just added.
// Get the image identifier from the image model
$imageIdentifier = $image->getImageIdentifier();
} else if ($identifier = $request->getImageIdentifier()) {
// An image identifier exists in the request, use that one (and not a possible image
// checksum for an image attached to the response)
// An image identifier exists in the request URI, use that
$imageIdentifier = $identifier;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Imbo/EventListener/StorageOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function insertImage(EventInterface $event) {
$request = $event->getRequest();
$user = $request->getUser();
$image = $request->getImage();
$imageIdentifier = $image->getChecksum();
$imageIdentifier = $image->getImageIdentifier();
$blob = $image->getBlob();

try {
Expand Down
6 changes: 4 additions & 2 deletions library/Imbo/Image/ImagePreparation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
Imbo\Exception,
Imbo\Model\Image,
Imagick,
ImagickException;
ImagickException,
Rhumsaa\Uuid\Uuid;

/**
* Image preparation
Expand Down Expand Up @@ -84,7 +85,8 @@ public function prepareImage(EventInterface $event) {
->setBlob($imageBlob)
->setWidth($size['width'])
->setHeight($size['height'])
->setOriginalChecksum(md5($imageBlob));
->setOriginalChecksum(md5($imageBlob))
->setImageIdentifier((string) Uuid::uuid4());

$request->setImage($image);
}
Expand Down
2 changes: 1 addition & 1 deletion library/Imbo/Image/Transformation/Watermark.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function transform(EventInterface $event) {
// Try to load watermark image from storage
try {
$watermarkData = $event->getStorage()->getImage(
$event->getRequest()->getPublicKey(),
$event->getRequest()->getUser(),
$imageIdentifier
);

Expand Down
2 changes: 1 addition & 1 deletion library/Imbo/Model/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static function createFromException(Exception $exception, Request $reques
->setImboErrorCode($exception->getImboErrorCode() ?: Exception::ERR_UNSPECIFIED);

if ($image = $request->getImage()) {
$model->setImageIdentifier($image->getChecksum());
$model->setImageIdentifier($image->getImageIdentifier());
} else if ($identifier = $request->getImageIdentifier()) {
$model->setImageIdentifier($identifier);
}
Expand Down
2 changes: 1 addition & 1 deletion library/Imbo/Resource/GlobalShortUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ public function getImage(EventInterface $event) {

$request->query = new ParameterBag($params['query']);
$event->getResponse()->headers->set('X-Imbo-ShortUrl', $request->getUri());
$event->getManager()->trigger('image.get');
$event->getManager()->trigger('image.get', ['skipAccessControl' => true]);
}
}
2 changes: 1 addition & 1 deletion library/Imbo/Resource/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function addImage(EventInterface $event) {

$model = new Model\ArrayModel();
$model->setData(array(
'imageIdentifier' => $image->getChecksum(),
'imageIdentifier' => $image->getImageIdentifier(),
'width' => $image->getWidth(),
'height' => $image->getHeight(),
'extension' => $image->getExtension(),
Expand Down
2 changes: 1 addition & 1 deletion library/Imbo/Resource/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function post(EventInterface $event) {
));

$model = new Model\Metadata();
$model->setData($event->getDatabase()->getMetadata($request->getPublicKey(), $request->getImageIdentifier()));
$model->setData($event->getDatabase()->getMetadata($request->getUser(), $request->getImageIdentifier()));

$event->getResponse()->setModel($model);
}
Expand Down
8 changes: 4 additions & 4 deletions library/Imbo/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ class Router {
* @var array
*/
private $routes = array(
'image' => '#^/users/(?<user>[a-z0-9_-]{1,})/images/(?<imageIdentifier>[a-f0-9]{32})(\.(?<extension>gif|jpg|png))?$#',
'image' => '#^/users/(?<user>[a-z0-9_-]{1,})/images/(?<imageIdentifier>[a-f0-9-]{32,36})(\.(?<extension>gif|jpg|png))?$#',
'globalshorturl' => '#^/s/(?<shortUrlId>[a-zA-Z0-9]{7})$#',
'status' => '#^/status(/|(\.(?<extension>json|xml)))?$#',
'images' => '#^/users/(?<user>[a-z0-9_-]{1,})/images(/|(\.(?<extension>json|xml)))?$#',
'metadata' => '#^/users/(?<user>[a-z0-9_-]{1,})/images/(?<imageIdentifier>[a-f0-9]{32})/meta(?:data)?(/|\.(?<extension>json|xml))?$#',
'metadata' => '#^/users/(?<user>[a-z0-9_-]{1,})/images/(?<imageIdentifier>[a-f0-9-]{32,36})/meta(?:data)?(/|\.(?<extension>json|xml))?$#',
'user' => '#^/users/(?<user>[a-z0-9_-]{1,})(/|\.(?<extension>json|xml))?$#',
'stats' => '#^/stats(/|(\.(?<extension>json|xml)))?$#',
'index' => '#^/?$#',
'shorturls' => '#^/users/(?<user>[a-z0-9_-]{1,})/images/(?<imageIdentifier>[a-f0-9]{32})/shorturls(/|\.(?<extension>json|xml))?$#',
'shorturl' => '#^/users/(?<user>[a-z0-9_-]{1,})/images/(?<imageIdentifier>[a-f0-9]{32})/shorturls/(?<shortUrlId>[a-zA-Z0-9]{7})$#',
'shorturls' => '#^/users/(?<user>[a-z0-9_-]{1,})/images/(?<imageIdentifier>[a-f0-9-]{32,36})/shorturls(/|\.(?<extension>json|xml))?$#',
'shorturl' => '#^/users/(?<user>[a-z0-9_-]{1,})/images/(?<imageIdentifier>[a-f0-9-]{32,36})/shorturls/(?<shortUrlId>[a-zA-Z0-9]{7})$#',
'groups' => '#^/groups(/|(\.(?<extension>json|xml)))?$#',
'group' => '#^/groups/(?<group>[a-z0-9_-]{1,})(/|\.(?<extension>json|xml))?$#',
'keys' => '#^/keys/(?<publickey>[a-z0-9_-]{1,})$#',
Expand Down
10 changes: 5 additions & 5 deletions setup/doctrine.mysql.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE TABLE IF NOT EXISTS `imageinfo` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user` varchar(255) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(32) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(36) COLLATE utf8_danish_ci NOT NULL,
`size` int(10) unsigned NOT NULL,
`extension` varchar(5) COLLATE utf8_danish_ci NOT NULL,
`mime` varchar(20) COLLATE utf8_danish_ci NOT NULL,
Expand All @@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS `metadata` (
CREATE TABLE IF NOT EXISTS `shorturl` (
`shortUrlId` char(7) COLLATE utf8_danish_ci NOT NULL,
`user` varchar(255) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(32) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(36) COLLATE utf8_danish_ci NOT NULL,
`extension` char(3) COLLATE utf8_danish_ci DEFAULT NULL,
`query` text COLLATE utf8_danish_ci NOT NULL,
PRIMARY KEY (`shortUrlId`),
Expand All @@ -36,23 +36,23 @@ CREATE TABLE IF NOT EXISTS `shorturl` (

CREATE TABLE IF NOT EXISTS `storage_images` (
`user` varchar(255) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(32) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(36) COLLATE utf8_danish_ci NOT NULL,
`data` blob NOT NULL,
`updated` int(10) unsigned NOT NULL,
PRIMARY KEY (`user`,`imageIdentifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci;

CREATE TABLE IF NOT EXISTS `storage_image_variations` (
`user` varchar(255) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(32) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(36) COLLATE utf8_danish_ci NOT NULL,
`width` int(10) unsigned NOT NULL,
`data` blob NOT NULL,
PRIMARY KEY (`user`,`imageIdentifier`,`width`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci;

CREATE TABLE IF NOT EXISTS `imagevariations` (
`user` varchar(255) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(32) COLLATE utf8_danish_ci NOT NULL,
`imageIdentifier` char(36) COLLATE utf8_danish_ci NOT NULL,
`width` int(10) unsigned NOT NULL,
`height` int(10) unsigned NOT NULL,
`added` int(10) unsigned NOT NULL,
Expand Down

0 comments on commit adef026

Please sign in to comment.