mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat: add output filename suffixes, CPU fallback for GPU packages, and fix e2e tests
- Add tool-specific suffix to output filenames so downloads don't overwrite originals (batch & single-tool routes) - Skip deleting shared models when uninstalling a bundle that shares models with another installed bundle - Auto-detect NVIDIA GPU and swap GPU-only pip packages (onnxruntime-gpu, paddlepaddle-gpu) for CPU equivalents - Refactor docker-compose with YAML anchors and explicit cpu/gpu profiles - Add libheif-plugin-x265 to Dockerfile - Fix install-all queue logic to handle concurrent individual installs and clear stale errors - Unify playwright docker config to use same test dir with API_URL env var - Fix flaky e2e selectors, rename Strip Metadata → Remove Metadata, handle collage custom dropzone, improve fallback test image generation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
* Returns a ZIP file containing all processed images.
|
||||
*/
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { extname } from "node:path";
|
||||
import { getBundleForTool, TOOL_BUNDLE_MAP } from "@ashim/shared";
|
||||
import archiver from "archiver";
|
||||
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
@@ -170,7 +171,15 @@ export async function registerBatchRoutes(app: FastifyInstance): Promise<void> {
|
||||
}
|
||||
const result = await toolConfig.process(processBuffer, settings, processFilename);
|
||||
|
||||
results[index] = { buffer: result.buffer, filename: result.filename };
|
||||
// Add tool suffix so downloads don't overwrite originals
|
||||
let outFilename = result.filename;
|
||||
if (outFilename === processFilename) {
|
||||
const ext = extname(processFilename);
|
||||
const base = ext ? processFilename.slice(0, -ext.length) : processFilename;
|
||||
outFilename = `${base}_${toolId}${ext}`;
|
||||
}
|
||||
|
||||
results[index] = { buffer: result.buffer, filename: outFilename };
|
||||
|
||||
progress.completedFiles++;
|
||||
updateJobProgress({ ...progress });
|
||||
|
||||
@@ -228,14 +228,26 @@ export async function registerFeatureRoutes(app: FastifyInstance): Promise<void>
|
||||
return reply.status(409).send({ error: `Bundle "${bundleId}" is not installed` });
|
||||
}
|
||||
|
||||
// Read manifest to find model files to delete
|
||||
// Read manifest to find model files to delete, but skip models
|
||||
// that are still needed by another installed bundle.
|
||||
const manifest = readManifest();
|
||||
if (manifest) {
|
||||
const manifestBundle = manifest.bundles[bundleId];
|
||||
if (manifestBundle) {
|
||||
// Collect model paths that OTHER installed bundles still need
|
||||
const sharedPaths = new Set<string>();
|
||||
for (const [otherId, otherBundle] of Object.entries(manifest.bundles)) {
|
||||
if (otherId === bundleId) continue;
|
||||
if (!isFeatureInstalled(otherId)) continue;
|
||||
for (const m of (otherBundle as any).models ?? []) {
|
||||
if (m.path) sharedPaths.add(m.path);
|
||||
}
|
||||
}
|
||||
|
||||
const modelsDir = getModelsDir();
|
||||
for (const model of manifestBundle.models) {
|
||||
if (!model.path) continue;
|
||||
if (sharedPaths.has(model.path)) continue; // still needed
|
||||
const modelPath = join(modelsDir, model.path);
|
||||
try {
|
||||
if (existsSync(modelPath)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { extname, join } from "node:path";
|
||||
import { getBundleForTool, TOOL_BUNDLE_MAP } from "@ashim/shared";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
@@ -250,6 +250,15 @@ export function createToolRoute<T>(app: FastifyInstance, config: ToolRouteConfig
|
||||
result = await config.process(processBuffer, settings, filename);
|
||||
}
|
||||
|
||||
// Add a tool-specific suffix to the filename so the download
|
||||
// doesn't silently overwrite the user's original file.
|
||||
// Skip if the tool already changed the filename (e.g. convert, split).
|
||||
if (result.filename === filename) {
|
||||
const ext = extname(filename);
|
||||
const base = ext ? filename.slice(0, -ext.length) : filename;
|
||||
result.filename = `${base}_${config.toolId}${ext}`;
|
||||
}
|
||||
|
||||
// Create workspace and save output
|
||||
const jobId = randomUUID();
|
||||
const workspacePath = await createWorkspace(jobId);
|
||||
|
||||
@@ -106,7 +106,7 @@ export function AiFeaturesSection() {
|
||||
type="button"
|
||||
onClick={installAll}
|
||||
disabled={
|
||||
anyInstalling || installAllActive || bundles.every((b) => b.status === "installed")
|
||||
installAllActive || bundles.every((b) => b.status === "installed")
|
||||
}
|
||||
className="flex items-center gap-2 px-4 py-2 rounded-lg bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50"
|
||||
>
|
||||
|
||||
@@ -228,14 +228,43 @@ export const useFeaturesStore = create<FeaturesState>((set, get) => {
|
||||
|
||||
installAll: async () => {
|
||||
set({ installAllActive: true });
|
||||
const notInstalled = get().bundles.filter((b) => b.status === "not_installed");
|
||||
set({ queued: notInstalled.map((b) => b.id) });
|
||||
|
||||
for (const bundle of notInstalled) {
|
||||
set({ queued: get().queued.filter((id) => id !== bundle.id) });
|
||||
// Immediately mark every not-yet-installed bundle as queued so the UI
|
||||
// updates right away. Exclude bundles that are already installing.
|
||||
const activeIds = new Set(Object.keys(get().installing));
|
||||
const pending = get().bundles.filter(
|
||||
(b) => b.status !== "installed" && !activeIds.has(b.id),
|
||||
);
|
||||
// Clear stale errors for these bundles
|
||||
const errors = { ...get().errors };
|
||||
for (const b of pending) delete errors[b.id];
|
||||
set({ queued: pending.map((b) => b.id), errors });
|
||||
|
||||
// If an install is already in progress (user clicked an individual
|
||||
// install before Install All), wait for it to finish first.
|
||||
if (activeIds.size > 0) {
|
||||
const activeId = [...activeIds][0];
|
||||
await new Promise<void>((resolve) => {
|
||||
completionRefs[bundle.id] = resolve;
|
||||
get().installBundle(bundle.id);
|
||||
completionRefs[activeId] = resolve;
|
||||
});
|
||||
await refreshBundles();
|
||||
}
|
||||
|
||||
// Process the queue: re-read which bundles still need installing
|
||||
// (the one that was active may have just finished).
|
||||
while (true) {
|
||||
const q = get().queued;
|
||||
if (q.length === 0) break;
|
||||
const nextId = q[0];
|
||||
set({ queued: q.slice(1) });
|
||||
|
||||
// Skip if it got installed in the meantime
|
||||
const current = get().bundles.find((b) => b.id === nextId);
|
||||
if (current?.status === "installed") continue;
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
completionRefs[nextId] = resolve;
|
||||
get().installBundle(nextId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user