mirror of
https://github.com/immich-app/immich.git
synced 2025-05-21 21:01:13 +02:00
fix: retrieve version from lockfile and fallback to cli command (#17812)
This commit is contained in:
parent
be1062474b
commit
d2f2f8d672
1 changed files with 35 additions and 13 deletions
|
@ -75,27 +75,49 @@ export class ServerInfoRepository {
|
|||
|
||||
buildVersions?: ServerBuildVersions;
|
||||
|
||||
private async retrieveVersionFallback(
|
||||
command: string,
|
||||
commandTransform?: (output: string) => string,
|
||||
version?: string,
|
||||
): Promise<string> {
|
||||
if (!version) {
|
||||
const output = await maybeFirstLine(command);
|
||||
version = commandTransform ? commandTransform(output) : output;
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
async getBuildVersions(): Promise<ServerBuildVersions> {
|
||||
if (!this.buildVersions) {
|
||||
const { nodeVersion, resourcePaths } = this.configRepository.getEnv();
|
||||
|
||||
const [nodejsOutput, ffmpegOutput, magickOutput] = await Promise.all([
|
||||
maybeFirstLine('node --version'),
|
||||
maybeFirstLine('ffmpeg -version'),
|
||||
maybeFirstLine('convert --version'),
|
||||
]);
|
||||
|
||||
const lockfile = await readFile(resourcePaths.lockFile)
|
||||
const lockfile: BuildLockfile | undefined = await readFile(resourcePaths.lockFile)
|
||||
.then((buffer) => JSON.parse(buffer.toString()))
|
||||
.catch(() => this.logger.warn(`Failed to read ${resourcePaths.lockFile}`));
|
||||
|
||||
const [nodejsVersion, ffmpegVersion, magickVersion, exiftoolVersion] = await Promise.all([
|
||||
this.retrieveVersionFallback('node --version', undefined, nodeVersion),
|
||||
this.retrieveVersionFallback(
|
||||
'ffmpeg -version',
|
||||
(output) => output.replaceAll('ffmpeg version ', ''),
|
||||
getLockfileVersion('ffmpeg', lockfile),
|
||||
),
|
||||
this.retrieveVersionFallback(
|
||||
'magick --version',
|
||||
(output) => output.replaceAll('Version: ImageMagick ', ''),
|
||||
getLockfileVersion('imagemagick', lockfile),
|
||||
),
|
||||
exiftool.version(),
|
||||
]);
|
||||
|
||||
const libvipsVersion = getLockfileVersion('libvips', lockfile) || sharp.versions.vips;
|
||||
|
||||
this.buildVersions = {
|
||||
nodejs: nodejsOutput || nodeVersion || '',
|
||||
exiftool: await exiftool.version(),
|
||||
ffmpeg: getLockfileVersion('ffmpeg', lockfile) || ffmpegOutput.replaceAll('ffmpeg version', '') || '',
|
||||
libvips: getLockfileVersion('libvips', lockfile) || sharp.versions.vips,
|
||||
imagemagick:
|
||||
getLockfileVersion('imagemagick', lockfile) || magickOutput.replaceAll('Version: ImageMagick ', '') || '',
|
||||
nodejs: nodejsVersion,
|
||||
exiftool: exiftoolVersion,
|
||||
ffmpeg: ffmpegVersion,
|
||||
libvips: libvipsVersion,
|
||||
imagemagick: magickVersion,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue