Skip to content

Commit

Permalink
Remove mbtiles & sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed May 29, 2024
1 parent f3a0be4 commit 888d4de
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 220 deletions.
7 changes: 3 additions & 4 deletions IsraelHiking.API/Controllers/FilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,19 @@ private async Task<DataContainerPoco> ConvertToDataContainer(byte[] data, string
/// Get a list of files that need to be downloaded since they are out dated
/// </summary>
/// <param name="lastModified"></param>
/// <param name="pmtiles">This parameter was added in 1.2024</param>
/// <returns></returns>
[HttpGet]
[Route("offline")]
[Authorize]
public async Task<IActionResult> GetOfflineFiles([FromQuery] DateTime lastModified, [FromQuery] bool pmtiles)
public async Task<IActionResult> GetOfflineFiles([FromQuery] DateTime lastModified)
{
if (!await _receiptValidationGateway.IsEntitled(User.Identity?.Name))
{
_logger.LogInformation($"Unable to get the list of offline files for user: {User.Identity?.Name} since the user is not entitled, date: {lastModified}");
return Forbid();
}
_logger.LogInformation($"Getting the list of offline files for user: {User.Identity?.Name}, date: {lastModified}, pmtiles: {pmtiles}");
return Ok(_offlineFilesService.GetUpdatedFilesList(lastModified, pmtiles));
_logger.LogInformation($"Getting the list of offline files for user: {User.Identity?.Name}, date: {lastModified}");
return Ok(_offlineFilesService.GetUpdatedFilesList(lastModified));
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions IsraelHiking.API/Services/IOfflineFilesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public interface IOfflineFilesService
/// Get a list of files that have been updated since a given date
/// </summary>
/// <param name="lastModifiedDate">The date to check against</param>
/// <param name="pmtiles"></param>
/// <returns>A list of file names</returns>
Dictionary<string, DateTime> GetUpdatedFilesList(DateTime lastModifiedDate, bool pmtiles);
Dictionary<string, DateTime> GetUpdatedFilesList(DateTime lastModifiedDate);
}
}
4 changes: 2 additions & 2 deletions IsraelHiking.API/Services/OfflineFilesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public OfflineFilesService(IFileSystemHelper fileSystemHelper,
}

