Fix database old config editor paths

This commit is contained in:
LukeGus
2025-08-17 16:01:12 -05:00
parent 880907cc93
commit cf945e3665
3 changed files with 54 additions and 54 deletions

View File

@@ -42,13 +42,13 @@ export const sshData = sqliteTable('ssh_data', {
enableTerminal: integer('enable_terminal', {mode: 'boolean'}).notNull().default(true), enableTerminal: integer('enable_terminal', {mode: 'boolean'}).notNull().default(true),
enableTunnel: integer('enable_tunnel', {mode: 'boolean'}).notNull().default(true), enableTunnel: integer('enable_tunnel', {mode: 'boolean'}).notNull().default(true),
tunnelConnections: text('tunnel_connections'), tunnelConnections: text('tunnel_connections'),
enableConfigEditor: integer('enable_file_manager', {mode: 'boolean'}).notNull().default(true), enableFileManager: integer('enable_file_manager', {mode: 'boolean'}).notNull().default(true),
defaultPath: text('default_path'), defaultPath: text('default_path'),
createdAt: text('created_at').notNull().default(sql`CURRENT_TIMESTAMP`), createdAt: text('created_at').notNull().default(sql`CURRENT_TIMESTAMP`),
updatedAt: text('updated_at').notNull().default(sql`CURRENT_TIMESTAMP`), updatedAt: text('updated_at').notNull().default(sql`CURRENT_TIMESTAMP`),
}); });
export const configEditorRecent = sqliteTable('file_manager_recent', { export const fileManagerRecent = sqliteTable('file_manager_recent', {
id: integer('id').primaryKey({autoIncrement: true}), id: integer('id').primaryKey({autoIncrement: true}),
userId: text('user_id').notNull().references(() => users.id), userId: text('user_id').notNull().references(() => users.id),
hostId: integer('host_id').notNull().references(() => sshData.id), hostId: integer('host_id').notNull().references(() => sshData.id),
@@ -57,7 +57,7 @@ export const configEditorRecent = sqliteTable('file_manager_recent', {
lastOpened: text('last_opened').notNull().default(sql`CURRENT_TIMESTAMP`), lastOpened: text('last_opened').notNull().default(sql`CURRENT_TIMESTAMP`),
}); });
export const configEditorPinned = sqliteTable('file_manager_pinned', { export const fileManagerPinned = sqliteTable('file_manager_pinned', {
id: integer('id').primaryKey({autoIncrement: true}), id: integer('id').primaryKey({autoIncrement: true}),
userId: text('user_id').notNull().references(() => users.id), userId: text('user_id').notNull().references(() => users.id),
hostId: integer('host_id').notNull().references(() => sshData.id), hostId: integer('host_id').notNull().references(() => sshData.id),
@@ -66,7 +66,7 @@ export const configEditorPinned = sqliteTable('file_manager_pinned', {
pinnedAt: text('pinned_at').notNull().default(sql`CURRENT_TIMESTAMP`), pinnedAt: text('pinned_at').notNull().default(sql`CURRENT_TIMESTAMP`),
}); });
export const configEditorShortcuts = sqliteTable('file_manager_shortcuts', { export const fileManagerShortcuts = sqliteTable('file_manager_shortcuts', {
id: integer('id').primaryKey({autoIncrement: true}), id: integer('id').primaryKey({autoIncrement: true}),
userId: text('user_id').notNull().references(() => users.id), userId: text('user_id').notNull().references(() => users.id),
hostId: integer('host_id').notNull().references(() => sshData.id), hostId: integer('host_id').notNull().references(() => sshData.id),

View File

@@ -1,6 +1,6 @@
import express from 'express'; import express from 'express';
import {db} from '../db/index.js'; import {db} from '../db/index.js';
import {sshData, configEditorRecent, configEditorPinned, configEditorShortcuts} from '../db/schema.js'; import {sshData, fileManagerRecent, fileManagerPinned, fileManagerShortcuts} from '../db/schema.js';
import {eq, and, desc} from 'drizzle-orm'; import {eq, and, desc} from 'drizzle-orm';
import chalk from 'chalk'; import chalk from 'chalk';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
@@ -101,7 +101,7 @@ router.get('/db/host/internal', async (req: Request, res: Response) => {
enableTerminal: !!row.enableTerminal, enableTerminal: !!row.enableTerminal,
enableTunnel: !!row.enableTunnel, enableTunnel: !!row.enableTunnel,
tunnelConnections: row.tunnelConnections ? JSON.parse(row.tunnelConnections) : [], tunnelConnections: row.tunnelConnections ? JSON.parse(row.tunnelConnections) : [],
enableConfigEditor: !!row.enableConfigEditor, enableFileManager: !!row.enableFileManager,
})); }));
res.json(result); res.json(result);
} catch (err) { } catch (err) {
@@ -150,7 +150,7 @@ router.post('/db/host', authenticateJWT, upload.single('key'), async (req: Reque
pin, pin,
enableTerminal, enableTerminal,
enableTunnel, enableTunnel,
enableConfigEditor, enableFileManager,
defaultPath, defaultPath,
tunnelConnections tunnelConnections
} = hostData; } = hostData;
@@ -173,7 +173,7 @@ router.post('/db/host', authenticateJWT, upload.single('key'), async (req: Reque
enableTerminal: !!enableTerminal ? 1 : 0, enableTerminal: !!enableTerminal ? 1 : 0,
enableTunnel: !!enableTunnel ? 1 : 0, enableTunnel: !!enableTunnel ? 1 : 0,
tunnelConnections: Array.isArray(tunnelConnections) ? JSON.stringify(tunnelConnections) : null, tunnelConnections: Array.isArray(tunnelConnections) ? JSON.stringify(tunnelConnections) : null,
enableConfigEditor: !!enableConfigEditor ? 1 : 0, enableFileManager: !!enableFileManager ? 1 : 0,
defaultPath: defaultPath || null, defaultPath: defaultPath || null,
}; };
@@ -238,7 +238,7 @@ router.put('/db/host/:id', authenticateJWT, upload.single('key'), async (req: Re
pin, pin,
enableTerminal, enableTerminal,
enableTunnel, enableTunnel,
enableConfigEditor, enableFileManager,
defaultPath, defaultPath,
tunnelConnections tunnelConnections
} = hostData; } = hostData;
@@ -261,7 +261,7 @@ router.put('/db/host/:id', authenticateJWT, upload.single('key'), async (req: Re
enableTerminal: !!enableTerminal ? 1 : 0, enableTerminal: !!enableTerminal ? 1 : 0,
enableTunnel: !!enableTunnel ? 1 : 0, enableTunnel: !!enableTunnel ? 1 : 0,
tunnelConnections: Array.isArray(tunnelConnections) ? JSON.stringify(tunnelConnections) : null, tunnelConnections: Array.isArray(tunnelConnections) ? JSON.stringify(tunnelConnections) : null,
enableConfigEditor: !!enableConfigEditor ? 1 : 0, enableFileManager: !!enableFileManager ? 1 : 0,
defaultPath: defaultPath || null, defaultPath: defaultPath || null,
}; };
@@ -308,7 +308,7 @@ router.get('/db/host', authenticateJWT, async (req: Request, res: Response) => {
enableTerminal: !!row.enableTerminal, enableTerminal: !!row.enableTerminal,
enableTunnel: !!row.enableTunnel, enableTunnel: !!row.enableTunnel,
tunnelConnections: row.tunnelConnections ? JSON.parse(row.tunnelConnections) : [], tunnelConnections: row.tunnelConnections ? JSON.parse(row.tunnelConnections) : [],
enableConfigEditor: !!row.enableConfigEditor, enableFileManager: !!row.enableFileManager,
})); }));
res.json(result); res.json(result);
} catch (err) { } catch (err) {
@@ -346,7 +346,7 @@ router.get('/db/host/:id', authenticateJWT, async (req: Request, res: Response)
enableTerminal: !!host.enableTerminal, enableTerminal: !!host.enableTerminal,
enableTunnel: !!host.enableTunnel, enableTunnel: !!host.enableTunnel,
tunnelConnections: host.tunnelConnections ? JSON.parse(host.tunnelConnections) : [], tunnelConnections: host.tunnelConnections ? JSON.parse(host.tunnelConnections) : [],
enableConfigEditor: !!host.enableConfigEditor, enableFileManager: !!host.enableFileManager,
}; };
res.json(result); res.json(result);
@@ -424,12 +424,12 @@ router.get('/file_manager/recent', authenticateJWT, async (req: Request, res: Re
try { try {
const recentFiles = await db const recentFiles = await db
.select() .select()
.from(configEditorRecent) .from(fileManagerRecent)
.where(and( .where(and(
eq(configEditorRecent.userId, userId), eq(fileManagerRecent.userId, userId),
eq(configEditorRecent.hostId, hostId) eq(fileManagerRecent.hostId, hostId)
)) ))
.orderBy(desc(configEditorRecent.lastOpened)); .orderBy(desc(fileManagerRecent.lastOpened));
res.json(recentFiles); res.json(recentFiles);
} catch (err) { } catch (err) {
logger.error('Failed to fetch recent files', err); logger.error('Failed to fetch recent files', err);
@@ -448,23 +448,23 @@ router.post('/file_manager/recent', authenticateJWT, async (req: Request, res: R
} }
try { try {
const conditions = [ const conditions = [
eq(configEditorRecent.userId, userId), eq(fileManagerRecent.userId, userId),
eq(configEditorRecent.path, path), eq(fileManagerRecent.path, path),
eq(configEditorRecent.hostId, hostId) eq(fileManagerRecent.hostId, hostId)
]; ];
const existing = await db const existing = await db
.select() .select()
.from(configEditorRecent) .from(fileManagerRecent)
.where(and(...conditions)); .where(and(...conditions));
if (existing.length > 0) { if (existing.length > 0) {
await db await db
.update(configEditorRecent) .update(fileManagerRecent)
.set({lastOpened: new Date().toISOString()}) .set({lastOpened: new Date().toISOString()})
.where(and(...conditions)); .where(and(...conditions));
} else { } else {
await db.insert(configEditorRecent).values({ await db.insert(fileManagerRecent).values({
userId, userId,
hostId, hostId,
name, name,
@@ -490,13 +490,13 @@ router.delete('/file_manager/recent', authenticateJWT, async (req: Request, res:
} }
try { try {
const conditions = [ const conditions = [
eq(configEditorRecent.userId, userId), eq(fileManagerRecent.userId, userId),
eq(configEditorRecent.path, path), eq(fileManagerRecent.path, path),
eq(configEditorRecent.hostId, hostId) eq(fileManagerRecent.hostId, hostId)
]; ];
const result = await db const result = await db
.delete(configEditorRecent) .delete(fileManagerRecent)
.where(and(...conditions)); .where(and(...conditions));
res.json({message: 'File removed from recent'}); res.json({message: 'File removed from recent'});
} catch (err) { } catch (err) {
@@ -524,12 +524,12 @@ router.get('/file_manager/pinned', authenticateJWT, async (req: Request, res: Re
try { try {
const pinnedFiles = await db const pinnedFiles = await db
.select() .select()
.from(configEditorPinned) .from(fileManagerPinned)
.where(and( .where(and(
eq(configEditorPinned.userId, userId), eq(fileManagerPinned.userId, userId),
eq(configEditorPinned.hostId, hostId) eq(fileManagerPinned.hostId, hostId)
)) ))
.orderBy(configEditorPinned.pinnedAt); .orderBy(fileManagerPinned.pinnedAt);
res.json(pinnedFiles); res.json(pinnedFiles);
} catch (err) { } catch (err) {
logger.error('Failed to fetch pinned files', err); logger.error('Failed to fetch pinned files', err);
@@ -548,18 +548,18 @@ router.post('/file_manager/pinned', authenticateJWT, async (req: Request, res: R
} }
try { try {
const conditions = [ const conditions = [
eq(configEditorPinned.userId, userId), eq(fileManagerPinned.userId, userId),
eq(configEditorPinned.path, path), eq(fileManagerPinned.path, path),
eq(configEditorPinned.hostId, hostId) eq(fileManagerPinned.hostId, hostId)
]; ];
const existing = await db const existing = await db
.select() .select()
.from(configEditorPinned) .from(fileManagerPinned)
.where(and(...conditions)); .where(and(...conditions));
if (existing.length === 0) { if (existing.length === 0) {
await db.insert(configEditorPinned).values({ await db.insert(fileManagerPinned).values({
userId, userId,
hostId, hostId,
name, name,
@@ -585,13 +585,13 @@ router.delete('/file_manager/pinned', authenticateJWT, async (req: Request, res:
} }
try { try {
const conditions = [ const conditions = [
eq(configEditorPinned.userId, userId), eq(fileManagerPinned.userId, userId),
eq(configEditorPinned.path, path), eq(fileManagerPinned.path, path),
eq(configEditorPinned.hostId, hostId) eq(fileManagerPinned.hostId, hostId)
]; ];
const result = await db const result = await db
.delete(configEditorPinned) .delete(fileManagerPinned)
.where(and(...conditions)); .where(and(...conditions));
res.json({message: 'File unpinned successfully'}); res.json({message: 'File unpinned successfully'});
} catch (err) { } catch (err) {
@@ -617,12 +617,12 @@ router.get('/file_manager/shortcuts', authenticateJWT, async (req: Request, res:
try { try {
const shortcuts = await db const shortcuts = await db
.select() .select()
.from(configEditorShortcuts) .from(fileManagerShortcuts)
.where(and( .where(and(
eq(configEditorShortcuts.userId, userId), eq(fileManagerShortcuts.userId, userId),
eq(configEditorShortcuts.hostId, hostId) eq(fileManagerShortcuts.hostId, hostId)
)) ))
.orderBy(configEditorShortcuts.createdAt); .orderBy(fileManagerShortcuts.createdAt);
res.json(shortcuts); res.json(shortcuts);
} catch (err) { } catch (err) {
logger.error('Failed to fetch shortcuts', err); logger.error('Failed to fetch shortcuts', err);
@@ -640,18 +640,18 @@ router.post('/file_manager/shortcuts', authenticateJWT, async (req: Request, res
} }
try { try {
const conditions = [ const conditions = [
eq(configEditorShortcuts.userId, userId), eq(fileManagerShortcuts.userId, userId),
eq(configEditorShortcuts.path, path), eq(fileManagerShortcuts.path, path),
eq(configEditorShortcuts.hostId, hostId) eq(fileManagerShortcuts.hostId, hostId)
]; ];
const existing = await db const existing = await db
.select() .select()
.from(configEditorShortcuts) .from(fileManagerShortcuts)
.where(and(...conditions)); .where(and(...conditions));
if (existing.length === 0) { if (existing.length === 0) {
await db.insert(configEditorShortcuts).values({ await db.insert(fileManagerShortcuts).values({
userId, userId,
hostId, hostId,
name, name,
@@ -676,13 +676,13 @@ router.delete('/file_manager/shortcuts', authenticateJWT, async (req: Request, r
} }
try { try {
const conditions = [ const conditions = [
eq(configEditorShortcuts.userId, userId), eq(fileManagerShortcuts.userId, userId),
eq(configEditorShortcuts.path, path), eq(fileManagerShortcuts.path, path),
eq(configEditorShortcuts.hostId, hostId) eq(fileManagerShortcuts.hostId, hostId)
]; ];
const result = await db const result = await db
.delete(configEditorShortcuts) .delete(fileManagerShortcuts)
.where(and(...conditions)); .where(and(...conditions));
res.json({message: 'Shortcut removed successfully'}); res.json({message: 'Shortcut removed successfully'});
} catch (err) { } catch (err) {
@@ -765,7 +765,7 @@ router.post('/bulk-import', authenticateJWT, async (req: Request, res: Response)
enableTerminal: !!hostData.enableTerminal ? 1 : 0, enableTerminal: !!hostData.enableTerminal ? 1 : 0,
enableTunnel: !!hostData.enableTunnel ? 1 : 0, enableTunnel: !!hostData.enableTunnel ? 1 : 0,
tunnelConnections: Array.isArray(hostData.tunnelConnections) ? JSON.stringify(hostData.tunnelConnections) : null, tunnelConnections: Array.isArray(hostData.tunnelConnections) ? JSON.stringify(hostData.tunnelConnections) : null,
enableConfigEditor: !!hostData.enableConfigEditor ? 1 : 0, enableFileManager: !!hostData.enableFileManager ? 1 : 0,
defaultPath: hostData.defaultPath || null, defaultPath: hostData.defaultPath || null,
}; };

View File

@@ -4,7 +4,7 @@
import './database/database.js' import './database/database.js'
import './ssh/terminal.js'; import './ssh/terminal.js';
import './ssh/tunnel.js'; import './ssh/tunnel.js';
import './ssh/file-manager.ts'; import './ssh/file-manager.js';
import './ssh/server-stats.js'; import './ssh/server-stats.js';
import chalk from 'chalk'; import chalk from 'chalk';