Return exif in info call

pull/221/head
Varun Patil 2022-11-07 13:25:52 -08:00
parent 1d65a6dabe
commit 0fbe35db7d
5 changed files with 23 additions and 23 deletions

View File

@ -52,7 +52,8 @@ class ImageController extends ApiBase
$file = $file[0]; $file = $file[0];
// Get the image info // Get the image info
$info = $this->timelineQuery->getInfoById($file->getId()); $basic = false !== $this->request->getParam('basic', false);
$info = $this->timelineQuery->getInfoById($file->getId(), $basic);
return new JSONResponse($info, Http::STATUS_OK); return new JSONResponse($info, Http::STATUS_OK);
} }

View File

@ -48,14 +48,18 @@ class TimelineQuery
{ {
} }
public function getInfoById(int $id): array public function getInfoById(int $id, bool $basic): array
{ {
$qb = $this->connection->getQueryBuilder(); $qb = $this->connection->getQueryBuilder();
$qb->select('fileid', 'dayid', 'datetaken') $qb->select('fileid', 'dayid', 'datetaken', 'w', 'h')
->from('memories') ->from('memories')
->where($qb->expr()->eq('fileid', $qb->createNamedParameter($id, \PDO::PARAM_INT))) ->where($qb->expr()->eq('fileid', $qb->createNamedParameter($id, \PDO::PARAM_INT)))
; ;
if (!$basic) {
$qb->addSelect('exif');
}
$result = $qb->executeQuery(); $result = $qb->executeQuery();
$row = $result->fetch(); $row = $result->fetch();
$result->closeCursor(); $result->closeCursor();
@ -72,6 +76,9 @@ class TimelineQuery
'fileid' => (int) $row['fileid'], 'fileid' => (int) $row['fileid'],
'dayid' => (int) $row['dayid'], 'dayid' => (int) $row['dayid'],
'datetaken' => $utcTs, 'datetaken' => $utcTs,
'w' => (int) $row['w'],
'h' => (int) $row['h'],
'exif' => $basic ? [] : json_decode($row['exif'], true),
]; ];
} }
} }

View File

@ -99,20 +99,12 @@ class TimelineWrite
// Store raw metadata in the database // Store raw metadata in the database
// We need to remove blacklisted fields to prevent leaking info // We need to remove blacklisted fields to prevent leaking info
unset($exif['SourceFile']); unset($exif['SourceFile'], $exif['FileName'], $exif['ExifToolVersion'], $exif['Directory'], $exif['FileSize'], $exif['FileModifyDate'], $exif['FileAccessDate'], $exif['FileInodeChangeDate'], $exif['FilePermissions']);
unset($exif['FileName']);
unset($exif['ExifToolVersion']);
unset($exif['Directory']);
unset($exif['FileSize']);
unset($exif['FileModifyDate']);
unset($exif['FileAccessDate']);
unset($exif['FileInodeChangeDate']);
unset($exif['FilePermissions']);
// Truncate any fields >2048 chars // Truncate any fields >2048 chars
foreach ($exif as $key => &$value) { foreach ($exif as $key => &$value) {
if (\is_string($value) && \strlen($value) > 2048) { if (\is_string($value) && \strlen($value) > 2048) {
$exif[$key] = \substr($value, 0, 2048); $exif[$key] = substr($value, 0, 2048);
} }
} }

View File

@ -44,18 +44,18 @@ class Version400604Date20221107205439 extends SimpleMigrationStep
*/ */
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper
{ {
/** @var ISchemaWrapper $schema */ /** @var ISchemaWrapper $schema */
$schema = $schemaClosure(); $schema = $schemaClosure();
$table = $schema->getTable('memories'); $table = $schema->getTable('memories');
$table->addColumn('exif', 'text', [ $table->addColumn('exif', 'text', [
'notnull' => false, 'notnull' => false,
'length' => 65535, 'length' => 65535,
'default' => '', 'default' => '',
]); ]);
return $schema; return $schema;
} }
/** /**

View File

@ -186,7 +186,7 @@ export default class EditDate extends Mixins(GlobalMixin) {
const calls = photos.map((p) => async () => { const calls = photos.map((p) => async () => {
try { try {
const res = await axios.get<any>( const res = await axios.get<any>(
generateUrl(INFO_API_URL, { id: p.fileid }) generateUrl(INFO_API_URL, { id: p.fileid }) + "?basic=1"
); );
if (typeof res.data.datetaken !== "number") { if (typeof res.data.datetaken !== "number") {
console.error("Invalid date for", p.fileid); console.error("Invalid date for", p.fileid);