修复了2个bug
This commit is contained in:
@@ -28,14 +28,12 @@ async function fetchImageJob(jobId: string, signal: AbortSignal) {
|
||||
}
|
||||
|
||||
async function fetchAssetsByID(ids: string[], signal: AbortSignal) {
|
||||
const assets = await Promise.all(ids.map(async (id) => {
|
||||
const response = await fetch(`/api/assets/${encodeURIComponent(id)}`, { cache: "no-store", signal });
|
||||
const payload = await readJSON(response);
|
||||
if (response.status === 404) return null;
|
||||
if (!response.ok) throw new Error(payloadError(payload, "读取编辑结果素材失败"));
|
||||
return isAsset(payload.asset) ? payload.asset : null;
|
||||
}));
|
||||
return assets.filter((asset): asset is Asset => Boolean(asset));
|
||||
const response = await fetch("/api/assets", { cache: "no-store", signal });
|
||||
const payload = await readJSON(response);
|
||||
if (!response.ok) throw new Error(payloadError(payload, "读取编辑结果素材失败"));
|
||||
const assets = Array.isArray(payload.assets) ? payload.assets.filter(isAsset) : [];
|
||||
const assetsByID = new Map(assets.map((asset) => [asset.id, asset]));
|
||||
return ids.map((id) => assetsByID.get(id)).filter((asset): asset is Asset => Boolean(asset));
|
||||
}
|
||||
|
||||
function isAsset(value: unknown): value is Asset {
|
||||
|
||||
@@ -26,3 +26,16 @@ export type SeedreamLayerComposition = {
|
||||
};
|
||||
|
||||
export type SeedreamLayerDraft = Pick<SeedreamLayerComposition, "baseAssetId" | "baseVisible" | "layers">;
|
||||
|
||||
export function hasCompleteSeedreamLayerMetadata(records: unknown[], outputCount: number): boolean {
|
||||
if (!Number.isInteger(outputCount) || outputCount < 2 || records.length !== outputCount) return false;
|
||||
const indices = records.map((value) => {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
||||
const raw = (value as Record<string, unknown>).z_index;
|
||||
const index = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() ? Number(raw) : Number.NaN;
|
||||
return Number.isInteger(index) && index >= 0 ? index : undefined;
|
||||
});
|
||||
if (indices.some((index) => index === undefined)) return false;
|
||||
const numericIndices = indices as number[];
|
||||
return numericIndices.includes(0) && new Set(numericIndices).size === numericIndices.length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user