forked from upstream-mirrors/OpenTracks
While importing photos, check url carefully.
(cherry picked from commit 309c96e4789bd7623b84720a8c8f2bf297c95d59)
This commit is contained in:
+20
-3
@@ -366,15 +366,32 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
||||
/**
|
||||
* Gets the photo url for a file.
|
||||
*
|
||||
* @param fileName the file name
|
||||
* @param externalPhotoUrl the file name
|
||||
*/
|
||||
protected String getPhotoUrl(String fileName) {
|
||||
protected String getInternalPhotoUrl(String externalPhotoUrl) {
|
||||
if (importTrackId == -1L) {
|
||||
Log.e(TAG, "Track id is invalid.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (externalPhotoUrl == null) {
|
||||
Log.i(TAG, "External photo url is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
Uri externalPhotoUri = Uri.parse(externalPhotoUrl);
|
||||
if (externalPhotoUri == null) {
|
||||
Log.w(TAG, "Could not parse external photo url.");
|
||||
return null;
|
||||
}
|
||||
String filename = externalPhotoUri.getLastPathSegment();
|
||||
if (filename == null) {
|
||||
Log.w(TAG, "External photo contains no filename.");
|
||||
return null;
|
||||
}
|
||||
|
||||
File dir = FileUtils.getPhotoDir(context, importTrackId);
|
||||
File file = new File(dir, fileName);
|
||||
File file = new File(dir, externalPhotoUrl);
|
||||
|
||||
Uri photoUri = FileUtils.getUriForFile(context, file);
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package de.dennisguse.opentracks.io.file.importer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
@@ -187,9 +186,7 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
|
||||
}
|
||||
|
||||
// If there is photoUrl it has to be changed because that url in kml file is a relative path to the internal kmz file.
|
||||
if (photoUrl != null) {
|
||||
photoUrl = getPhotoUrl(Uri.parse(photoUrl).getLastPathSegment());
|
||||
}
|
||||
photoUrl = getInternalPhotoUrl(photoUrl);
|
||||
|
||||
addWaypoint();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user