feat: item color map, fix regex matching, fix sort order, fix resize handle
This commit is contained in:
@@ -28,12 +28,15 @@ export const GET = withAuth(async (req: NextRequest) => {
|
||||
if (itemsWhitelist.length > 0) {
|
||||
if (useRegex) {
|
||||
const localeMap = getServerLocaleMap();
|
||||
// Each pattern is expanded to matching keys (tested against key AND localized name).
|
||||
// Union all patterns — if a pattern matches nothing, it contributes no keys.
|
||||
const keys = [...new Set(itemsWhitelist.flatMap(p => matchKeys(p, localeMap)))];
|
||||
if (keys.length === 0) return NextResponse.json([]);
|
||||
conditions.push(`item_key = ANY($${i++})`);
|
||||
values.push(keys);
|
||||
const localeKeys = [...new Set(itemsWhitelist.flatMap(p => matchKeys(p, localeMap)))];
|
||||
const sqlPattern = itemsWhitelist.map(p => `(${p})`).join('|');
|
||||
const orConds = [`item_key ~* $${i++}`];
|
||||
values.push(sqlPattern);
|
||||
if (localeKeys.length > 0) {
|
||||
orConds.push(`item_key = ANY($${i++})`);
|
||||
values.push(localeKeys);
|
||||
}
|
||||
conditions.push(`(${orConds.join(' OR ')})`);
|
||||
} else {
|
||||
conditions.push(`item_key = ANY($${i++})`);
|
||||
values.push(itemsWhitelist);
|
||||
@@ -43,12 +46,15 @@ export const GET = withAuth(async (req: NextRequest) => {
|
||||
if (itemsBlacklist.length > 0) {
|
||||
if (useRegex) {
|
||||
const localeMap = getServerLocaleMap();
|
||||
const keys = [...new Set(itemsBlacklist.flatMap(p => matchKeys(p, localeMap)))];
|
||||
// If blacklist pattern matches nothing, nothing to exclude — skip condition
|
||||
if (keys.length > 0) {
|
||||
conditions.push(`item_key != ALL($${i++})`);
|
||||
values.push(keys);
|
||||
const localeKeys = [...new Set(itemsBlacklist.flatMap(p => matchKeys(p, localeMap)))];
|
||||
const sqlPattern = itemsBlacklist.map(p => `(${p})`).join('|');
|
||||
const andConds = [`item_key !~* $${i++}`];
|
||||
values.push(sqlPattern);
|
||||
if (localeKeys.length > 0) {
|
||||
andConds.push(`item_key != ALL($${i++})`);
|
||||
values.push(localeKeys);
|
||||
}
|
||||
conditions.push(`(${andConds.join(' AND ')})`);
|
||||
} else {
|
||||
conditions.push(`item_key != ALL($${i++})`);
|
||||
values.push(itemsBlacklist);
|
||||
@@ -78,10 +84,15 @@ export const GET = withAuth(async (req: NextRequest) => {
|
||||
if (itemsWhitelist.length > 0) {
|
||||
if (useRegex) {
|
||||
const localeMap = getServerLocaleMap();
|
||||
const keys = [...new Set(itemsWhitelist.flatMap(p => matchKeys(p, localeMap)))];
|
||||
if (keys.length === 0) return NextResponse.json([]);
|
||||
baseConditions.push(`item_key = ANY($${j++})`);
|
||||
baseValues.push(keys);
|
||||
const localeKeys = [...new Set(itemsWhitelist.flatMap(p => matchKeys(p, localeMap)))];
|
||||
const sqlPattern = itemsWhitelist.map(p => `(${p})`).join('|');
|
||||
const orConds = [`item_key ~* $${j++}`];
|
||||
baseValues.push(sqlPattern);
|
||||
if (localeKeys.length > 0) {
|
||||
orConds.push(`item_key = ANY($${j++})`);
|
||||
baseValues.push(localeKeys);
|
||||
}
|
||||
baseConditions.push(`(${orConds.join(' OR ')})`);
|
||||
} else {
|
||||
baseConditions.push(`item_key = ANY($${j++})`);
|
||||
baseValues.push(itemsWhitelist);
|
||||
@@ -90,11 +101,15 @@ export const GET = withAuth(async (req: NextRequest) => {
|
||||
if (itemsBlacklist.length > 0) {
|
||||
if (useRegex) {
|
||||
const localeMap = getServerLocaleMap();
|
||||
const keys = [...new Set(itemsBlacklist.flatMap(p => matchKeys(p, localeMap)))];
|
||||
if (keys.length > 0) {
|
||||
baseConditions.push(`item_key != ALL($${j++})`);
|
||||
baseValues.push(keys);
|
||||
const localeKeys = [...new Set(itemsBlacklist.flatMap(p => matchKeys(p, localeMap)))];
|
||||
const sqlPattern = itemsBlacklist.map(p => `(${p})`).join('|');
|
||||
const andConds = [`item_key !~* $${j++}`];
|
||||
baseValues.push(sqlPattern);
|
||||
if (localeKeys.length > 0) {
|
||||
andConds.push(`item_key != ALL($${j++})`);
|
||||
baseValues.push(localeKeys);
|
||||
}
|
||||
baseConditions.push(`(${andConds.join(' AND ')})`);
|
||||
} else {
|
||||
baseConditions.push(`item_key != ALL($${j++})`);
|
||||
baseValues.push(itemsBlacklist);
|
||||
|
||||
Reference in New Issue
Block a user