Make application and logo configurable (#336)
* Adds settings for server name and logo * Implements ApplicationLogo and replaces site name based on settings * Refactors component for changing the company logo * Removes unused variable * Uses message instead of statusMessage * Replaces favicon with logo if set
This commit is contained in:
@@ -42,7 +42,7 @@ export default defineEventHandler(async (h3) => {
|
||||
},
|
||||
});
|
||||
if (count == 0) {
|
||||
await dump();
|
||||
dump();
|
||||
throw createError({ statusCode: 404, message: "Company not found" });
|
||||
}
|
||||
|
||||
|
||||
@@ -3,21 +3,49 @@ import { applicationSettings } from "~/server/internal/config/application-config
|
||||
import { readDropValidatedBody } from "~/server/arktype";
|
||||
import { defineEventHandler, createError } from "h3";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import objectHandler from "~/server/internal/objects";
|
||||
import type { Settings } from "~/server/internal/utils/types";
|
||||
|
||||
const UpdateSettings = type({
|
||||
showGamePanelTextDecoration: "boolean",
|
||||
"store?": {
|
||||
showGamePanelTextDecoration: "boolean",
|
||||
},
|
||||
"generalSettings?": {
|
||||
serverName: "string",
|
||||
mLogoObjectId: "string | null",
|
||||
},
|
||||
});
|
||||
|
||||
export default defineEventHandler<{ body: typeof UpdateSettings.infer }>(
|
||||
async (h3) => {
|
||||
async (h3): Promise<Settings> => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["settings:update"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await readDropValidatedBody(h3, UpdateSettings);
|
||||
|
||||
await applicationSettings.set(
|
||||
"showGamePanelTextDecoration",
|
||||
body.showGamePanelTextDecoration,
|
||||
);
|
||||
if (body.store) {
|
||||
await applicationSettings.set(
|
||||
"showGamePanelTextDecoration",
|
||||
body.store.showGamePanelTextDecoration,
|
||||
);
|
||||
}
|
||||
if (body.generalSettings) {
|
||||
const previousMLogoObjectId =
|
||||
await applicationSettings.get("mLogoObjectId");
|
||||
await applicationSettings.set(
|
||||
"serverName",
|
||||
body.generalSettings.serverName,
|
||||
);
|
||||
if (body.generalSettings.mLogoObjectId !== previousMLogoObjectId) {
|
||||
if (previousMLogoObjectId) {
|
||||
await objectHandler.deleteAsSystem(previousMLogoObjectId);
|
||||
}
|
||||
applicationSettings.set(
|
||||
"mLogoObjectId",
|
||||
body.generalSettings.mLogoObjectId || null,
|
||||
);
|
||||
}
|
||||
}
|
||||
return await applicationSettings.getSettings();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import { handleFileUpload } from "~/server/internal/utils/handlefileupload";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["settings:update"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const result = await handleFileUpload(h3, {}, ["anonymous:read"], 1);
|
||||
if (!result)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: "File upload required (multipart form)",
|
||||
});
|
||||
|
||||
const [ids, , pull] = result;
|
||||
const id = ids.at(0);
|
||||
if (!id)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Upload at least one file.",
|
||||
});
|
||||
|
||||
await pull();
|
||||
|
||||
return { id: id };
|
||||
});
|
||||
@@ -1,10 +1,13 @@
|
||||
import { applicationSettings } from "~/server/internal/config/application-configuration";
|
||||
import { systemConfig } from "~/server/internal/config/sys-conf";
|
||||
|
||||
export default defineEventHandler((_h3) => {
|
||||
export default defineEventHandler(async (_h3) => {
|
||||
return {
|
||||
appName: "Drop",
|
||||
version: systemConfig.getDropVersion(),
|
||||
gitRef: `#${systemConfig.getGitRef()}`,
|
||||
external: systemConfig.getExternalUrl(),
|
||||
serverName: await applicationSettings.get("serverName"),
|
||||
mLogoObjectId: await applicationSettings.get("mLogoObjectId"),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import { applicationSettings } from "~/server/internal/config/application-configuration";
|
||||
import type { Settings } from "~/server/internal/utils/types";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
export default defineEventHandler(async (h3): Promise<Settings> => {
|
||||
const allowed = await aclManager.getUserACL(h3, ["settings:read"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const showGamePanelTextDecoration = await applicationSettings.get(
|
||||
"showGamePanelTextDecoration",
|
||||
);
|
||||
|
||||
return { showGamePanelTextDecoration };
|
||||
return applicationSettings.getSettings();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user