refactor: ⚡ make identicons and server metrics optional
Co-authored-by: Kainoa Kanter <kainoa@t1c.dev>
This commit is contained in:
parent
7ab8021a9d
commit
703f28a1ab
@ -1112,6 +1112,8 @@ isModerator: "Moderator"
|
||||
isAdmin: "Administrator"
|
||||
isPatron: "Calckey Patron"
|
||||
reactionPickerSkinTone: "Preferred emoji skin tone"
|
||||
enableServerMachineStats: "Enable server hardware statistics"
|
||||
enableIdenticonGeneration: "Enable Identicon generation"
|
||||
|
||||
_sensitiveMediaDetection:
|
||||
description: "Reduces the effort of server moderation through automatically recognizing
|
||||
|
@ -978,6 +978,8 @@ enableCustomKaTeXMacro: "カスタムKaTeXマクロを有効にする"
|
||||
preventAiLearning: "AIによる学習を防止"
|
||||
preventAiLearningDescription: "投稿したノート、添付した画像などのコンテンツを学習の対象にしないようAIに要求します。これはnoaiフラグをHTMLレスポンスに含めることによって実現されます。"
|
||||
noGraze: "ブラウザの拡張機能「Graze for Mastodon」は、Calckeyの動作を妨げるため、無効にしてください。"
|
||||
enableServerMachineStats: "サーバーのマシン情報を公開する"
|
||||
enableIdenticonGeneration: "ユーザーごとのIdenticon生成を有効にする"
|
||||
|
||||
_sensitiveMediaDetection:
|
||||
description: "機械学習を使って自動でセンシティブなメディアを検出し、モデレーションに役立てられます。サーバーの負荷が少し増えます。"
|
||||
|
BIN
packages/backend/assets/avatar.png
Normal file
BIN
packages/backend/assets/avatar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
21
packages/backend/migration/1688280713783-add-meta-options.js
Normal file
21
packages/backend/migration/1688280713783-add-meta-options.js
Normal 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"`,
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import si from "systeminformation";
|
||||
import Xev from "xev";
|
||||
import * as osUtils from "os-utils";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import meilisearch from "../db/meilisearch.js";
|
||||
|
||||
const ev = new Xev();
|
||||
@ -20,6 +21,9 @@ export default function () {
|
||||
ev.emit(`serverStatsLog:${x.id}`, log.slice(0, x.length || 50));
|
||||
});
|
||||
|
||||
const meta = fetchMeta();
|
||||
if (!meta.enableServerMachineStats) return;
|
||||
|
||||
async function tick() {
|
||||
const cpu = await cpuUsage();
|
||||
const memStats = await mem();
|
||||
|
@ -546,4 +546,14 @@ export class Meta {
|
||||
default: {},
|
||||
})
|
||||
public experimentalFeatures: Record<string, unknown>;
|
||||
|
||||
@Column("boolean", {
|
||||
default: false,
|
||||
})
|
||||
public enableServerMachineStats: boolean;
|
||||
|
||||
@Column("boolean", {
|
||||
default: true,
|
||||
})
|
||||
public enableIdenticonGeneration: boolean;
|
||||
}
|
||||
|
@ -481,6 +481,16 @@ export const meta = {
|
||||
},
|
||||
},
|
||||
},
|
||||
enableServerMachineStats: {
|
||||
type: "boolean",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
},
|
||||
enableIdenticonGeneration: {
|
||||
type: "boolean",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
@ -592,5 +602,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
enableIpLogging: instance.enableIpLogging,
|
||||
enableActiveEmailValidation: instance.enableActiveEmailValidation,
|
||||
experimentalFeatures: instance.experimentalFeatures,
|
||||
enableServerMachineStats: instance.enableServerMachineStats,
|
||||
enableIdenticonGeneration: instance.enableIdenticonGeneration,
|
||||
};
|
||||
});
|
||||
|
@ -2,11 +2,13 @@ import * as os from "node:os";
|
||||
import si from "systeminformation";
|
||||
import define from "../define.js";
|
||||
import meilisearch from "@/db/meilisearch.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
requireCredentialPrivateMode: true,
|
||||
|
||||
allowGet: true,
|
||||
cacheSec: 30,
|
||||
tags: ["meta"],
|
||||
} 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 {
|
||||
machine: os.hostname(),
|
||||
cpu: {
|
||||
|
@ -16,6 +16,7 @@ import { IsNull } from "typeorm";
|
||||
import config from "@/config/index.js";
|
||||
import Logger from "@/services/logger.js";
|
||||
import { UserProfiles, Users } from "@/models/index.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { genIdenticon } from "@/misc/gen-identicon.js";
|
||||
import { createTemp } from "@/misc/create-temp.js";
|
||||
import { publishMainStream } from "@/services/stream.js";
|
||||
@ -125,10 +126,16 @@ router.get("/avatar/@:acct", async (ctx) => {
|
||||
});
|
||||
|
||||
router.get("/identicon/:x", async (ctx) => {
|
||||
const [temp, cleanup] = await createTemp();
|
||||
await genIdenticon(ctx.params.x, fs.createWriteStream(temp));
|
||||
ctx.set("Content-Type", "image/png");
|
||||
ctx.body = fs.createReadStream(temp).on("close", () => cleanup());
|
||||
const meta = await fetchMeta();
|
||||
if (meta.enableIdenticonGeneration) {
|
||||
const [temp, cleanup] = await createTemp();
|
||||
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) => {
|
||||
|
@ -343,6 +343,17 @@
|
||||
</template>
|
||||
</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>
|
||||
<template #label>DeepL Translation</template>
|
||||
|
||||
@ -442,6 +453,8 @@ let libreTranslateApiUrl: string = $ref("");
|
||||
let libreTranslateApiKey: string = $ref("");
|
||||
let defaultReaction: string = $ref("");
|
||||
let defaultReactionCustom: string = $ref("");
|
||||
let enableServerMachineStats: boolean = $ref(false);
|
||||
let enableIdenticonGeneration: boolean = $ref(false);
|
||||
|
||||
async function init() {
|
||||
const meta = await os.api("admin/meta");
|
||||
@ -482,6 +495,8 @@ async function init() {
|
||||
defaultReactionCustom = ["⭐", "👍", "❤️"].includes(meta.defaultReaction)
|
||||
? ""
|
||||
: meta.defaultReaction;
|
||||
enableServerMachineStats = meta.enableServerMachineStats;
|
||||
enableIdenticonGeneration = meta.enableIdenticonGeneration;
|
||||
}
|
||||
|
||||
function save() {
|
||||
@ -521,6 +536,8 @@ function save() {
|
||||
libreTranslateApiUrl,
|
||||
libreTranslateApiKey,
|
||||
defaultReaction,
|
||||
enableServerMachineStats,
|
||||
enableIdenticonGeneration,
|
||||
}).then(() => {
|
||||
fetchInstance();
|
||||
});
|
||||
|
@ -106,7 +106,7 @@ const { widgetProps, configure, save } = useWidgetPropsManager(
|
||||
|
||||
const meta = ref(null);
|
||||
|
||||
os.api("server-info", {}).then((res) => {
|
||||
os.apiGet("server-info", {}).then((res) => {
|
||||
meta.value = res;
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user