meta: use places
parent
c3fa9f0d4c
commit
bae5f99b2b
|
@ -374,9 +374,9 @@ class ApiBase extends Controller
|
|||
/**
|
||||
* Check if geolocation is enabled for this user.
|
||||
*/
|
||||
protected function geoPlacesIsEnabled(): bool
|
||||
protected function placesIsEnabled(): bool
|
||||
{
|
||||
return true;
|
||||
return \OCA\Memories\Util::placesGISType() !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -238,7 +238,7 @@ class DaysController extends ApiBase
|
|||
}
|
||||
|
||||
// Filter only for one place
|
||||
if ($this->geoPlacesIsEnabled()) {
|
||||
if ($this->placesIsEnabled()) {
|
||||
if ($locationId = $this->request->getParam('place')) {
|
||||
$transforms[] = [$this->timelineQuery, 'transformPlaceFilter', (int) $locationId];
|
||||
}
|
||||
|
|
|
@ -114,8 +114,7 @@ class PageController extends Controller
|
|||
// Image editor
|
||||
$policy->addAllowedConnectDomain('data:');
|
||||
|
||||
// Allow nominatim for metadata
|
||||
$policy->addAllowedConnectDomain('nominatim.openstreetmap.org');
|
||||
// Allow OSM
|
||||
$policy->addAllowedFrameDomain('www.openstreetmap.org');
|
||||
|
||||
return $policy;
|
||||
|
|
|
@ -43,7 +43,7 @@ class PlacesController extends ApiBase
|
|||
}
|
||||
|
||||
// Check tags enabled for this user
|
||||
if (!$this->geoPlacesIsEnabled()) {
|
||||
if (!$this->placesIsEnabled()) {
|
||||
return new JSONResponse(['message' => 'Places not enabled'], Http::STATUS_PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ class PlacesController extends ApiBase
|
|||
}
|
||||
|
||||
// Check tags enabled for this user
|
||||
if (!$this->geoPlacesIsEnabled()) {
|
||||
if (!$this->placesIsEnabled()) {
|
||||
return new JSONResponse(['message' => 'Places not enabled'], Http::STATUS_PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
|
|
|
@ -92,12 +92,28 @@ class TimelineQuery
|
|||
}
|
||||
}
|
||||
|
||||
$address = null;
|
||||
if (!$basic && \OCA\Memories\Util::placesGISType() !== 0) {
|
||||
$qb = $this->connection->getQueryBuilder();
|
||||
$qb->select('e.name')
|
||||
->from('memories_places', 'mp')
|
||||
->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)))
|
||||
->orderBy('e.admin_level', 'DESC')
|
||||
;
|
||||
$places = $qb->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
|
||||
if (\count($places) > 0) {
|
||||
$address = implode(', ', $places);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'fileid' => (int) $row['fileid'],
|
||||
'dayid' => (int) $row['dayid'],
|
||||
'datetaken' => $utcTs,
|
||||
'w' => (int) $row['w'],
|
||||
'h' => (int) $row['h'],
|
||||
'datetaken' => $utcTs,
|
||||
'address' => $address,
|
||||
'exif' => $exif,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -289,8 +289,7 @@ class TimelineWrite
|
|||
public function updateGeoData(File &$file, float $lat, float $lon): void
|
||||
{
|
||||
// Get GIS type
|
||||
$config = \OC::$server->get(\OCP\IConfig::class);
|
||||
$gisType = $config->getSystemValue('memories.gis_type', 0);
|
||||
$gisType = \OCA\Memories\Util::placesGISType();
|
||||
|
||||
// Construct WHERE clause depending on GIS type
|
||||
$where = null;
|
||||
|
|
|
@ -142,6 +142,15 @@ class Util
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if geolocation (places) is enabled and available.
|
||||
* Returns the type of the GIS.
|
||||
*/
|
||||
public static function placesGISType(): int
|
||||
{
|
||||
return \OC::$server->get(\OCP\IConfig::class)->getSystemValue('memories.gis_type', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill all instances of a process by name.
|
||||
* Similar to pkill, which may not be available on all systems.
|
||||
|
|
|
@ -87,7 +87,6 @@ export default defineComponent({
|
|||
fileInfo: null as IFileInfo,
|
||||
exif: {} as { [prop: string]: any },
|
||||
baseInfo: {} as any,
|
||||
nominatim: null as any,
|
||||
state: 0,
|
||||
}),
|
||||
|
||||
|
@ -245,22 +244,7 @@ export default defineComponent({
|
|||
},
|
||||
|
||||
address(): string | null {
|
||||
if (!this.lat || !this.lon) return null;
|
||||
|
||||
if (!this.nominatim) return this.t("memories", "Loading …");
|
||||
|
||||
const n = this.nominatim;
|
||||
const country = n.address.country_code?.toUpperCase();
|
||||
|
||||
if (n.address?.city && n.address.state) {
|
||||
return `${n.address.city}, ${n.address.state}, ${country}`;
|
||||
} else if (n.address?.state) {
|
||||
return `${n.address.state}, ${country}`;
|
||||
} else if (n.address?.country) {
|
||||
return n.address.country;
|
||||
} else {
|
||||
return n.display_name;
|
||||
}
|
||||
return this.baseInfo.address;
|
||||
},
|
||||
|
||||
lat(): number {
|
||||
|
@ -293,7 +277,6 @@ export default defineComponent({
|
|||
this.state = Math.random();
|
||||
this.fileInfo = fileInfo;
|
||||
this.exif = {};
|
||||
this.nominatim = null;
|
||||
|
||||
const state = this.state;
|
||||
const url = API.IMAGE_INFO(fileInfo.id);
|
||||
|
@ -302,9 +285,6 @@ export default defineComponent({
|
|||
|
||||
this.baseInfo = res.data;
|
||||
this.exif = res.data.exif || {};
|
||||
|
||||
// Lazy loading
|
||||
this.getNominatim().catch();
|
||||
},
|
||||
|
||||
handleFileUpdated({ fileid }) {
|
||||
|
@ -312,19 +292,6 @@ export default defineComponent({
|
|||
this.update(this.fileInfo);
|
||||
}
|
||||
},
|
||||
|
||||
async getNominatim() {
|
||||
const lat = this.lat;
|
||||
const lon = this.lon;
|
||||
if (!lat || !lon) return null;
|
||||
|
||||
const state = this.state;
|
||||
const n = await axios.get(
|
||||
`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=json&zoom=18`
|
||||
);
|
||||
if (state !== this.state) return;
|
||||
this.nominatim = n.data;
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@ -368,4 +335,4 @@ export default defineComponent({
|
|||
min-height: 200px;
|
||||
max-height: 250px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
|
|
@ -76,6 +76,7 @@ export type IPhoto = {
|
|||
h: number;
|
||||
w: number;
|
||||
datetaken: number;
|
||||
address?: string;
|
||||
exif?: {
|
||||
Rotation?: number;
|
||||
Orientation?: number;
|
||||
|
|
Loading…
Reference in New Issue