Skip to content

Commit

Permalink
Converted from MongoDB to storage-based database.
Browse files Browse the repository at this point in the history
- Removed MongoDB.
- Converted to storage based database that was first prototyped
in another repo.
- Separated out asset metadata for the db fixture into separate
metadata files.
- Started handling async errors in Express route handlers explicitly
to make it easier to find problems when running tests.
- Introduced an abstract for the database to make it easier to write
tests.
  • Loading branch information
ashleydavis committed Mar 26, 2024
1 parent 807655f commit db73b60
Show file tree
Hide file tree
Showing 217 changed files with 2,791 additions and 2,049 deletions.
3 changes: 3 additions & 0 deletions backend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules\\typescript\\lib"
}
19 changes: 9 additions & 10 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
"main": "build/index.js",
"scripts": {
"start": "node build/index.js",
"start:dev": "npm run clean-uploads && npm run copy-uploads && concurrently \"npm run start-db-with-fixture\" \"npm run start-with-dev-db\"",
"start:dev:nodb": "npm run clean-uploads && concurrently \"npm run start-db-empty\" \"npm run start-with-dev-db\"",
"start-db-with-fixture": "insta-mongo --db-port=7001 --rest-port=7000 --load=50-assets --fixtures=../fixtures --db=photosphere",
"start-db-empty": "insta-mongo --db-port=7001 --rest-port=7000 --fixtures=../fixtures",
"start-with-dev-db": "cross-env PORT=3000 DB_CONNECTION_STRING=mongodb://localhost:7001 ts-node-dev --respawn src/index.ts",
"start-for-e2e-tests": "npm run clean-uploads && concurrently \"npm run start-db-empty\" \"npm run start-with-dev-db\"",
"start:dev": "npm run clean-uploads && npm run copy-uploads && npm run start-watch",
"start:dev-no-uploads": "npm run clean-uploads && npm run start-watch",
"start-watch": "cross-env PORT=3000 ts-node-dev --respawn src/index.ts",
"start-for-e2e-tests": "npm run clean-uploads && npm run start:dev-no-uploads",
"build": "npm install --production=false && npm run compile",
"compile": "tsc",
"compile:watch": "tsc --watch",
Expand All @@ -28,23 +26,24 @@
"@types/express": "^4.17.16",
"@types/fs-extra": "^11.0.1",
"@types/jest": "^29.4.0",
"@types/node": "^18.11.18",
"@types/node": "^18.19.15",
"@types/uuid": "^9.0.8",
"axios": "^0.27.2",
"concurrently": "^7.2.2",
"cross-env": "^7.0.3",
"fs-extra": "^11.1.0",
"insta-mongo": "^0.0.6",
"jest": "^29.4.1",
"nodemon": "^2.0.16",
"supertest": "^6.3.3",
"ts-jest": "^29.0.5",
"ts-node-dev": "^2.0.0",
"typescript": "^4.9.4"
"typescript": "^5.3.3"
},
"dependencies": {
"aws-sdk": "^2.1313.0",
"cors": "^2.8.5",
"dayjs": "^1.11.7",
"express": "^5.0.0-beta.1",
"mongodb": "^4.7.0"
"uuid": "^9.0.1"
}
}
14 changes: 3 additions & 11 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MongoClient } from "mongodb";
import { createServer } from "./server";
import { CloudStorage } from "./services/cloud-storage";
import { Database } from "./services/database";
import { FileStorage } from "./services/file-storage";

async function main() {
Expand All @@ -12,19 +12,11 @@ async function main() {
throw new Error(`Set environment variable PORT.`);
}

const DB_CONNECTION_STRING = process.env.DB_CONNECTION_STRING;
if (DB_CONNECTION_STRING === undefined) {
throw new Error(`Set environment variable DB_CONNECTION_STRING.`);
}

const client = new MongoClient(DB_CONNECTION_STRING);
await client.connect();

const db = client.db(dbName);
const storage = process.env.NODE_ENV === "production"
? new CloudStorage()
: new FileStorage();
const app = await createServer(db, () => new Date(Date.now()), storage);
const database = new Database(storage);
const app = await createServer(() => new Date(Date.now()), database, storage);

app.listen(PORT, () => {
console.log(`Photosphere listening on port ${PORT}`);
Expand Down
13 changes: 5 additions & 8 deletions backend/src/lib/asset.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { ObjectId } from "mongodb";

//
// Represents an asset that has been uploaded to the backend.
//

//
// Full asset data.
//
export interface IAsset {

//
// Unique ID of the asset in the database.
//
_id: ObjectId;
_id: string;

//
// The original name of the asset before it was uploaded.
Expand Down Expand Up @@ -84,9 +86,4 @@ export interface IAsset {
// Description of the asset, once the user has set it.
//
description?: string;

//
// Text to search for the asset.
//
searchText?: string;
}
Loading

0 comments on commit db73b60

Please sign in to comment.