refactor: make identicons and server metrics optional

Co-authored-by: Kainoa Kanter <kainoa@t1c.dev>
This commit is contained in:
Syuilo 2023-07-02 16:20:40 -07:00 committed by ThatOneCalculator
parent 7ab8021a9d
commit f17c9837c5
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
11 changed files with 100 additions and 6 deletions

View File

@ -1112,6 +1112,8 @@ isModerator: "Moderator"
isAdmin: "Administrator" isAdmin: "Administrator"
isPatron: "Calckey Patron" isPatron: "Calckey Patron"
reactionPickerSkinTone: "Preferred emoji skin tone" reactionPickerSkinTone: "Preferred emoji skin tone"
enableServerMachineStats: "Enable server hardware statistics"
enableIdenticonGeneration: "Enable Identicon generation"
_sensitiveMediaDetection: _sensitiveMediaDetection:
description: "Reduces the effort of server moderation through automatically recognizing description: "Reduces the effort of server moderation through automatically recognizing

View File

@ -978,6 +978,8 @@ enableCustomKaTeXMacro: "カスタムKaTeXマクロを有効にする"
preventAiLearning: "AIによる学習を防止" preventAiLearning: "AIによる学習を防止"
preventAiLearningDescription: "投稿したート、添付した画像などのコンテンツを学習の対象にしないようAIに要求します。これはnoaiフラグをHTMLレスポンスに含めることによって実現されます。" preventAiLearningDescription: "投稿したート、添付した画像などのコンテンツを学習の対象にしないようAIに要求します。これはnoaiフラグをHTMLレスポンスに含めることによって実現されます。"
noGraze: "ブラウザの拡張機能「Graze for Mastodon」は、Calckeyの動作を妨げるため、無効にしてください。" noGraze: "ブラウザの拡張機能「Graze for Mastodon」は、Calckeyの動作を妨げるため、無効にしてください。"
enableServerMachineStats: "サーバーのマシン情報を公開する"
enableIdenticonGeneration: "ユーザーごとのIdenticon生成を有効にする"
_sensitiveMediaDetection: _sensitiveMediaDetection:
description: "機械学習を使って自動でセンシティブなメディアを検出し、モデレーションに役立てられます。サーバーの負荷が少し増えます。" description: "機械学習を使って自動でセンシティブなメディアを検出し、モデレーションに役立てられます。サーバーの負荷が少し増えます。"

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -0,0 +1,21 @@
export class AddMetaOptions1688280713783 {
name = "AddMetaOptions1688280713783";
async up(queryRunner) {
await queryRunner.query(
`ALTER TABLE "meta" ADD "enableServerMachineStats" boolean NOT NULL DEFAULT false`,
);
await queryRunner.query(
`ALTER TABLE "meta" ADD "enableIdenticonGeneration" boolean NOT NULL DEFAULT true`,
);
}
async down(queryRunner) {
await queryRunner.query(
`ALTER TABLE "meta" DROP COLUMN "enableIdenticonGeneration"`,
);
await queryRunner.query(
`ALTER TABLE "meta" DROP COLUMN "enableServerMachineStats"`,
);
}
}

View File

@ -1,6 +1,7 @@
import si from "systeminformation"; import si from "systeminformation";
import Xev from "xev"; import Xev from "xev";
import * as osUtils from "os-utils"; import * as osUtils from "os-utils";
import { fetchMeta } from "@/misc/fetch-meta.js";
import meilisearch from "../db/meilisearch.js"; import meilisearch from "../db/meilisearch.js";
const ev = new Xev(); const ev = new Xev();
@ -20,6 +21,9 @@ export default function () {
ev.emit(`serverStatsLog:${x.id}`, log.slice(0, x.length || 50)); ev.emit(`serverStatsLog:${x.id}`, log.slice(0, x.length || 50));
}); });
const meta = fetchMeta();
if (!meta.enableServerMachineStats) return;
async function tick() { async function tick() {
const cpu = await cpuUsage(); const cpu = await cpuUsage();
const memStats = await mem(); const memStats = await mem();

View File

@ -546,4 +546,14 @@ export class Meta {
default: {}, default: {},
}) })
public experimentalFeatures: Record<string, unknown>; public experimentalFeatures: Record<string, unknown>;
@Column("boolean", {
default: false,
})
public enableServerMachineStats: boolean;
@Column("boolean", {
default: true,
})
public enableIdenticonGeneration: boolean;
} }

View File

@ -481,6 +481,16 @@ export const meta = {
}, },
}, },
}, },
enableServerMachineStats: {
type: "boolean",
optional: false,
nullable: false,
},
enableIdenticonGeneration: {
type: "boolean",
optional: false,
nullable: false,
},
}, },
}, },
} as const; } as const;
@ -592,5 +602,7 @@ export default define(meta, paramDef, async (ps, me) => {
enableIpLogging: instance.enableIpLogging, enableIpLogging: instance.enableIpLogging,
enableActiveEmailValidation: instance.enableActiveEmailValidation, enableActiveEmailValidation: instance.enableActiveEmailValidation,
experimentalFeatures: instance.experimentalFeatures, experimentalFeatures: instance.experimentalFeatures,
enableServerMachineStats: instance.enableServerMachineStats,
enableIdenticonGeneration: instance.enableIdenticonGeneration,
}; };
}); });

