|-- memory -- business logic for memory "database"
|-- sql -- business logic for sql database
|-- diagnostics -- contains the checks for the startup diagnostics (checks if all the settings are valid, all packeges are avaiale, image folder exists, etc.)
|-- fileprocessing -- photo and video converting code
|-- jobs -- code about job scheduling (crontab like feature)
|-- threading -- code that runs on a separate threading
|-- DiskManagerWorker.ts -- scans a direcory
|-- Metadataloader.ts -- parses a photo / video for metadata
|-- *Worker.ts -- queues and helper classes to convert video / photo, parse a directory
|-- routers -- contains the declarations of the HTTP Api endpoints
|-- index.ts -- here starts the Server up (callst server.ts)
|-- server.ts -- this is HTTP server startup code
|-- ProjectPath.ts -- singleton, contains the project related paths
```
## Case-study: Listing a directory
Scenario: Web UI wants to show the `/demoDir` directory, usind SQL database with low reindexing severity.
4. Loding data from local_storage: [gallery.service.ts]: `galleryCacheService.getDirectory('/demoDir')`
5. Make a call to backend if the content changed [gallery.service.ts]: `networkService.getJson<ContentWrapperWithError>('/gallery/content/' + '/testDir', params)`
* params contains last modification and last scanned date that is know from the local_storage cache
Server side:
6. Requests hits the server in [GalleryRouter.ts]: `protected static addDirectoryList(app: Express)`:
8. Normalizing `directory` path parameter (in this case `/testDir`): [AuthenticationMWs.ts]: `AuthenticationMWs.normalizePathParam('directory')`
* Makes sure that path does not go out of the allowed paths (gallery itself)
9. Cheking if the path exists and the User has rights to access it: [AuthenticationMWs.ts]:`AuthenticationMWs.authorisePath('directory', true)`
* returns 403 if not accessable
10. Injecting gallery version to the HTTP header: [VersionMWs.ts]:`VersionMWs.injectGalleryVersion`
* gallery version is a hash that represents the current gallery status (latest modified date, number of photos/videos, etc)
11. Getting the content of `/testDir` [GalleryMWs]: GalleryMWs.listDirectory
1. If the last modificatoin and scan date of `/testDir` equals with what the client have sent, returning empty result to the client (skipping the rest)
2. If last modification date is different from what the client knew, reindexing `/testDir`: `IndexingManager.indexDirectory(relativeDirectoryName)`
* Scans a directory, asyncronously saves it to DB, while directly retourns with raw results from `DiskManagerWorker.ts`
3. If Last scan heppened a while ago, reindex it asyncronously and return data from DB
12. Attaching Thumbnails data to the photos/videos: [ThumbnailGeneratorMWs]: `ThumbnailGeneratorMWs.addThumbnailInformation`
* Checks if a photo already has a generated thumbnail image
13. Removes empty properties and circular dependencies: [GalleryMWs.ts]: `GalleryMWs.cleanUpGalleryResults`
14. Rending http body and ending HTTP call: [RenderingMWs.ts]: `RenderingMWs.renderResult`
Client side:
15. Setting `content` BehaviorSubject (rxjs) with the `ContentWrapperWithError` from the server.
16. Rendering gallery: UI is data binded to the `galleryService.content` [gallery.component.html]
You can run tests in various ways. If you use VS Code, the built-in test explorer is a good way to visualize and run the tests. You can also run tests from the command line.
- Run all tests:
`npx mocha`
- Run all tests in parallel and report with very verbose output (to debug tests that don't run):
`npx mocha --reporter spec --parallel`
- Run a specific test (here the SettingsRouter in the backend):
The MySQL / MariaDB tests needs a separate database to be running during the test. If you have docker, you can start one with the required test-settings, using the command below: