♻️ handle priority field

This commit is contained in:
Fred KISSIE
2026-09-17 21:44:56 +02:00
parent ec36317057
commit 85adae063b
9 changed files with 90 additions and 5 deletions
@@ -15,6 +15,7 @@ import {
redirectPathMatchTypeSchema,
redirectRewritePathSchema,
isValidMatchPath,
redirectPrioritySchema,
redirectRewritePathTypeSchema
} from "@server/routers/redirect/validation";
import { getUniqueRedirectName } from "@server/db/names";
@@ -39,6 +40,7 @@ const bodySchema = z
matchPath: redirectMatchPathSchema.optional().nullable(),
rewritePath: redirectRewritePathSchema.optional().nullable(),
rewritePathType: redirectRewritePathTypeSchema.optional().nullable(),
priority: redirectPrioritySchema.optional().nullable(),
permanent: z.boolean().optional(),
enabled: z.boolean().optional()
})
@@ -123,6 +125,7 @@ export async function createRedirect(
matchPath,
rewritePath,
rewritePathType,
priority,
permanent,
enabled
} = parsedBody.data;
@@ -195,6 +198,7 @@ export async function createRedirect(
matchPath: matchPath ?? null,
rewritePath: rewritePath ?? null,
rewritePathType: rewritePathType ?? null,
priority: priority ?? 100,
permanent: permanent ?? false,
enabled: enabled ?? true
})
+2
View File
@@ -22,6 +22,7 @@ export type GetRedirectResponse = {
matchPath: string | null;
rewritePath: string | null;
rewritePathType: "exact" | "prefix" | "regex" | "stripPrefix" | null;
priority: number | null;
permanent: boolean;
enabled: boolean;
resourceId: number | null;
@@ -46,6 +47,7 @@ const redirectColumns = {
matchPath: redirects.matchPath,
rewritePath: redirects.rewritePath,
rewritePathType: redirects.rewritePathType,
priority: redirects.priority,
permanent: redirects.permanent,
enabled: redirects.enabled,
resourceId: redirects.resourceId,
+3 -1
View File
@@ -22,6 +22,7 @@ export type ListRedirectsResponse = PaginatedResponse<{
matchPath: string | null;
rewritePath: string | null;
rewritePathType: "exact" | "prefix" | "regex" | "stripPrefix" | null;
priority: number | null;
permanent: boolean;
enabled: boolean;
resourceId: number | null;
@@ -145,6 +146,7 @@ export async function listRedirects(
matchPath: redirects.matchPath,
rewritePath: redirects.rewritePath,
rewritePathType: redirects.rewritePathType,
priority: redirects.priority,
permanent: redirects.permanent,
enabled: redirects.enabled,
resourceId: redirects.resourceId,
@@ -173,7 +175,7 @@ export async function listRedirects(
baseQuery
.limit(pageSize)
.offset(pageSize * (page - 1))
.orderBy(desc(redirects.redirectId))
.orderBy(desc(redirects.priority), desc(redirects.redirectId))
]);
return response<ListRedirectsResponse>(res, {
@@ -16,6 +16,7 @@ import {
redirectPathMatchTypeSchema,
redirectRewritePathSchema,
redirectRewritePathTypeSchema,
redirectPrioritySchema,
isValidMatchPath
} from "@server/routers/redirect/validation";
import { createCertificate } from "../certificates";
@@ -40,6 +41,7 @@ const bodySchema = z.strictObject({
matchPath: redirectMatchPathSchema.optional().nullable(),
rewritePath: redirectRewritePathSchema.optional().nullable(),
rewritePathType: redirectRewritePathTypeSchema.optional().nullable(),
priority: redirectPrioritySchema.optional(),
permanent: z.boolean().optional(),
enabled: z.boolean().optional()
});
@@ -255,6 +257,9 @@ export async function updateRedirect(
if (body.rewritePathType !== undefined) {
updateData.rewritePathType = body.rewritePathType;
}
if (body.priority !== undefined) {
updateData.priority = body.priority;
}
if (body.permanent !== undefined) {
updateData.permanent = body.permanent;
}
+3
View File
@@ -45,6 +45,9 @@ export function isValidMatchPath(
export const redirectRewritePathSchema = z.string().nonempty();
// Same range as target priorities; 100 means "let the system order it".
export const redirectPrioritySchema = z.int().min(1).max(1000);
export const redirectDestinationDomainSchema = z
.string()
.nonempty()