|
|
@ -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,27 +36,18 @@ 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 = readFileSync(imageFilePath, { encoding: 'utf-8' }); |
|
|
|
rsbody.screenshot = execSync( |
|
|
|
} catch (error) { |
|
|
|
`${SERVER_PATHS.usr.sbin['anvil-get-server-screenshot'].self} --convert --resize 500x500 --server-uuid '${serverUuid}'`, |
|
|
|
stderr( |
|
|
|
{ encoding: 'utf-8' }, |
|
|
|
`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); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|