Public Access
refactor(limits): server limits in one file, own texts for unknown errors
This commit is contained in:
1 parent
f605917874
commit
24a98062ee
18 files changed
+84
-49
No files matched your search
@@ -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()),
|
||||
};
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user