Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: add draggable channel tags (migration + reorder API)

Gus271d5beada61
diff --git a/src/web/migrations/0029_channel_position.sql b/src/web/migrations/0029_channel_position.sql
new file mode 100644
index 000000000..424e10ca1
--- /dev/null
+++ b/src/web/migrations/0029_channel_position.sql
@@ -0,0 +1,7 @@
+ALTER TABLE channel ADD COLUMN position INTEGER NOT NULL DEFAULT 0;
+
+UPDATE channel SET position = (
+ SELECT COUNT(*) FROM channel AS c2
+ WHERE c2.workspace_id = channel.workspace_id
+ AND c2.created_at < channel.created_at
+);
diff --git a/src/web/src/app/api/channels/reorder/route.ts b/src/web/src/app/api/channels/reorder/route.ts
new file mode 100644
index 000000000..f4f105d1e
--- /dev/null
+++ b/src/web/src/app/api/channels/reorder/route.ts
@@ -0,0 +1,40 @@
+import { NextRequest } from "next/server";
+import { getCloudflareContext } from "@opennextjs/cloudflare";
+import { queries } from "@alook/shared";
+import { getDb } from "@/lib/db";
+import { withAuth } from "@/lib/middleware/auth";
+import { withWorkspaceMember } from "@/lib/middleware/workspace";
+import { writeError } from "@/lib/middleware/helpers";
+
+export const PUT = withAuth(async (req: NextRequest, ctx) => {
+ const ws = await withWorkspaceMember(req, ctx);
+ if (ws instanceof Response) return ws;
+
+ let raw: { ordered_channel_ids?: unknown };
+ try {
+ raw = await req.json();
+ } catch {
+ return writeError("invalid request body", 400);
+ }
+
+ const ids = raw.ordered_channel_ids;
+ if (!Array.isArray(ids) || ids.length === 0 || !ids.every((id) => typeof id === "string" && id.length > 0)) {
+ return writeError("ordered_channel_ids must be a non-empty array of strings", 400);
+ }
+
+ if (ids.includes("ch_default")) {
+ return writeError("cannot reorder the default channel", 400);
+ }
+
+ const { env } = getCloudflareContext();
+ const db = getDb((env as Env).DB);
+
+ const existing = await queries.channel.listChannels(db, ws.workspaceId);
+ const existingIds = new Set(existing.map((c) => c.id));
+ for (const id of ids) {
+ if (!existingIds.has(id)) return writeError(`Channel ${id} not found`, 400);
+ }
+
+ await queries.channel.reorderChannels(db, ws.workspaceId, ids);
+ return new Response(null, { status: 204 });
+});