refactor(limits): server limits in one file, own texts for unknown errors
Build, Test & Push Frontend / quality-check (push) Successful in 19s
Build, Test & Push Frontend / docker (push) Successful in 27s

This commit is contained in:
lobo committed 2026-09-29 14:48:28 +02:00
1 parent f605917874
commit 24a98062ee
18 files changed
+84 -49

No files matched your search

+1 -3
View File
@@ -1,7 +1,5 @@
import {apiFetch} from './api.js';
export const GAME_STATUSES = ['BACKLOG', 'PLAYING', 'FINISHED', 'COMPLETED', 'DROPPED'];
export const GAME_PRIORITIES = ['HIGH', 'MEDIUM', 'LOW'];
import {GAME_STATUSES} from './limits.js';
// Radix Select has no empty value, so "no priority" needs its own value in the form.
export const NO_PRIORITY = 'NONE';
+5 -9
View File
@@ -1,15 +1,11 @@
import {apiFetch} from './api.js';
import {parseStatus} from './backlog.js';
import {hoursToMinutes, MAX_PLATFORM_LENGTH} from './manualGames.js';
import {MAX_IMPORT_TITLE_LENGTH, MAX_PLATFORM_LENGTH, MAX_PLAYTIME_MINUTES} from './limits.js';
import {hoursToMinutes} from './manualGames.js';
const IMPORTS_URL = () => `${import.meta.env.VITE_CORE_API_URL}/api/library/imports`;
const JSON_HEADERS = {'Content-Type': 'application/json'};
// Core's limits: lines per import, title length of the game search, playtime.
export const MAX_IMPORT_ROWS = 1000;
const MAX_TITLE = 100;
const MAX_MINUTES = 6_000_000;
// The calls return the raw response; the caller handles the status.
export const createImport = (source, rows) =>
apiFetch(IMPORTS_URL(), {method: 'POST', headers: JSON_HEADERS, body: JSON.stringify({source, rows})});
@@ -31,7 +27,7 @@ export const undoImport = (id) => apiFetch(`${IMPORTS_URL()}/${id}/games`, {meth
* One title per line; empty lines are left out.
*/
export const parseTextList = (text) => text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean)
.map((line) => ({title: line.slice(0, MAX_TITLE)}));
.map((line) => ({title: line.slice(0, MAX_IMPORT_TITLE_LENGTH)}));
// Header names, lower case, per field.
const COLUMNS = {
@@ -65,9 +61,9 @@ export const parseCsv = (text) => {
const minutes = at.minutes >= 0 ? Math.round(Number(value(record, 'minutes'))) || 0
: hoursToMinutes(value(record, 'hours'));
return {
title: value(record, 'title').slice(0, MAX_TITLE),
title: value(record, 'title').slice(0, MAX_IMPORT_TITLE_LENGTH),
platform: platform && platform.length <= MAX_PLATFORM_LENGTH ? platform : null,
playtimeMinutes: minutes > 0 ? Math.min(minutes, MAX_MINUTES) : null,
playtimeMinutes: minutes > 0 ? Math.min(minutes, MAX_PLAYTIME_MINUTES) : null,
status: parseStatus(value(record, 'status').toUpperCase()),
};
});
+32
View File
@@ -0,0 +1,32 @@
// Limits and enums that Core or Auth check. Each copy names its server source: change both together.
// Core GameStatus
export const GAME_STATUSES = ['BACKLOG', 'PLAYING', 'FINISHED', 'COMPLETED', 'DROPPED'];
// Core GamePriority, in the order the UI shows it
export const GAME_PRIORITIES = ['HIGH', 'MEDIUM', 'LOW'];
// Core ManualGameUpdate.MAX_PLATFORM_LENGTH, Auth FavoritePlatformRequest @Size(max = 32)
export const MAX_PLATFORM_LENGTH = 32;
// Core ManualGameUpdate.MAX_MINUTES
export const MAX_PLAYTIME_MINUTES = 6_000_000;
// Core BacklogEntryDto.notes @Size(max = 2000)
export const MAX_NOTES_LENGTH = 2000;
// Core ImportRequest.MAX_ROWS
export const MAX_IMPORT_ROWS = 1000;
// Core ImportRequest.Row.title @Size(max = 100)
export const MAX_IMPORT_TITLE_LENGTH = 100;
// Core ManualGameController.search @Size(min = 2, max = 100)
export const MIN_GAME_SEARCH_LENGTH = 2;
export const MAX_GAME_SEARCH_LENGTH = 100;
// Frontend only: Core's library search takes any length.
export const MAX_LIBRARY_SEARCH_LENGTH = 100;
// Core GameCorrectionService.MAX_TEXT
export const MAX_CORRECTION_LENGTH = 512;
// Core GameCorrectionService.MAX_GENRES
export const MAX_CORRECTION_GENRES = 10;
// Auth DisplayNameFormat.PATTERN (3 to 24 characters)
export const MAX_DISPLAY_NAME_LENGTH = 24;
// Auth CreateHintRequest @Size(max = 500)
export const MAX_HINT_LENGTH = 500;
-3
View File
@@ -7,9 +7,6 @@ const JSON_HEADERS = {'Content-Type': 'application/json'};
// positive keys; Auth also takes only those as background or banner.
export const isSteamKey = (appid) => Number(appid) > 0;
// Core's limit of a game's platform (ManualGameUpdate.MAX_PLATFORM_LENGTH).
export const MAX_PLATFORM_LENGTH = 32;
// Two decimals: then hoursToMinutes gives back the same minute.
export const toHours = (minutes) => (minutes > 0 ? String(Math.round((minutes / 60) * 100) / 100) : '');