fix(striker-ui-api): convert, read server screenshot in get server detail

main
Tsu-ba-me 1 year ago
parent 4f46bb43eb
commit 4b3343c421
  1. 30
      striker-ui-api/src/lib/request_handlers/server/getServerDetail.ts

@ -1,12 +1,11 @@
import assert from 'assert'; import assert from 'assert';
import { RequestHandler } from 'express'; import { RequestHandler } from 'express';
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import { REP_UUID, SERVER_PATHS } from '../../consts'; import { REP_UUID, SERVER_PATHS } from '../../consts';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { stderr, stdout, stdoutVar } from '../../shell'; import { stderr, stdout } from '../../shell';
import { execSync } from 'child_process';
export const getServerDetail: RequestHandler< export const getServerDetail: RequestHandler<
ServerDetailParamsDictionary, ServerDetailParamsDictionary,
@ -37,26 +36,17 @@ export const getServerDetail: RequestHandler<
} }
if (isScreenshot) { if (isScreenshot) {
const imageFileName = `${serverUuid}_screenshot`;
const imageFilePath = path.join(SERVER_PATHS.tmp.self, imageFileName);
stdoutVar(
{ imageFileName, imageFilePath },
`Server ${serverUuid} image file: `,
);
const rsbody = { screenshot: '' }; const rsbody = { screenshot: '' };
if (existsSync(imageFilePath)) { try {
try { rsbody.screenshot = execSync(
rsbody.screenshot = readFileSync(imageFilePath, { encoding: 'utf-8' }); `${SERVER_PATHS.usr.sbin['anvil-get-server-screenshot'].self} --convert --resize 500x500 --server-uuid '${serverUuid}'`,
} catch (error) { { encoding: 'utf-8' },
stderr( );
`Failed to read image file at ${imageFilePath}; CAUSE: ${error}`, } catch (error) {
); stderr(`Failed to server ${serverUuid} screenshot; CAUSE: ${error}`);
return response.status(500).send(); return response.status(500).send();
}
} }
return response.send(rsbody); return response.send(rsbody);

Loading…
Cancel
Save