pslam: fix more issues

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/877/head
Varun Patil 2023-10-15 13:16:57 -07:00
parent bd2101e7bb
commit 49848bbd16
10 changed files with 51 additions and 36 deletions

View File

@ -160,7 +160,9 @@ class PlacesBackend extends Backend
foreach ($places as &$row) { foreach ($places as &$row) {
$row['osm_id'] = (int) $row['osm_id']; $row['osm_id'] = (int) $row['osm_id'];
$row['count'] = (int) $row['count']; $row['count'] = (int) $row['count'];
self::choosePlaceLang($row, $lang);
$row['name'] = self::translateName($lang, $row['name'], $row['other_names']);
unset($row['other_names']);
} }
return $places; return $places;
@ -198,19 +200,24 @@ class PlacesBackend extends Backend
/** /**
* Choose the best name for the place. * Choose the best name for the place.
*/ */
public static function choosePlaceLang(array &$place, string $lang): array public static function translateName(string $lang, string $name, ?string $otherNames): string
{ {
try { if (empty($otherNames)) {
$otherNames = json_decode($place['other_names'], true); return $name;
if (isset($otherNames[$lang])) {
$place['name'] = $otherNames[$lang];
}
} catch (\Error $e) {
// Ignore
} finally {
unset($place['other_names']);
} }
return $place; try {
// Decode the other names
$json = json_decode($otherNames, true);
// Check if the language is available
if (\array_key_exists($lang, $json) && \is_string($json[$lang])) {
return $json[$lang];
}
} catch (\Error) {
// Ignore errors, just use original name
}
return $name;
} }
} }

View File

