Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): Does not assign lat/lon if they are at 0,0 #2991 #3669

Merged
merged 4 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions server/src/infra/migrations/1692057328660-fixGPSNullIsland.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class FixGPSNullIsland1692057328660 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`UPDATE "exif" SET latitude = NULL, longitude = NULL WHERE latitude = 0 AND longitude = 0;`);
}

public async down(): Promise<void> {
// Setting lat,lon to 0 not necessary
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,16 @@ export class MetadataExtractionProcessor {

const latitude = getExifProperty('GPSLatitude');
const longitude = getExifProperty('GPSLongitude');
newExif.latitude = latitude !== null ? parseLatitude(latitude) : null;
newExif.longitude = longitude !== null ? parseLongitude(longitude) : null;
const lat = parseLatitude(latitude);
const lon = parseLongitude(longitude);

if (lat === 0 && lon === 0) {
this.logger.warn(`Latitude & Longitude were on Null Island (${lat},${lon}), not assigning coordinates`);
} else {
newExif.latitude = lat;
newExif.longitude = lon;
}

if (getExifProperty('MotionPhoto')) {
// Seen on more recent Pixel phones: starting as early as Pixel 4a, possibly earlier.
const rawDirectory = getExifProperty('Directory');
Expand Down
12 changes: 12 additions & 0 deletions server/src/microservices/utils/exif/coordinates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ describe('parsing latitude from string input', () => {
});
});

describe('parsing latitude from null input', () => {
it('returns null for null input', () => {
expect(parseLatitude(null)).toBeNull();
});
});

describe('parsing longitude from string input', () => {
it('returns null for invalid inputs', () => {
expect(parseLongitude('')).toBeNull();
Expand All @@ -44,3 +50,9 @@ describe('parsing longitude from string input', () => {
expect(parseLongitude('-0.0')).toBeCloseTo(-0.0);
});
});

describe('parsing longitude from null input', () => {
it('returns null for null input', () => {
expect(parseLongitude(null)).toBeNull();
});
});
11 changes: 9 additions & 2 deletions server/src/microservices/utils/exif/coordinates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { isNumberInRange } from '../numbers';

export function parseLatitude(input: string | number): number | null {
export function parseLatitude(input: string | number | null): number | null {
if (input === null) {
return null;
}
const latitude = typeof input === 'string' ? Number.parseFloat(input) : input;

if (isNumberInRange(latitude, -90, 90)) {
Expand All @@ -9,7 +12,11 @@ export function parseLatitude(input: string | number): number | null {
return null;
}

export function parseLongitude(input: string | number): number | null {
export function parseLongitude(input: string | number | null): number | null {
if (input === null) {
return null;
}

const longitude = typeof input === 'string' ? Number.parseFloat(input) : input;

if (isNumberInRange(longitude, -180, 180)) {
Expand Down