@dyrected/core 2.5.35 → 2.5.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.cjs +62 -1
- package/dist/server.js +62 -1
- package/package.json +1 -1
package/dist/server.cjs
CHANGED
|
@@ -3270,22 +3270,56 @@ function registerRoutes(app, config) {
|
|
|
3270
3270
|
const db = config.db;
|
|
3271
3271
|
const user = c.get("user");
|
|
3272
3272
|
const key = c.req.param("key");
|
|
3273
|
+
const scope = c.req.query("scope");
|
|
3273
3274
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
3274
3275
|
if (!user?.collection || !user.sub) return c.json({ error: true, message: "Authentication required." }, 401);
|
|
3275
3276
|
if (!key) return c.json({ error: true, message: "Preference key is required." }, 400);
|
|
3277
|
+
const getGlobalPreference = async () => {
|
|
3278
|
+
const globalDoc = await db.findOne({ collection: "__global_preferences", id: key });
|
|
3279
|
+
return globalDoc ? globalDoc.value : null;
|
|
3280
|
+
};
|
|
3281
|
+
if (scope === "global") {
|
|
3282
|
+
const globalValue2 = await getGlobalPreference();
|
|
3283
|
+
return c.json({ key, value: globalValue2 });
|
|
3284
|
+
}
|
|
3276
3285
|
const doc = await db.findOne({ collection: user.collection, id: user.sub });
|
|
3277
3286
|
if (!doc) return c.json({ error: true, message: "User not found." }, 404);
|
|
3278
3287
|
const preferences = typeof doc.__preferences === "object" && doc.__preferences !== null ? doc.__preferences : {};
|
|
3279
|
-
|
|
3288
|
+
if (key in preferences) {
|
|
3289
|
+
return c.json({ key, value: preferences[key] ?? null });
|
|
3290
|
+
}
|
|
3291
|
+
const globalValue = await getGlobalPreference();
|
|
3292
|
+
return c.json({ key, value: globalValue });
|
|
3280
3293
|
});
|
|
3281
3294
|
app.put("/api/preferences/:key", requireAuth(), async (c) => {
|
|
3282
3295
|
const db = config.db;
|
|
3283
3296
|
const user = c.get("user");
|
|
3284
3297
|
const key = c.req.param("key");
|
|
3298
|
+
const scope = c.req.query("scope");
|
|
3285
3299
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
3286
3300
|
if (!user?.collection || !user.sub) return c.json({ error: true, message: "Authentication required." }, 401);
|
|
3287
3301
|
if (!key) return c.json({ error: true, message: "Preference key is required." }, 400);
|
|
3288
3302
|
const body = await c.req.json().catch(() => ({}));
|
|
3303
|
+
if (scope === "global") {
|
|
3304
|
+
const isAdminUser = Array.isArray(user?.roles) && user.roles.includes("admin");
|
|
3305
|
+
if (!isAdminUser) {
|
|
3306
|
+
return c.json({ error: true, message: "Only administrators can save global preferences." }, 403);
|
|
3307
|
+
}
|
|
3308
|
+
const existing = await db.findOne({ collection: "__global_preferences", id: key });
|
|
3309
|
+
if (existing) {
|
|
3310
|
+
await db.update({
|
|
3311
|
+
collection: "__global_preferences",
|
|
3312
|
+
id: key,
|
|
3313
|
+
data: { value: body.value }
|
|
3314
|
+
});
|
|
3315
|
+
} else {
|
|
3316
|
+
await db.create({
|
|
3317
|
+
collection: "__global_preferences",
|
|
3318
|
+
data: { id: key, value: body.value }
|
|
3319
|
+
});
|
|
3320
|
+
}
|
|
3321
|
+
return c.json({ key, value: body.value });
|
|
3322
|
+
}
|
|
3289
3323
|
const doc = await db.findOne({ collection: user.collection, id: user.sub });
|
|
3290
3324
|
if (!doc) return c.json({ error: true, message: "User not found." }, 404);
|
|
3291
3325
|
const preferences = typeof doc.__preferences === "object" && doc.__preferences !== null ? doc.__preferences : {};
|
|
@@ -3297,6 +3331,33 @@ function registerRoutes(app, config) {
|
|
|
3297
3331
|
});
|
|
3298
3332
|
return c.json({ key, value: body.value });
|
|
3299
3333
|
});
|
|
3334
|
+
app.delete("/api/preferences/:key", requireAuth(), async (c) => {
|
|
3335
|
+
const db = config.db;
|
|
3336
|
+
const user = c.get("user");
|
|
3337
|
+
const key = c.req.param("key");
|
|
3338
|
+
const scope = c.req.query("scope");
|
|
3339
|
+
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
3340
|
+
if (!user?.collection || !user.sub) return c.json({ error: true, message: "Authentication required." }, 401);
|
|
3341
|
+
if (!key) return c.json({ error: true, message: "Preference key is required." }, 400);
|
|
3342
|
+
if (scope === "global") {
|
|
3343
|
+
const isAdminUser = Array.isArray(user?.roles) && user.roles.includes("admin");
|
|
3344
|
+
if (!isAdminUser) {
|
|
3345
|
+
return c.json({ error: true, message: "Only administrators can delete global preferences." }, 403);
|
|
3346
|
+
}
|
|
3347
|
+
await db.delete({ collection: "__global_preferences", id: key });
|
|
3348
|
+
return c.json({ success: true });
|
|
3349
|
+
}
|
|
3350
|
+
const doc = await db.findOne({ collection: user.collection, id: user.sub });
|
|
3351
|
+
if (!doc) return c.json({ error: true, message: "User not found." }, 404);
|
|
3352
|
+
const preferences = typeof doc.__preferences === "object" && doc.__preferences !== null ? { ...doc.__preferences } : {};
|
|
3353
|
+
delete preferences[key];
|
|
3354
|
+
await db.update({
|
|
3355
|
+
collection: user.collection,
|
|
3356
|
+
id: user.sub,
|
|
3357
|
+
data: { __preferences: preferences }
|
|
3358
|
+
});
|
|
3359
|
+
return c.json({ success: true });
|
|
3360
|
+
});
|
|
3300
3361
|
app.get("/api/media/:filename{.+$}", async (c) => {
|
|
3301
3362
|
const mediaController = new MediaController("media");
|
|
3302
3363
|
return mediaController.serve(c);
|
package/dist/server.js
CHANGED
|
@@ -1971,22 +1971,56 @@ function registerRoutes(app, config) {
|
|
|
1971
1971
|
const db = config.db;
|
|
1972
1972
|
const user = c.get("user");
|
|
1973
1973
|
const key = c.req.param("key");
|
|
1974
|
+
const scope = c.req.query("scope");
|
|
1974
1975
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1975
1976
|
if (!user?.collection || !user.sub) return c.json({ error: true, message: "Authentication required." }, 401);
|
|
1976
1977
|
if (!key) return c.json({ error: true, message: "Preference key is required." }, 400);
|
|
1978
|
+
const getGlobalPreference = async () => {
|
|
1979
|
+
const globalDoc = await db.findOne({ collection: "__global_preferences", id: key });
|
|
1980
|
+
return globalDoc ? globalDoc.value : null;
|
|
1981
|
+
};
|
|
1982
|
+
if (scope === "global") {
|
|
1983
|
+
const globalValue2 = await getGlobalPreference();
|
|
1984
|
+
return c.json({ key, value: globalValue2 });
|
|
1985
|
+
}
|
|
1977
1986
|
const doc = await db.findOne({ collection: user.collection, id: user.sub });
|
|
1978
1987
|
if (!doc) return c.json({ error: true, message: "User not found." }, 404);
|
|
1979
1988
|
const preferences = typeof doc.__preferences === "object" && doc.__preferences !== null ? doc.__preferences : {};
|
|
1980
|
-
|
|
1989
|
+
if (key in preferences) {
|
|
1990
|
+
return c.json({ key, value: preferences[key] ?? null });
|
|
1991
|
+
}
|
|
1992
|
+
const globalValue = await getGlobalPreference();
|
|
1993
|
+
return c.json({ key, value: globalValue });
|
|
1981
1994
|
});
|
|
1982
1995
|
app.put("/api/preferences/:key", requireAuth(), async (c) => {
|
|
1983
1996
|
const db = config.db;
|
|
1984
1997
|
const user = c.get("user");
|
|
1985
1998
|
const key = c.req.param("key");
|
|
1999
|
+
const scope = c.req.query("scope");
|
|
1986
2000
|
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
1987
2001
|
if (!user?.collection || !user.sub) return c.json({ error: true, message: "Authentication required." }, 401);
|
|
1988
2002
|
if (!key) return c.json({ error: true, message: "Preference key is required." }, 400);
|
|
1989
2003
|
const body = await c.req.json().catch(() => ({}));
|
|
2004
|
+
if (scope === "global") {
|
|
2005
|
+
const isAdminUser = Array.isArray(user?.roles) && user.roles.includes("admin");
|
|
2006
|
+
if (!isAdminUser) {
|
|
2007
|
+
return c.json({ error: true, message: "Only administrators can save global preferences." }, 403);
|
|
2008
|
+
}
|
|
2009
|
+
const existing = await db.findOne({ collection: "__global_preferences", id: key });
|
|
2010
|
+
if (existing) {
|
|
2011
|
+
await db.update({
|
|
2012
|
+
collection: "__global_preferences",
|
|
2013
|
+
id: key,
|
|
2014
|
+
data: { value: body.value }
|
|
2015
|
+
});
|
|
2016
|
+
} else {
|
|
2017
|
+
await db.create({
|
|
2018
|
+
collection: "__global_preferences",
|
|
2019
|
+
data: { id: key, value: body.value }
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
return c.json({ key, value: body.value });
|
|
2023
|
+
}
|
|
1990
2024
|
const doc = await db.findOne({ collection: user.collection, id: user.sub });
|
|
1991
2025
|
if (!doc) return c.json({ error: true, message: "User not found." }, 404);
|
|
1992
2026
|
const preferences = typeof doc.__preferences === "object" && doc.__preferences !== null ? doc.__preferences : {};
|
|
@@ -1998,6 +2032,33 @@ function registerRoutes(app, config) {
|
|
|
1998
2032
|
});
|
|
1999
2033
|
return c.json({ key, value: body.value });
|
|
2000
2034
|
});
|
|
2035
|
+
app.delete("/api/preferences/:key", requireAuth(), async (c) => {
|
|
2036
|
+
const db = config.db;
|
|
2037
|
+
const user = c.get("user");
|
|
2038
|
+
const key = c.req.param("key");
|
|
2039
|
+
const scope = c.req.query("scope");
|
|
2040
|
+
if (!db) return c.json({ message: "Database not configured" }, 500);
|
|
2041
|
+
if (!user?.collection || !user.sub) return c.json({ error: true, message: "Authentication required." }, 401);
|
|
2042
|
+
if (!key) return c.json({ error: true, message: "Preference key is required." }, 400);
|
|
2043
|
+
if (scope === "global") {
|
|
2044
|
+
const isAdminUser = Array.isArray(user?.roles) && user.roles.includes("admin");
|
|
2045
|
+
if (!isAdminUser) {
|
|
2046
|
+
return c.json({ error: true, message: "Only administrators can delete global preferences." }, 403);
|
|
2047
|
+
}
|
|
2048
|
+
await db.delete({ collection: "__global_preferences", id: key });
|
|
2049
|
+
return c.json({ success: true });
|
|
2050
|
+
}
|
|
2051
|
+
const doc = await db.findOne({ collection: user.collection, id: user.sub });
|
|
2052
|
+
if (!doc) return c.json({ error: true, message: "User not found." }, 404);
|
|
2053
|
+
const preferences = typeof doc.__preferences === "object" && doc.__preferences !== null ? { ...doc.__preferences } : {};
|
|
2054
|
+
delete preferences[key];
|
|
2055
|
+
await db.update({
|
|
2056
|
+
collection: user.collection,
|
|
2057
|
+
id: user.sub,
|
|
2058
|
+
data: { __preferences: preferences }
|
|
2059
|
+
});
|
|
2060
|
+
return c.json({ success: true });
|
|
2061
|
+
});
|
|
2001
2062
|
app.get("/api/media/:filename{.+$}", async (c) => {
|
|
2002
2063
|
const mediaController = new MediaController("media");
|
|
2003
2064
|
return mediaController.serve(c);
|