@ -134,9 +134,10 @@ class VideoController extends GenericApiController
$liveVideoPath = null; $liveVideoPath = null;
// Video is inside the file // Video is inside the file
$path = null; $path = '<>';
if (str_starts_with($liveid, 'self__')) { if (str_starts_with($liveid, 'self__')) {
$path = $file->getStorage()->getLocalFile($file->getInternalPath()); $path = $file->getStorage()->getLocalFile($file->getInternalPath())
?: throw Exceptions::BadRequest('[Video] File path missing (self__*)');
$mime = 'video/mp4'; $mime = 'video/mp4';
$name = $file->getName().'.mp4'; $name = $file->getName().'.mp4';
} }
@ -145,7 +146,7 @@ class VideoController extends GenericApiController
if ('self__trailer' === $liveid) { if ('self__trailer' === $liveid) {
try { // Get trailer try { // Get trailer
$blob = Exif::getBinaryExifProp($path, '-trailer'); $blob = Exif::getBinaryExifProp($path, '-trailer');
} catch (\Exception $e) { } catch (\Exception) {
throw Exceptions::NotFound('file trailer'); throw Exceptions::NotFound('file trailer');
} }
} elseif (str_starts_with($liveid, 'self__exifbin=')) { } elseif (str_starts_with($liveid, 'self__exifbin=')) {
@ -158,15 +159,10 @@ class VideoController extends GenericApiController
try { // Get embedded video file try { // Get embedded video file
$blob = Exif::getBinaryExifProp($path, "-{$field}"); $blob = Exif::getBinaryExifProp($path, "-{$field}");
} catch (\Exception $e) { } catch (\Exception) {
throw Exceptions::NotFound('Could not read binary EXIF field'); throw Exceptions::NotFound('Could not read binary EXIF field');
} }
} elseif (str_starts_with($liveid, 'self__traileroffset=')) { } elseif (str_starts_with($liveid, 'self__traileroffset=')) {
// Make sure we have a path
if (!$path) {
throw Exceptions::BadRequest('File path missing for self__traileroffset');
}
// Remove prefix // Remove prefix
$offset = (int) substr($liveid, \strlen('self__traileroffset=')); $offset = (int) substr($liveid, \strlen('self__traileroffset='));
if ($offset <= 0) { if ($offset <= 0) {
@ -320,7 +316,7 @@ class VideoController extends GenericApiController
* *
* @return mixed The response from upstream * @return mixed The response from upstream
*/ */
private static function postFile(string $client, mixed $blob): mixed private static function postFile(string $client, string $blob): mixed
{ {
try { try {
return self::postFileInternal($client, $blob); return self::postFileInternal($client, $blob);

View File

@ -34,10 +34,8 @@ class IndexJob extends TimedJob
/** /**
* Run the background indexing job. * Run the background indexing job.
*
* @param mixed $argument
*/ */
protected function run($argument) protected function run(mixed $argument): void
{ {
// Check if indexing is enabled // Check if indexing is enabled
if ('0' === Util::getSystemConfig('memories.index.mode')) { if ('0' === Util::getSystemConfig('memories.index.mode')) {

View File

@ -69,7 +69,8 @@ class LivePhoto
// //
// The video is then located at the end of the file, so we can get the offset. // The video is then located at the end of the file, so we can get the offset.
// Match each DirectoryItemSemantic to find MotionPhoto, then get the length. // Match each DirectoryItemSemantic to find MotionPhoto, then get the length.
$path = $file->getStorage()->getLocalFile($file->getInternalPath()); $path = $file->getStorage()->getLocalFile($file->getInternalPath())
?: throw new \Exception('[BUG][LivePhoto] Failed to get local file path');
$extExif = Exif::getExifWithDuplicates($path); $extExif = Exif::getExifWithDuplicates($path);
foreach ($extExif as $key => $value) { foreach ($extExif as $key => $value) {

View File

@ -6,6 +6,7 @@ namespace OCA\Memories\Db;
use OCA\Memories\Util; use OCA\Memories\Util;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\ITags; use OCP\ITags;
trait TimelineQueryFilters trait TimelineQueryFilters
@ -55,7 +56,7 @@ trait TimelineQueryFilters
} }
} }
private function getFavoriteVCategoryFun(IQueryBuilder &$query) private function getFavoriteVCategoryFun(IQueryBuilder &$query): IQueryFunction
{ {
return $query->createFunction( return $query->createFunction(
$query->getConnection()->getQueryBuilder()->select('id')->from('vcategory', 'vc')->where( $query->getConnection()->getQueryBuilder()->select('id')->from('vcategory', 'vc')->where(

View File

@ -80,20 +80,30 @@ trait TimelineQuerySingleItem
// Get address from places // Get address from places
if (Util::placesGISType() > 0) { if (Util::placesGISType() > 0) {
// Get names of places for this file
$qb = $this->connection->getQueryBuilder(); $qb = $this->connection->getQueryBuilder();
$qb->select('e.name', 'e.other_names') $places = $qb->select('e.name', 'e.other_names')
->from('memories_places', 'mp') ->from('memories_places', 'mp')
->innerJoin('mp', 'memories_planet', 'e', $qb->expr()->eq('mp.osm_id', 'e.osm_id')) ->innerJoin('mp', 'memories_planet', 'e', $qb->expr()->eq('mp.osm_id', 'e.osm_id'))
->where($qb->expr()->eq('mp.fileid', $qb->createNamedParameter($id, \PDO::PARAM_INT))) ->where($qb->expr()->eq('mp.fileid', $qb->createNamedParameter($id, \PDO::PARAM_INT)))
->andWhere($qb->expr()->gt('e.admin_level', $qb->expr()->literal(0, \PDO::PARAM_INT))) ->andWhere($qb->expr()->gt('e.admin_level', $qb->expr()->literal(0, \PDO::PARAM_INT)))
->orderBy('e.admin_level', 'DESC') ->orderBy('e.admin_level', 'DESC')
->executeQuery()->fetchAll()
; ;
$places = $qb->executeQuery()->fetchAll(); if (\count($places)) {
$lang = Util::getUserLang(); // Get user language
if (\count($places) > 0) { $lang = Util::getUserLang();
$places = array_map(static fn ($p) => PlacesBackend::choosePlaceLang($p, $lang)['name'], $places);
$info['address'] = implode(', ', $places); // Get translated address
$info['address'] = implode(', ', array_map(
static fn ($p): string => PlacesBackend::translateName(
$lang,
$p['name'],
$p['other_names'],
),
$places,
));
} }
} }

View File

@ -65,7 +65,7 @@ trait TimelineWriteOrphans
} }
// Mark all files as not orphaned. // Mark all files as not orphaned.
$fileIds = array_map(static fn ($row) => $row['fileid'], $orphans); $fileIds = array_map(static fn ($row): int => (int) $row['fileid'], $orphans);
$this->orphanAll(false, $fileIds, true); $this->orphanAll(false, $fileIds, true);
$this->connection->commit(); $this->connection->commit();

View File

@ -57,6 +57,8 @@ class PostWriteListener implements IEventListener
// Check if a directory at a higher level contains a .nomedia file // Check if a directory at a higher level contains a .nomedia file
try { try {
$parent = $node; $parent = $node;
/** @psalm-suppress RedundantConditionGivenDocblockType */
while ($parent = $parent->getParent()) { while ($parent = $parent->getParent()) {
if ($parent->nodeExists('.nomedia') || $parent->nodeExists('.nomemories')) { if ($parent->nodeExists('.nomedia') || $parent->nodeExists('.nomemories')) {
return; return;

View File

@ -27,7 +27,7 @@ class Places
/** /**
* Make SQL query to detect GIS type. * Make SQL query to detect GIS type.
* *
* @psalm-return 0|1|2 * @psalm-return 0|1|2|3
*/ */
public function detectGisType(): int public function detectGisType(): int
{ {

View File

@ -44,7 +44,7 @@ trait UtilController
parent::__construct(); parent::__construct();
} }
public function callback(Http\IOutput $output) public function callback(Http\IOutput $output): void
{ {
try { try {
($this->closure)($output); ($this->closure)($output);