mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-11-22 13:08:14 +00:00
Compare commits
3 Commits
f141d4719c
...
cf3cc4e638
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf3cc4e638 | ||
|
|
46b9e41100 | ||
|
|
02adafbd4b |
@@ -2,9 +2,12 @@ import Database from 'better-sqlite3';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
const db = new Database(path.join(process.cwd(), 'data', 'db.sqlite'));
|
const DATA_DIR = process.env.DATA_DIR || process.cwd();
|
||||||
|
const dbPath = path.join(DATA_DIR, './data/db.sqlite');
|
||||||
|
|
||||||
const migrationsFolder = path.join(process.cwd(), 'drizzle');
|
const db = new Database(dbPath);
|
||||||
|
|
||||||
|
const migrationsFolder = path.join(DATA_DIR, 'drizzle');
|
||||||
|
|
||||||
db.exec(`
|
db.exec(`
|
||||||
CREATE TABLE IF NOT EXISTS ran_migrations (
|
CREATE TABLE IF NOT EXISTS ran_migrations (
|
||||||
@@ -54,7 +57,7 @@ fs.readdirSync(migrationsFolder)
|
|||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
type TEXT NOT NULL,
|
type TEXT NOT NULL,
|
||||||
chatId TEXT NOT NULL,
|
chatId TEXT NOT NULL,
|
||||||
createdAt TEXT NOT NULL,
|
createdAt TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
messageId TEXT NOT NULL,
|
messageId TEXT NOT NULL,
|
||||||
content TEXT,
|
content TEXT,
|
||||||
sources TEXT DEFAULT '[]'
|
sources TEXT DEFAULT '[]'
|
||||||
@@ -67,8 +70,10 @@ fs.readdirSync(migrationsFolder)
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
messages.forEach((msg: any) => {
|
messages.forEach((msg: any) => {
|
||||||
if (msg.type === 'user') {
|
while (typeof msg.metadata === 'string') {
|
||||||
msg.metadata = JSON.parse(msg.metadata || '{}');
|
msg.metadata = JSON.parse(msg.metadata || '{}');
|
||||||
|
}
|
||||||
|
if (msg.type === 'user') {
|
||||||
insertMessage.run(
|
insertMessage.run(
|
||||||
'user',
|
'user',
|
||||||
msg.chatId,
|
msg.chatId,
|
||||||
@@ -78,7 +83,6 @@ fs.readdirSync(migrationsFolder)
|
|||||||
'[]',
|
'[]',
|
||||||
);
|
);
|
||||||
} else if (msg.type === 'assistant') {
|
} else if (msg.type === 'assistant') {
|
||||||
msg.metadata = JSON.parse(msg.metadata || '{}');
|
|
||||||
insertMessage.run(
|
insertMessage.run(
|
||||||
'assistant',
|
'assistant',
|
||||||
msg.chatId,
|
msg.chatId,
|
||||||
|
|||||||
Reference in New Issue
Block a user