1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 11:15:54 +02: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:
Jason Rasmussen 2024-06-12 12:36:24 -04:00 committed by GitHub
parent 10aa00af21
commit 3d82005797
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 13 deletions

View File

@ -8146,7 +8146,7 @@
"type": "boolean"
},
"maxDistance": {
"format": "float",
"format": "double",
"maximum": 0.1,
"minimum": 0.001,
"type": "number"
@ -8347,7 +8347,7 @@
"type": "boolean"
},
"maxDistance": {
"format": "float",
"format": "double",
"maximum": 2,
"minimum": 0,
"type": "number"
@ -8357,7 +8357,7 @@
"type": "integer"
},
"minScore": {
"format": "float",
"format": "double",
"maximum": 1,
"minimum": 0,
"type": "number"
@ -9797,7 +9797,7 @@
"type": "integer"
},
"diskUsagePercentage": {
"format": "float",
"format": "double",
"type": "number"
},
"diskUse": {

View File

@ -21,7 +21,7 @@ export class DuplicateDetectionConfig extends TaskConfig {
@Min(0.001)
@Max(0.1)
@Type(() => Number)
@ApiProperty({ type: 'number', format: 'float' })
@ApiProperty({ type: 'number', format: 'double' })
maxDistance!: number;
}
@ -30,14 +30,14 @@ export class FacialRecognitionConfig extends ModelConfig {
@Min(0)
@Max(1)
@Type(() => Number)
@ApiProperty({ type: 'number', format: 'float' })
@ApiProperty({ type: 'number', format: 'double' })
minScore!: number;
@IsNumber()
@Min(0)
@Max(2)
@Type(() => Number)
@ApiProperty({ type: 'number', format: 'float' })
@ApiProperty({ type: 'number', format: 'double' })
maxDistance!: number;
@IsNumber()

View File

@ -21,7 +21,7 @@ export class ServerStorageResponseDto {
@ApiProperty({ type: 'integer', format: 'int64' })
diskAvailableRaw!: number;
@ApiProperty({ type: 'number', format: 'float' })
@ApiProperty({ type: 'number', format: 'double' })
diskUsagePercentage!: number;
}

View File

@ -6,7 +6,7 @@ import {
SwaggerDocumentOptions,
SwaggerModule,
} 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 { writeFileSync } from 'node:fs';
import path from 'node:path';
@ -111,6 +111,14 @@ function sortKeys<T>(target: T): T {
export const routeToErrorMessage = (methodName: string) =>
'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) => {
document.paths = sortKeys(document.paths);
@ -119,13 +127,23 @@ const patchOpenAPI = (document: OpenAPIObject) => {
document.components.schemas = sortKeys(schemas);
for (const schema of Object.values(schemas)) {
for (const [schemaName, schema] of Object.entries(schemas)) {
if (schema.properties) {
schema.properties = sortKeys(schema.properties);
}
if (schema.required) {
schema.required = schema.required.sort();
for (const [key, value] of Object.entries(schema.properties)) {
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();
}
}
}
}