mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
refactor(ai): remove mode, add colorizeStrength to restore options
This commit is contained in:
@@ -4,13 +4,13 @@ import sharp from "sharp";
|
|||||||
import { type ProgressCallback, parseStdoutJson, runPythonWithProgress } from "./bridge.js";
|
import { type ProgressCallback, parseStdoutJson, runPythonWithProgress } from "./bridge.js";
|
||||||
|
|
||||||
export interface RestorePhotoOptions {
|
export interface RestorePhotoOptions {
|
||||||
mode?: string;
|
|
||||||
scratchRemoval?: boolean;
|
scratchRemoval?: boolean;
|
||||||
faceEnhancement?: boolean;
|
faceEnhancement?: boolean;
|
||||||
fidelity?: number;
|
fidelity?: number;
|
||||||
denoise?: boolean;
|
denoise?: boolean;
|
||||||
denoiseStrength?: number;
|
denoiseStrength?: number;
|
||||||
colorize?: boolean;
|
colorize?: boolean;
|
||||||
|
colorizeStrength?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RestorePhotoResult {
|
export interface RestorePhotoResult {
|
||||||
|
|||||||
@@ -69,13 +69,6 @@ describe("restorePhoto", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("serializes mode option", async () => {
|
|
||||||
await restorePhoto(FAKE_INPUT, FAKE_OUTPUT_DIR, { mode: "heavy" });
|
|
||||||
|
|
||||||
const args = vi.mocked(runPythonWithProgress).mock.calls[0][1];
|
|
||||||
expect(JSON.parse(args[2])).toEqual({ mode: "heavy" });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("serializes scratchRemoval option", async () => {
|
it("serializes scratchRemoval option", async () => {
|
||||||
await restorePhoto(FAKE_INPUT, FAKE_OUTPUT_DIR, { scratchRemoval: true });
|
await restorePhoto(FAKE_INPUT, FAKE_OUTPUT_DIR, { scratchRemoval: true });
|
||||||
|
|
||||||
@@ -111,15 +104,22 @@ describe("restorePhoto", () => {
|
|||||||
expect(JSON.parse(args[2])).toEqual({ colorize: true });
|
expect(JSON.parse(args[2])).toEqual({ colorize: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("serializes colorizeStrength option", async () => {
|
||||||
|
await restorePhoto(FAKE_INPUT, FAKE_OUTPUT_DIR, { colorizeStrength: 60 });
|
||||||
|
|
||||||
|
const args = vi.mocked(runPythonWithProgress).mock.calls[0][1];
|
||||||
|
expect(JSON.parse(args[2])).toEqual({ colorizeStrength: 60 });
|
||||||
|
});
|
||||||
|
|
||||||
it("serializes all options together", async () => {
|
it("serializes all options together", async () => {
|
||||||
const allOptions = {
|
const allOptions = {
|
||||||
mode: "auto",
|
|
||||||
scratchRemoval: true,
|
scratchRemoval: true,
|
||||||
faceEnhancement: true,
|
faceEnhancement: true,
|
||||||
fidelity: 0.8,
|
fidelity: 0.8,
|
||||||
denoise: true,
|
denoise: true,
|
||||||
denoiseStrength: 0.5,
|
denoiseStrength: 0.5,
|
||||||
colorize: true,
|
colorize: true,
|
||||||
|
colorizeStrength: 75,
|
||||||
};
|
};
|
||||||
await restorePhoto(FAKE_INPUT, FAKE_OUTPUT_DIR, allOptions);
|
await restorePhoto(FAKE_INPUT, FAKE_OUTPUT_DIR, allOptions);
|
||||||
|
|
||||||
@@ -354,12 +354,5 @@ describe("restorePhoto", () => {
|
|||||||
|
|
||||||
await expect(restorePhoto(FAKE_INPUT, FAKE_OUTPUT_DIR)).rejects.toThrow("segmentation fault");
|
await expect(restorePhoto(FAKE_INPUT, FAKE_OUTPUT_DIR)).rejects.toThrow("segmentation fault");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes mode option", async () => {
|
|
||||||
await restorePhoto(FAKE_INPUT, FAKE_OUTPUT_DIR, { mode: "light" });
|
|
||||||
|
|
||||||
const args = vi.mocked(runPythonWithProgress).mock.calls[0][1];
|
|
||||||
expect(JSON.parse(args[2])).toEqual({ mode: "light" });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user