revert fb8e77bb68
Local Build and Deploy / deploy (push) Successful in 1m11s

revert style: clean up code with prettier and eslint
This commit is contained in:
remco committed 2026-07-12 21:02:03 +02:00
1 parent 27de078f54
commit e85e4d74ea
378 files changed
+20710 -22428

No files matched your search

+44 -44
View File
@@ -1,102 +1,102 @@
import { existsSync, promises as fs } from "node:fs";
import path from "node:path";
import { downloadFile } from "@/lib/services/import/core/download";
import { CANONICAL_PETS, resolvePetSwfUrl } from "@/lib/services/pet-source";
import { convertSwfToNitro } from "@/lib/services/swf-to-nitro";
import { existsSync, promises as fs } from 'node:fs'
import path from 'node:path'
import { downloadFile } from '@/lib/services/import/core/download'
import { CANONICAL_PETS, resolvePetSwfUrl } from '@/lib/services/pet-source'
import { convertSwfToNitro } from '@/lib/services/swf-to-nitro'
export interface PetListItem {
lib: string;
nitroExists: boolean;
lib: string
nitroExists: boolean
}
export interface ImportPetResult {
ok: boolean;
lib: string;
warnings: string[];
error?: string;
ok: boolean
lib: string
warnings: string[]
error?: string
}
export const PET_NITRO_DIR = path.join(
/*turbopackIgnore: true*/ process.cwd(),
"public/nitro-assets/bundled/pet",
);
export const PET_SWF_DIR = path.join(/*turbopackIgnore: true*/ process.cwd(), "public/swf/gordon");
'public/nitro-assets/bundled/pet',
)
export const PET_SWF_DIR = path.join(/*turbopackIgnore: true*/ process.cwd(), 'public/swf/gordon')
export async function ensurePetDirs(): Promise<void> {
await Promise.all(
[PET_NITRO_DIR, PET_SWF_DIR]
.filter((dir) => !existsSync(/*turbopackIgnore: true*/ dir))
.map((dir) => fs.mkdir(/*turbopackIgnore: true*/ dir, { recursive: true })),
);
)
}
function nitroPathFor(lib: string): string {
return path.join(/*turbopackIgnore: true*/ PET_NITRO_DIR, `${lib}.nitro`);
return path.join(/*turbopackIgnore: true*/ PET_NITRO_DIR, `${lib}.nitro`)
}
export async function importSinglePet(params: {
lib: string;
onProgress?: (status: string) => void;
lib: string
onProgress?: (status: string) => void
}): Promise<ImportPetResult> {
const { lib, onProgress } = params;
const warnings: string[] = [];
await ensurePetDirs();
const { lib, onProgress } = params
const warnings: string[] = []
await ensurePetDirs()
onProgress?.("downloading");
const swfPath = path.join(/*turbopackIgnore: true*/ PET_SWF_DIR, `${lib}.swf`);
let swfUrl: string;
onProgress?.('downloading')
const swfPath = path.join(/*turbopackIgnore: true*/ PET_SWF_DIR, `${lib}.swf`)
let swfUrl: string
try {
swfUrl = await resolvePetSwfUrl(lib);
swfUrl = await resolvePetSwfUrl(lib)
} catch (err) {
return {
ok: false,
lib,
warnings,
error: `Could not resolve SWF URL: ${(err as Error).message}`,
};
}
}
const dl = await downloadFile(swfUrl, swfPath, { validate: "swf" });
if (!dl.ok) return { ok: false, lib, warnings, error: `SWF download failed: ${swfUrl}` };
const dl = await downloadFile(swfUrl, swfPath, { validate: 'swf' })
if (!dl.ok) return { ok: false, lib, warnings, error: `SWF download failed: ${swfUrl}` }
onProgress?.("converting");
onProgress?.('converting')
try {
const swfBuffer = await fs.readFile(/*turbopackIgnore: true*/ swfPath);
const result = convertSwfToNitro(swfBuffer, lib);
await fs.writeFile(/*turbopackIgnore: true*/ nitroPathFor(lib), result.bundle);
if (result.warnings?.length) warnings.push(...result.warnings);
const swfBuffer = await fs.readFile(/*turbopackIgnore: true*/ swfPath)
const result = convertSwfToNitro(swfBuffer, lib)
await fs.writeFile(/*turbopackIgnore: true*/ nitroPathFor(lib), result.bundle)
if (result.warnings?.length) warnings.push(...result.warnings)
} catch (err) {
return {
ok: false,
lib,
warnings,
error: `SWF→Nitro conversion failed: ${(err as Error).message}`,
};
}
}
return { ok: true, lib, warnings };
return { ok: true, lib, warnings }
}
export async function deleteImportedPet(lib: string): Promise<{ deletedFile: boolean }> {
const p = nitroPathFor(lib);
const p = nitroPathFor(lib)
if (existsSync(/*turbopackIgnore: true*/ p)) {
await fs.unlink(/*turbopackIgnore: true*/ p).catch(() => {});
return { deletedFile: true };
await fs.unlink(/*turbopackIgnore: true*/ p).catch(() => {})
return { deletedFile: true }
}
return { deletedFile: false };
return { deletedFile: false }
}
export function getPetList(search: string): PetListItem[] {
const term = search.trim().toLowerCase();
const term = search.trim().toLowerCase()
const list = CANONICAL_PETS.map((lib) => ({
lib,
nitroExists: existsSync(/*turbopackIgnore: true*/ nitroPathFor(lib)),
}));
return term ? list.filter((p) => p.lib.toLowerCase().includes(term)) : list;
}))
return term ? list.filter((p) => p.lib.toLowerCase().includes(term)) : list
}
export function getPetStats(): { total: number; imported: number; missing: number } {
const imported = CANONICAL_PETS.filter((lib) =>
existsSync(/*turbopackIgnore: true*/ nitroPathFor(lib)),
).length;
return { total: CANONICAL_PETS.length, imported, missing: CANONICAL_PETS.length - imported };
).length
return { total: CANONICAL_PETS.length, imported, missing: CANONICAL_PETS.length - imported }
}