Log failure on parsing
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
parent
fa6c257084
commit
1d2d7fd60d
|
@ -84,7 +84,10 @@ if ($debugging) {
|
|||
|
||||
$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
|
||||
$server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
|
||||
$server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
|
||||
$server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(
|
||||
\OC::$server->getAppDataDir('dav-photocache'),
|
||||
\OC::$server->getLogger()
|
||||
)));
|
||||
$server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
|
||||
|
||||
// And off we go!
|
||||
|
|
|
@ -54,7 +54,8 @@ class Application extends App {
|
|||
|
||||
$container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) {
|
||||
return new PhotoCache(
|
||||
$server->getAppDataDir('dav-photocache')
|
||||
$server->getAppDataDir('dav-photocache'),
|
||||
$server->getLogger()
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -108,7 +108,6 @@ class ImageExportPlugin extends ServerPlugin {
|
|||
|
||||
$response->setBody($file->getContent());
|
||||
} catch (NotFoundException $e) {
|
||||
var_dump($e);
|
||||
$response->setStatus(404);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,27 +24,32 @@
|
|||
namespace OCA\DAV\CardDAV;
|
||||
|
||||
use OCP\Files\IAppData;
|
||||
use OCP\ILogger;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\Files\NotPermittedException;
|
||||
use OCP\Files\SimpleFS\ISimpleFile;
|
||||
use OCP\Files\SimpleFS\ISimpleFolder;
|
||||
use Sabre\CardDAV\Card;
|
||||
use Sabre\VObject\Property\Binary;
|
||||
use Sabre\VObject\Property\Uri;
|
||||
use Sabre\VObject\Reader;
|
||||
|
||||
class PhotoCache {
|
||||
|
||||
/** @var IAppData $appData */
|
||||
/** @var IAppData */
|
||||
protected $appData;
|
||||
|
||||
/** @var ILogger */
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* PhotoCache constructor.
|
||||
*
|
||||
* @param IAppData $appData
|
||||
* @param ILogger $logger
|
||||
*/
|
||||
public function __construct(IAppData $appData) {
|
||||
public function __construct(IAppData $appData, ILogger $logger) {
|
||||
$this->appData = $appData;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,13 +140,14 @@ class PhotoCache {
|
|||
|
||||
$ratio = $photo->width() / $photo->height();
|
||||
if ($ratio < 1) {
|
||||
$ratio = 1/$ratio;
|
||||
$ratio = 1 / $ratio;
|
||||
}
|
||||
$size = (int)($size * $ratio);
|
||||
|
||||
$size = (int) ($size * $ratio);
|
||||
if ($size !== -1) {
|
||||
$photo->resize($size);
|
||||
}
|
||||
|
||||
try {
|
||||
$file = $folder->newFile($path);
|
||||
$file->putContent($photo->data());
|
||||
|
@ -153,7 +159,6 @@ class PhotoCache {
|
|||
return $file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $addressBookId
|
||||
* @param string $cardUri
|
||||
|
@ -205,7 +210,7 @@ class PhotoCache {
|
|||
return false;
|
||||
}
|
||||
if (substr_count($parsed['path'], ';') === 1) {
|
||||
list($type,) = explode(';', $parsed['path']);
|
||||
list($type) = explode(';', $parsed['path']);
|
||||
}
|
||||
$val = file_get_contents($val);
|
||||
} else {
|
||||
|
@ -219,16 +224,18 @@ class PhotoCache {
|
|||
'image/gif',
|
||||
];
|
||||
|
||||
if(!in_array($type, $allowedContentTypes, true)) {
|
||||
if (!in_array($type, $allowedContentTypes, true)) {
|
||||
$type = 'application/octet-stream';
|
||||
}
|
||||
|
||||
return [
|
||||
'Content-Type' => $type,
|
||||
'body' => $val
|
||||
'body' => $val
|
||||
];
|
||||
} catch(\Exception $ex) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->logException($ex, [
|
||||
'message' => 'Exception during vcard photo parsing'
|
||||
]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -167,7 +167,10 @@ class Server {
|
|||
$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
|
||||
$this->server->addPlugin(new VCFExportPlugin());
|
||||
$this->server->addPlugin(new MultiGetExportPlugin());
|
||||
$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
|
||||
$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(
|
||||
\OC::$server->getAppDataDir('dav-photocache'),
|
||||
\OC::$server->getLogger())
|
||||
));
|
||||
}
|
||||
|
||||
// system tags plugins
|
||||
|
|
Loading…
Reference in New Issue