recherche

This commit is contained in:
Bastien COIGNOUX
2026-05-04 21:52:51 +02:00
parent 432f8ce176
commit 2b8741de08
30 changed files with 2317 additions and 246 deletions

View File

@ -8,13 +8,42 @@ migrate(
(app) => {
const usersId = app.findCollectionByNameOrId("users").id;
function loadOrCreate(name, factory) {
/** Retrouve une collection même si findCollectionByNameOrId échoue (casse, cache, image Docker). */
function findExistingCollection(name) {
try {
return app.findCollectionByNameOrId(name);
} catch {
} catch (_) {}
try {
const all = app.findAllCollections();
const want = String(name).toLowerCase();
for (let i = 0; i < all.length; i++) {
const c = all[i];
if (c && c.name && String(c.name).toLowerCase() === want) {
return c;
}
}
} catch (_) {}
return null;
}
function loadOrCreate(name, factory) {
const existing = findExistingCollection(name);
if (existing != null) {
return existing;
}
try {
const col = factory();
app.save(col);
return col;
} catch (err) {
const msg = String(err && err.value ? err.value : err && err.message ? err.message : err);
if (msg.includes("unique") || msg.includes("Unique")) {
const again = findExistingCollection(name);
if (again != null) {
return again;
}
}
throw err;
}
}