View File

@ -2,11 +2,13 @@ import * as os from "node:os";
import si from "systeminformation"; import si from "systeminformation";
import define from "../define.js"; import define from "../define.js";
import meilisearch from "@/db/meilisearch.js"; import meilisearch from "@/db/meilisearch.js";
import { fetchMeta } from "@/misc/fetch-meta.js";
export const meta = { export const meta = {
requireCredential: false, requireCredential: false,
requireCredentialPrivateMode: true, requireCredentialPrivateMode: true,
allowGet: true,
cacheSec: 30,
tags: ["meta"], tags: ["meta"],
} as const; } as const;
@ -29,6 +31,23 @@ export default define(meta, paramDef, async () => {
} }
} }
const instanceMeta = await fetchMeta();
if (!instanceMeta.enableServerMachineStats) {
return {
machine: 'Not specified',
cpu: {
model: 'Not specified',
cores: 0,
},
mem: {
total: 0,
},
fs: {
total: 0,
used: 0,
},
};
}
return { return {
machine: os.hostname(), machine: os.hostname(),
cpu: { cpu: {

View File

@ -16,6 +16,7 @@ import { IsNull } from "typeorm";
import config from "@/config/index.js"; import config from "@/config/index.js";
import Logger from "@/services/logger.js"; import Logger from "@/services/logger.js";
import { UserProfiles, Users } from "@/models/index.js"; import { UserProfiles, Users } from "@/models/index.js";
import { fetchMeta } from "@/misc/fetch-meta.js";
import { genIdenticon } from "@/misc/gen-identicon.js"; import { genIdenticon } from "@/misc/gen-identicon.js";
import { createTemp } from "@/misc/create-temp.js"; import { createTemp } from "@/misc/create-temp.js";
import { publishMainStream } from "@/services/stream.js"; import { publishMainStream } from "@/services/stream.js";
@ -125,10 +126,16 @@ router.get("/avatar/@:acct", async (ctx) => {
}); });
router.get("/identicon/:x", async (ctx) => { router.get("/identicon/:x", async (ctx) => {
const [temp, cleanup] = await createTemp(); const meta = await fetchMeta();
await genIdenticon(ctx.params.x, fs.createWriteStream(temp)); if (meta.enableIdenticonGeneration) {
ctx.set("Content-Type", "image/png"); const [temp, cleanup] = await createTemp();
ctx.body = fs.createReadStream(temp).on("close", () => cleanup()); await genIdenticon(ctx.params.x, fs.createWriteStream(temp));
ctx.set("Content-Type", "image/png");
ctx.body = fs.createReadStream(temp).on("close", () => cleanup());
}
else {
ctx.redirect("/static-assets/avatar.png")
}
}); });
mastoRouter.get("/oauth/authorize", async (ctx) => { mastoRouter.get("/oauth/authorize", async (ctx) => {

View File

@ -343,6 +343,17 @@
</template> </template>
</FormSection> </FormSection>
<FormSection>
<template #label>Server Performance</template>
<FormSwitch v-model="enableServerMachineStats">
<template #label>{{ i18n.ts.enableServerMachineStats }}</template>
</FormSwitch>
<FormSwitch v-model="enableIdenticonGeneration">
<template #label>{{ i18n.ts.enableIdenticonGeneration }}</template>
</FormSwitch>
</FormSection>
<FormSection> <FormSection>
<template #label>DeepL Translation</template> <template #label>DeepL Translation</template>
@ -442,6 +453,8 @@ let libreTranslateApiUrl: string = $ref("");
let libreTranslateApiKey: string = $ref(""); let libreTranslateApiKey: string = $ref("");
let defaultReaction: string = $ref(""); let defaultReaction: string = $ref("");
let defaultReactionCustom: string = $ref(""); let defaultReactionCustom: string = $ref("");
let enableServerMachineStats: boolean = $ref(false);
let enableIdenticonGeneration: boolean = $ref(false);
async function init() { async function init() {
const meta = await os.api("admin/meta"); const meta = await os.api("admin/meta");
@ -482,6 +495,8 @@ async function init() {
defaultReactionCustom = ["⭐", "👍", "❤️"].includes(meta.defaultReaction) defaultReactionCustom = ["⭐", "👍", "❤️"].includes(meta.defaultReaction)
? "" ? ""
: meta.defaultReaction; : meta.defaultReaction;
enableServerMachineStats = meta.enableServerMachineStats;
enableIdenticonGeneration = meta.enableIdenticonGeneration;
} }
function save() { function save() {
@ -521,6 +536,8 @@ function save() {
libreTranslateApiUrl, libreTranslateApiUrl,
libreTranslateApiKey, libreTranslateApiKey,
defaultReaction, defaultReaction,
enableServerMachineStats,
enableIdenticonGeneration,
}).then(() => { }).then(() => {
fetchInstance(); fetchInstance();
}); });

View File

@ -106,7 +106,7 @@ const { widgetProps, configure, save } = useWidgetPropsManager(
const meta = ref(null); const meta = ref(null);
os.api("server-info", {}).then((res) => { os.apiGet("server-info", {}).then((res) => {
meta.value = res; meta.value = res;
}); });