/// <inheritdoc/>
public Dictionary<string, DateTime> GetUpdatedFilesList(DateTime lastModifiedDate, bool pmtiles)
public Dictionary<string, DateTime> GetUpdatedFilesList(DateTime lastModifiedDate)
{
var filesDictionary = new Dictionary<string, DateTime>();
var contents = _fileProvider.GetDirectoryContents(string.Empty);
Expand All @@ -51,7 +51,7 @@ public Dictionary<string, DateTime> GetUpdatedFilesList(DateTime lastModifiedDat
{
continue;
}
if (content.Name.EndsWith(pmtiles ? ".pmtiles" : ".mbtiles") || content.Name.StartsWith("style"))
if (content.Name.EndsWith(".pmtiles") || content.Name.StartsWith("style"))
{
filesDictionary[content.Name] = content.LastModified.DateTime;
}
Expand Down
77 changes: 5 additions & 72 deletions IsraelHiking.Web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions IsraelHiking.Web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"@awesome-cordova-plugins/social-sharing": "^6.7.0",
"@capacitor-community/keep-awake": "^5.0.0",
"@capacitor-community/screen-brightness": "^6.0.0",
"@capacitor-community/sqlite": "^5.7.3-3",
"@capacitor/android": "^6.0.0",
"@capacitor/app": "^6.0.0",
"@capacitor/camera": "^6.0.0",
Expand Down Expand Up @@ -59,7 +58,7 @@
"d3": "^7.9.0",
"d3-regression": "^1.3.10",
"deepmerge": "^4.3.1",
"dexie": "^3.2.6",
"dexie": "^4.0.7",
"fflate": "^0.8.2",
"file-saver-es": "^2.0.5",
"font-awesome": "^4.7.0",
Expand All @@ -68,6 +67,7 @@
"intl": "^1.2.5",
"invert-color": "^2.0.0",
"isomorphic-xml2js": "^0.1.3",
"jszip": "^3.10.1",
"linear-interpolator": "^1.0.2",
"lodash-es": "^4.17.21",
"lottie-web": "^5.12.2",
Expand Down
2 changes: 0 additions & 2 deletions IsraelHiking.Web/src/application/application.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ import { GlobalErrorHandler } from "./services/global-error.handler";
import { OverpassTurboService } from "./services/overpass-turbo.service";
import { ImageAttributionService } from "./services/image-attribution.service";
import { PmTilesService } from "./services/pmtiles.service";
import { MBTilesService } from "./services/mbtiles.service";
// interactions
import { RouteEditPoiInteraction } from "./components/intercations/route-edit-poi.interaction";
import { RouteEditRouteInteraction } from "./components/intercations/route-edit-route.interaction";
Expand Down Expand Up @@ -310,7 +309,6 @@ const initializeApplication = (injector: Injector) => async () => {
OverpassTurboService,
ImageAttributionService,
PmTilesService,
MBTilesService,
AudioPlayerFactory,
FileSystemWrapper,
// eslint-disable-next-line
Expand Down
15 changes: 1 addition & 14 deletions IsraelHiking.Web/src/application/services/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import deepmerge from "deepmerge";
import { LoggingService } from "./logging.service";
import { RunningContextService } from "./running-context.service";
import { PmTilesService } from "./pmtiles.service";
import { MBTilesService } from "./mbtiles.service";
import { POPULARITY_HEATMAP, initialState } from "../reducers/initial-state";
import { ClearHistoryAction } from "../reducers/routes.reducer";
import { SetSelectedPoiAction, SetSidebarAction } from "../reducers/poi.reducer";
Expand Down Expand Up @@ -46,13 +45,11 @@ export class DatabaseService {
constructor(private readonly loggingService: LoggingService,
private readonly runningContext: RunningContextService,
private readonly pmTilesService: PmTilesService,
private readonly mbtilesService: MBTilesService,
private readonly store: Store) {
this.updating = false;
}

public async initialize() {
this.mbtilesService.initialize();
this.stateDatabase = new Dexie(DatabaseService.STATE_DB_NAME);
this.stateDatabase.version(1).stores({
state: "id"
Expand Down Expand Up @@ -101,7 +98,7 @@ export class DatabaseService {

private initCustomTileLoadFunction() {
addProtocol("custom", async (params, _abortController) => {
const data = await this.getTile(params.url);
const data = await this.pmTilesService.getTile(params.url);
return {data};
});
}
Expand All @@ -113,7 +110,6 @@ export class DatabaseService {
this.store.dispatch(new SetSidebarAction(false));
const finalState = this.store.snapshot() as ApplicationState;
await this.updateState(finalState);
await this.mbtilesService.uninitialize();
}

private async updateState(state: ApplicationState) {
Expand All @@ -133,15 +129,6 @@ export class DatabaseService {
}
}

public async getTile(url: string): Promise<ArrayBuffer> {
try {
return await this.pmTilesService.getTile(url);
} catch (ex) {
this.loggingService.error(`[Database] Failed to get tile from pmtiles: ${(ex as Error).message}`);
}
return this.mbtilesService.getTile(url);
}

public storePois(pois: GeoJSON.Feature[]): Promise<any> {
return this.poisDatabase.table(DatabaseService.POIS_TABLE_NAME).bulkPut(pois);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { firstValueFrom } from "rxjs";

import { LoggingService } from "./logging.service";
import { SpatialService } from "./spatial.service";
import { DatabaseService } from "./database.service";
import { PmTilesService } from "./pmtiles.service";
import { Urls } from "../urls";
import type { ApplicationState, LatLngAlt } from "../models/models";

Expand All @@ -20,7 +20,7 @@ export class ElevationProvider {

constructor(private readonly httpClient: HttpClient,
private readonly loggingService: LoggingService,
private readonly databaseService: DatabaseService,
private readonly pmTilesService: PmTilesService,
private readonly store: Store) {
this.elevationCache = new Map<string, Uint8ClampedArray>();
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export class ElevationProvider {
continue;
}

const arrayBuffer = await this.databaseService.getTile(`custom://TerrainRGB/${zoom}/${tileX}/${tileY}.png`);
const arrayBuffer = await this.pmTilesService.getTile(`custom://TerrainRGB/${zoom}/${tileX}/${tileY}.png`);
const data = await this.getImageData(arrayBuffer);
this.elevationCache.set(key, data);
}
Expand Down
Loading

0 comments on commit 888d4de

Please sign in to comment.