refactor(ai): remove mode, add colorizeStrength to restore options

This commit is contained in:
SnapOtter
2026-05-13 16:55:38 +08:00
parent dd6ea16dd4
commit 693b441aa0
2 changed files with 9 additions and 16 deletions
+1 -1
View File
@@ -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 {
+8 -15
View File
@@ -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" });
});
}); });
}); });