mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 06:35:24 +00:00
30 lines
757 B
TypeScript
30 lines
757 B
TypeScript
import type { SnippetReorderUpdate } from "./repository.js";
|
|
|
|
type SnippetReorderRequestBody = {
|
|
snippets?: unknown;
|
|
updates?: unknown;
|
|
};
|
|
|
|
export function extractSnippetReorderUpdates(
|
|
body: unknown,
|
|
): SnippetReorderUpdate[] | null {
|
|
if (!body || typeof body !== "object") {
|
|
return null;
|
|
}
|
|
|
|
const payload = body as SnippetReorderRequestBody;
|
|
// Keep accepting the legacy `updates` key so older clients do not break
|
|
// while the web and desktop helpers converge on `snippets`.
|
|
const snippetsUpdates = Array.isArray(payload.snippets)
|
|
? payload.snippets
|
|
: Array.isArray(payload.updates)
|
|
? payload.updates
|
|
: null;
|
|
|
|
if (!snippetsUpdates) {
|
|
return null;
|
|
}
|
|
|
|
return snippetsUpdates as SnippetReorderUpdate[];
|
|
}
|