@clawchatsai/connector 0.0.42 → 0.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server.js +17 -17
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -334,14 +334,14 @@ function getActiveDb() {
|
|
|
334
334
|
return getDb(getWorkspaces().active);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
|
|
338
|
-
function getGlobalDb() {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
337
|
+
const _globalDbCache = new Map(); // keyed by resolved dbPath
|
|
338
|
+
function getGlobalDb(dataDir = DATA_DIR) {
|
|
339
|
+
const dbPath = path.join(dataDir, 'global.db');
|
|
340
|
+
if (_globalDbCache.has(dbPath)) return _globalDbCache.get(dbPath);
|
|
341
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
342
|
+
const db = new Database(dbPath);
|
|
343
|
+
db.pragma('journal_mode = WAL');
|
|
344
|
+
db.exec(`
|
|
345
345
|
CREATE TABLE IF NOT EXISTS custom_emojis (
|
|
346
346
|
name TEXT NOT NULL,
|
|
347
347
|
pack TEXT NOT NULL DEFAULT 'slackmojis',
|
|
@@ -351,7 +351,8 @@ function getGlobalDb() {
|
|
|
351
351
|
PRIMARY KEY (name, pack)
|
|
352
352
|
)
|
|
353
353
|
`);
|
|
354
|
-
|
|
354
|
+
_globalDbCache.set(dbPath, db);
|
|
355
|
+
return db;
|
|
355
356
|
}
|
|
356
357
|
|
|
357
358
|
function closeDb(workspaceName) {
|
|
@@ -363,11 +364,10 @@ function closeDb(workspaceName) {
|
|
|
363
364
|
}
|
|
364
365
|
|
|
365
366
|
function closeAllDbs() {
|
|
366
|
-
for (const [
|
|
367
|
-
db.close();
|
|
368
|
-
}
|
|
367
|
+
for (const [, db] of dbCache) db.close();
|
|
369
368
|
dbCache.clear();
|
|
370
|
-
|
|
369
|
+
for (const [, db] of _globalDbCache) db.close();
|
|
370
|
+
_globalDbCache.clear();
|
|
371
371
|
}
|
|
372
372
|
|
|
373
373
|
function _createFtsTables(db) {
|
|
@@ -4417,7 +4417,7 @@ export function createApp(config = {}) {
|
|
|
4417
4417
|
// Custom emoji listing (no auth)
|
|
4418
4418
|
if (method === 'GET' && urlPath === '/api/emoji') {
|
|
4419
4419
|
try {
|
|
4420
|
-
const db = getGlobalDb();
|
|
4420
|
+
const db = getGlobalDb(_DATA_DIR);
|
|
4421
4421
|
const rows = db.prepare('SELECT name, pack, url, mime_type FROM custom_emojis ORDER BY created_at DESC').all();
|
|
4422
4422
|
res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'public, max-age=300' });
|
|
4423
4423
|
return res.end(JSON.stringify(rows));
|
|
@@ -4461,7 +4461,7 @@ export function createApp(config = {}) {
|
|
|
4461
4461
|
if (urlLower.endsWith('.gif')) mimeType = 'image/gif';
|
|
4462
4462
|
else if (urlLower.endsWith('.webp')) mimeType = 'image/webp';
|
|
4463
4463
|
else if (urlLower.endsWith('.jpg') || urlLower.endsWith('.jpeg')) mimeType = 'image/jpeg';
|
|
4464
|
-
const db = getGlobalDb();
|
|
4464
|
+
const db = getGlobalDb(_DATA_DIR);
|
|
4465
4465
|
db.prepare('INSERT OR REPLACE INTO custom_emojis (name, pack, url, mime_type) VALUES (?, ?, ?, ?)').run(safeName, targetPack, url, mimeType);
|
|
4466
4466
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
4467
4467
|
return res.end(JSON.stringify({ name: safeName, pack: targetPack, url, mime_type: mimeType }));
|
|
@@ -4473,7 +4473,7 @@ export function createApp(config = {}) {
|
|
|
4473
4473
|
try {
|
|
4474
4474
|
const { name, pack } = await parseBody(req);
|
|
4475
4475
|
if (!name || !pack) { res.writeHead(400, { 'Content-Type': 'application/json' }); return res.end(JSON.stringify({ error: 'Missing name or pack' })); }
|
|
4476
|
-
const db = getGlobalDb();
|
|
4476
|
+
const db = getGlobalDb(_DATA_DIR);
|
|
4477
4477
|
db.prepare('DELETE FROM custom_emojis WHERE name = ? AND pack = ?').run(name, pack);
|
|
4478
4478
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
4479
4479
|
return res.end(JSON.stringify({ ok: true }));
|
|
@@ -4630,7 +4630,7 @@ if (isDirectRun) {
|
|
|
4630
4630
|
app.gatewayClient.connect();
|
|
4631
4631
|
|
|
4632
4632
|
// Initialize global DB (custom emojis, etc.)
|
|
4633
|
-
getGlobalDb();
|
|
4633
|
+
getGlobalDb(_DATA_DIR);
|
|
4634
4634
|
});
|
|
4635
4635
|
|
|
4636
4636
|
// Graceful shutdown
|