a cache for slack profile pictures and emojis

feat: save cache db to disk

Changed files
+7 -5
src
+1
.gitignore
···
**/*.bun
.env*
+
data/
+2 -1
README.md
···
```bash
SLACK_TOKEN=xoxb-123456789012-123456789012-123456789012-123456789012
SLACK_SIGNING_SECRET=12345678901234567890123456789012
-
PORT=3000
+
DATABASE_PATH=/path/to/db.sqlite # Optional
+
PORT=3000 # Optional
```
The slack app can be created from the [`manifest.yaml`](./manifest.yaml) in this repo. It just needs the `emoji:read` and `users:read` scopes.
+2 -2
src/cache.ts
···
/**
* Creates a new Cache instance
-
* @param dbPath Path to SQLite database file, defaults to in-memory
+
* @param dbPath Path to SQLite database file
* @param defaultExpirationHours Default cache expiration in hours
*/
-
constructor(dbPath = ":memory:", defaultExpirationHours = 24) {
+
constructor(dbPath: string, defaultExpirationHours = 24) {
this.db = new Database(dbPath);
this.defaultExpiration = defaultExpirationHours;
+2 -2
src/index.ts
···
startLazyListenerAfterAck: true,
});
-
const cache = new SlackCache();
+
const cache = new SlackCache(process.env.DATABASE_PATH ?? "./data/cachet.db");
const app = new Elysia()
.use(
···
},
},
)
-
.listen(3000);
+
.listen(process.env.PORT ?? 3000);
console.log(
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port} at ${version}`,