mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-07-15 21:03:47 +00:00
Merge pull request #778 from ZacharyZcR/feat/snippet-host-filter
feat: add host filter for snippets
This commit is contained in:
@@ -782,6 +782,7 @@ const migrateSchema = () => {
|
|||||||
|
|
||||||
addColumnIfNotExists("snippets", "folder", "TEXT");
|
addColumnIfNotExists("snippets", "folder", "TEXT");
|
||||||
addColumnIfNotExists("snippets", "order", "INTEGER NOT NULL DEFAULT 0");
|
addColumnIfNotExists("snippets", "order", "INTEGER NOT NULL DEFAULT 0");
|
||||||
|
addColumnIfNotExists("snippets", "host_filter", "TEXT");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sqlite
|
sqlite
|
||||||
|
|||||||
@@ -302,6 +302,7 @@ export const snippets = sqliteTable("snippets", {
|
|||||||
updatedAt: text("updated_at")
|
updatedAt: text("updated_at")
|
||||||
.notNull()
|
.notNull()
|
||||||
.default(sql`CURRENT_TIMESTAMP`),
|
.default(sql`CURRENT_TIMESTAMP`),
|
||||||
|
hostFilter: text("host_filter"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const snippetFolders = sqliteTable("snippet_folders", {
|
export const snippetFolders = sqliteTable("snippet_folders", {
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ async function getAccessibleSnippet(snippetId: number, userId: string) {
|
|||||||
order: snippets.order,
|
order: snippets.order,
|
||||||
createdAt: snippets.createdAt,
|
createdAt: snippets.createdAt,
|
||||||
updatedAt: snippets.updatedAt,
|
updatedAt: snippets.updatedAt,
|
||||||
|
hostFilter: snippets.hostFilter,
|
||||||
})
|
})
|
||||||
.from(snippetAccess)
|
.from(snippetAccess)
|
||||||
.innerJoin(snippets, eq(snippetAccess.snippetId, snippets.id))
|
.innerJoin(snippets, eq(snippetAccess.snippetId, snippets.id))
|
||||||
@@ -1104,7 +1105,7 @@ router.post(
|
|||||||
requireDataAccess,
|
requireDataAccess,
|
||||||
async (req: Request, res: Response) => {
|
async (req: Request, res: Response) => {
|
||||||
const userId = (req as AuthenticatedRequest).userId;
|
const userId = (req as AuthenticatedRequest).userId;
|
||||||
const { name, content, description, folder, order } = req.body;
|
const { name, content, description, folder, order, hostFilter } = req.body;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!isNonEmptyString(userId) ||
|
!isNonEmptyString(userId) ||
|
||||||
@@ -1146,6 +1147,7 @@ router.post(
|
|||||||
description: description?.trim() || null,
|
description: description?.trim() || null,
|
||||||
folder: folder?.trim() || null,
|
folder: folder?.trim() || null,
|
||||||
order: snippetOrder,
|
order: snippetOrder,
|
||||||
|
hostFilter: hostFilter ? JSON.stringify(hostFilter) : null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await db.insert(snippets).values(insertData).returning();
|
const result = await db.insert(snippets).values(insertData).returning();
|
||||||
@@ -1238,6 +1240,7 @@ router.put(
|
|||||||
description: string | null;
|
description: string | null;
|
||||||
folder: string | null;
|
folder: string | null;
|
||||||
order: number;
|
order: number;
|
||||||
|
hostFilter: string | null;
|
||||||
}> = {
|
}> = {
|
||||||
updatedAt: sql`CURRENT_TIMESTAMP`,
|
updatedAt: sql`CURRENT_TIMESTAMP`,
|
||||||
};
|
};
|
||||||
@@ -1251,6 +1254,10 @@ router.put(
|
|||||||
if (updateData.folder !== undefined)
|
if (updateData.folder !== undefined)
|
||||||
updateFields.folder = updateData.folder?.trim() || null;
|
updateFields.folder = updateData.folder?.trim() || null;
|
||||||
if (updateData.order !== undefined) updateFields.order = updateData.order;
|
if (updateData.order !== undefined) updateFields.order = updateData.order;
|
||||||
|
if (updateData.hostFilter !== undefined)
|
||||||
|
updateFields.hostFilter = updateData.hostFilter
|
||||||
|
? JSON.stringify(updateData.hostFilter)
|
||||||
|
: null;
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(snippets)
|
.update(snippets)
|
||||||
|
|||||||
Reference in New Issue
Block a user