Skip to content

Commit

Permalink
hideServerInfoでもadminなどは許可するように
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Aug 15, 2024
1 parent 989a34c commit e7dcf00
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 0 additions & 2 deletions src/daemons/server-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export default function() {
if (log.length > 200) log.pop();
}

if (config.hideServerInfo) return;

tick();

setInterval(tick, interval);
Expand Down
18 changes: 11 additions & 7 deletions src/server/api/endpoints/server-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ export const meta = {
},
};

export default define(meta, async () => {
export default define(meta, async (ps, user) => {
let metricsActive = false;
if (!config.hideServerInfo || (user != null && (user.isAdmin || user.isModerator))) {
metricsActive = true;
}
const memStats = await si.mem();
const fsStats = await si.fsSize();

return {
machine: config.hideServerInfo ? 'Unknown' : os.hostname(),
machine: !metricsActive ? 'Unknown' : os.hostname(),
cpu: {
model: config.hideServerInfo ? 'Unknown' : os.cpus()[0].model,
cores: config.hideServerInfo ? 'Unknown' : os.cpus().length
model: !metricsActive ? 'Unknown' : os.cpus()[0].model,
cores: !metricsActive ? 'Unknown' : os.cpus().length
},
mem: {
total: config.hideServerInfo ? 'Unknown' : memStats.total
total: !metricsActive ? 'Unknown' : memStats.total
},
fs: {
total: config.hideServerInfo ? 'Unknown' : fsStats[0].size,
used: config.hideServerInfo ? 'Unknown' : fsStats[0].used,
total: !metricsActive ? 'Unknown' : fsStats[0].size,
used: !metricsActive ? 'Unknown' : fsStats[0].used,
},
};
});
10 changes: 5 additions & 5 deletions src/server/api/stream/channels/server-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ const ev = new Xev();
export default class extends Channel {
public readonly chName = 'serverStats';
public static shouldShare = true;
public static requireCredential = false;
public static requireCredential = true;
private active = false;

@autobind
public async init(params: any) {
if (config.hideServerInfo) return;
ev.addListener('serverStats', this.onStats);
this.active = !config.hideServerInfo || !!(this.user?.isAdmin || this.user?.isModerator);
if (this.active) ev.addListener('serverStats', this.onStats);
}

@autobind
private onStats(stats: any) {
if (config.hideServerInfo) return;
this.send('stats', stats);
}

@autobind
public onMessage(type: string, body: any) {
if (config.hideServerInfo) return;
if (!this.active) return;
switch (type) {
case 'requestLog':
ev.once(`serverStatsLog:${body.id}`, statsLog => {
Expand Down

0 comments on commit e7dcf00

Please sign in to comment.