mirror of
https://github.com/immich-app/immich.git
synced 2025-06-03 13:44:16 -04:00
fix: no floats (replace with doubles) (#10218)
* fix: no floats (replace with doubles) * Update server/src/utils/misc.ts Co-authored-by: Zack Pollard <zackpollard@ymail.com> --------- Co-authored-by: Zack Pollard <zackpollard@ymail.com>
This commit is contained in:
parent
10aa00af21
commit
3d82005797
@ -53,7 +53,7 @@ class DuplicateDetectionConfig {
|
|||||||
|
|
||||||
return DuplicateDetectionConfig(
|
return DuplicateDetectionConfig(
|
||||||
enabled: mapValueOfType<bool>(json, r'enabled')!,
|
enabled: mapValueOfType<bool>(json, r'enabled')!,
|
||||||
maxDistance: mapValueOfType<double>(json, r'maxDistance')!,
|
maxDistance: (mapValueOfType<num>(json, r'maxDistance')!).toDouble(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -74,9 +74,9 @@ class FacialRecognitionConfig {
|
|||||||
|
|
||||||
return FacialRecognitionConfig(
|
return FacialRecognitionConfig(
|
||||||
enabled: mapValueOfType<bool>(json, r'enabled')!,
|
enabled: mapValueOfType<bool>(json, r'enabled')!,
|
||||||
maxDistance: mapValueOfType<double>(json, r'maxDistance')!,
|
maxDistance: (mapValueOfType<num>(json, r'maxDistance')!).toDouble(),
|
||||||
minFaces: mapValueOfType<int>(json, r'minFaces')!,
|
minFaces: mapValueOfType<int>(json, r'minFaces')!,
|
||||||
minScore: mapValueOfType<double>(json, r'minScore')!,
|
minScore: (mapValueOfType<num>(json, r'minScore')!).toDouble(),
|
||||||
modelName: mapValueOfType<String>(json, r'modelName')!,
|
modelName: mapValueOfType<String>(json, r'modelName')!,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ class ServerStorageResponseDto {
|
|||||||
diskAvailableRaw: mapValueOfType<int>(json, r'diskAvailableRaw')!,
|
diskAvailableRaw: mapValueOfType<int>(json, r'diskAvailableRaw')!,
|
||||||
diskSize: mapValueOfType<String>(json, r'diskSize')!,
|
diskSize: mapValueOfType<String>(json, r'diskSize')!,
|
||||||
diskSizeRaw: mapValueOfType<int>(json, r'diskSizeRaw')!,
|
diskSizeRaw: mapValueOfType<int>(json, r'diskSizeRaw')!,
|
||||||
diskUsagePercentage: mapValueOfType<double>(json, r'diskUsagePercentage')!,
|
diskUsagePercentage: (mapValueOfType<num>(json, r'diskUsagePercentage')!).toDouble(),
|
||||||
diskUse: mapValueOfType<String>(json, r'diskUse')!,
|
diskUse: mapValueOfType<String>(json, r'diskUse')!,
|
||||||
diskUseRaw: mapValueOfType<int>(json, r'diskUseRaw')!,
|
diskUseRaw: mapValueOfType<int>(json, r'diskUseRaw')!,
|
||||||
);
|
);
|
||||||
|
@ -8146,7 +8146,7 @@
|
|||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"maxDistance": {
|
"maxDistance": {
|
||||||
"format": "float",
|
"format": "double",
|
||||||
"maximum": 0.1,
|
"maximum": 0.1,
|
||||||
"minimum": 0.001,
|
"minimum": 0.001,
|
||||||
"type": "number"
|
"type": "number"
|
||||||
@ -8347,7 +8347,7 @@
|
|||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"maxDistance": {
|
"maxDistance": {
|
||||||
"format": "float",
|
"format": "double",
|
||||||
"maximum": 2,
|
"maximum": 2,
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
"type": "number"
|
"type": "number"
|
||||||
@ -8357,7 +8357,7 @@
|
|||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"minScore": {
|
"minScore": {
|
||||||
"format": "float",
|
"format": "double",
|
||||||
"maximum": 1,
|
"maximum": 1,
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
"type": "number"
|
"type": "number"
|
||||||
@ -9797,7 +9797,7 @@
|
|||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"diskUsagePercentage": {
|
"diskUsagePercentage": {
|
||||||
"format": "float",
|
"format": "double",
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"diskUse": {
|
"diskUse": {
|
||||||
|
@ -21,7 +21,7 @@ export class DuplicateDetectionConfig extends TaskConfig {
|
|||||||
@Min(0.001)
|
@Min(0.001)
|
||||||
@Max(0.1)
|
@Max(0.1)
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@ApiProperty({ type: 'number', format: 'float' })
|
@ApiProperty({ type: 'number', format: 'double' })
|
||||||
maxDistance!: number;
|
maxDistance!: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,14 +30,14 @@ export class FacialRecognitionConfig extends ModelConfig {
|
|||||||
@Min(0)
|
@Min(0)
|
||||||
@Max(1)
|
@Max(1)
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@ApiProperty({ type: 'number', format: 'float' })
|
@ApiProperty({ type: 'number', format: 'double' })
|
||||||
minScore!: number;
|
minScore!: number;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@Min(0)
|
@Min(0)
|
||||||
@Max(2)
|
@Max(2)
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@ApiProperty({ type: 'number', format: 'float' })
|
@ApiProperty({ type: 'number', format: 'double' })
|
||||||
maxDistance!: number;
|
maxDistance!: number;
|
||||||
|
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
@ -21,7 +21,7 @@ export class ServerStorageResponseDto {
|
|||||||
@ApiProperty({ type: 'integer', format: 'int64' })
|
@ApiProperty({ type: 'integer', format: 'int64' })
|
||||||
diskAvailableRaw!: number;
|
diskAvailableRaw!: number;
|
||||||
|
|
||||||
@ApiProperty({ type: 'number', format: 'float' })
|
@ApiProperty({ type: 'number', format: 'double' })
|
||||||
diskUsagePercentage!: number;
|
diskUsagePercentage!: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
SwaggerDocumentOptions,
|
SwaggerDocumentOptions,
|
||||||
SwaggerModule,
|
SwaggerModule,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
|
import { ReferenceObject, SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { writeFileSync } from 'node:fs';
|
import { writeFileSync } from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
@ -111,6 +111,14 @@ function sortKeys<T>(target: T): T {
|
|||||||
export const routeToErrorMessage = (methodName: string) =>
|
export const routeToErrorMessage = (methodName: string) =>
|
||||||
'Failed to ' + methodName.replaceAll(/[A-Z]+/g, (letter) => ` ${letter.toLowerCase()}`);
|
'Failed to ' + methodName.replaceAll(/[A-Z]+/g, (letter) => ` ${letter.toLowerCase()}`);
|
||||||
|
|
||||||
|
const isSchema = (schema: string | ReferenceObject | SchemaObject): schema is SchemaObject => {
|
||||||
|
if (typeof schema === 'string' || '$ref' in schema) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
const patchOpenAPI = (document: OpenAPIObject) => {
|
const patchOpenAPI = (document: OpenAPIObject) => {
|
||||||
document.paths = sortKeys(document.paths);
|
document.paths = sortKeys(document.paths);
|
||||||
|
|
||||||
@ -119,13 +127,23 @@ const patchOpenAPI = (document: OpenAPIObject) => {
|
|||||||
|
|
||||||
document.components.schemas = sortKeys(schemas);
|
document.components.schemas = sortKeys(schemas);
|
||||||
|
|
||||||
for (const schema of Object.values(schemas)) {
|
for (const [schemaName, schema] of Object.entries(schemas)) {
|
||||||
if (schema.properties) {
|
if (schema.properties) {
|
||||||
schema.properties = sortKeys(schema.properties);
|
schema.properties = sortKeys(schema.properties);
|
||||||
}
|
|
||||||
|
|
||||||
if (schema.required) {
|
for (const [key, value] of Object.entries(schema.properties)) {
|
||||||
schema.required = schema.required.sort();
|
if (typeof value === 'string') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSchema(value) && value.type === 'number' && value.format === 'float') {
|
||||||
|
throw new Error(`Invalid number format: ${schemaName}.${key}=float (use double instead). `);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.required) {
|
||||||
|
schema.required = schema.required.sort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user