Fixed Storge with Generated Image from a Board

This commit is contained in:
Bruno Fargnoli 2026-07-20 15:25:34 +02:00
parent 72455e8064
commit be0318c1d8
5 changed files with 34 additions and 9 deletions

View file

@ -6547,7 +6547,7 @@ app.post('/api/assets/image-editor/save', multer({ storage: multer.memoryStorage
app.post('/api/assets/link', async (req, res) => {
try {
const { projectId, filename, type = 'image', name, metadata } = req.body;
const { projectId, filename, type = 'image', name, metadata, detached } = req.body;
if (!projectId || !filename) {
return res.status(400).json({ error: 'projectId and filename are required' });
@ -6581,7 +6581,8 @@ app.post('/api/assets/link', async (req, res) => {
format: path.extname(storedFilePath).replace('.', '').toUpperCase() || assetType.toUpperCase(),
source: 'ASSET LIB'
},
createdAt: Date.now()
createdAt: Date.now(),
detached: detached === true || String(detached).toLowerCase() === 'true'
});
res.status(201).json(newAsset);

View file

@ -141,7 +141,11 @@ export default function BoardAiPanel({ projectId, projectName, boardId, onImageG
clientId,
promptId,
persistProcessingCard: false,
detachedAsset: true
// Detached: image-generation outputs (no image input) become root project
// assets with no Kanban card. autoParentFromInputs: when an image input is
// an asset, the output is saved as an Edit of that source image instead.
detachedAsset: true,
autoParentFromInputs: true
})
const imageAssets = (Array.isArray(assets) ? assets : [assets]).filter(
a => a && (a.type ? a.type === 'image' : true)
@ -393,7 +397,10 @@ export default function BoardAiPanel({ projectId, projectName, boardId, onImageG
filename: asset.filename || asset.filePath,
type: picker.valueType === 'mesh' ? 'mesh' : 'image',
name: asset.name,
metadata: { source: 'ASSET LIB' }
metadata: { source: 'ASSET LIB' },
// Link the source to the project without a Kanban card; the edit
// output is parented to it (see autoParentFromInputs below).
detached: true
})
setInputValue(picker.paramId, {
source: `asset:${attached.id}`,

View file

@ -16,7 +16,8 @@ import {
dataURLToFile,
measureImage,
mimeFromName,
extFromMime
extFromMime,
toServedAssetPath
} from '../utils/boardHelpers'
import './BoardPage.css'
@ -257,7 +258,9 @@ export default function BoardPage() {
const placeAssetImage = useCallback(async (asset) => {
const api = excalidrawApiRef.current
if (!api || !asset) return
const refPath = asset.filename || asset.filePath || null
// Edits return a stored filePath (with data/assets/ prefix) and no filename;
// normalize either to the served path so reload URLs resolve correctly.
const refPath = asset.filename || (asset.filePath ? toServedAssetPath(asset.filePath) : null)
try {
// ComfyUI results carry an absolute `url`; external-API/persisted assets
// resolve from their served filename. Either way we render from a data URL.

View file

@ -23,6 +23,13 @@ export function boardStateSignature(elements = [], appState = {}) {
return JSON.stringify({ e: elementSig, a: sanitized })
}
// Normalize an asset path to the served (url) form assetUrl() expects. Assets
// created as edits return a stored filePath ("data/assets/images/x.png") with no
// filename field; the served mount strips the "data/assets/" prefix.
export function toServedAssetPath(pathOrFilename) {
return String(pathOrFilename || '').replace(/\\/g, '/').replace(/^data\/assets\//, '')
}
export function mimeFromName(name = '') {
const ext = String(name).split('.').pop().toLowerCase()
if (ext === 'jpg' || ext === 'jpeg') return 'image/jpeg'

View file

@ -3167,7 +3167,7 @@ export async function deleteAssetEditByFilePath(filePath) {
const absoluteEditFilePath = toAbsoluteStoragePath(existingEdit.filePath);
await fs.rm(absoluteEditFilePath, { force: true }).catch(() => null);
await fs.rmdir(path.dirname(absoluteEditFilePath)).catch(() => null);
// NB: never remove path.dirname() here — edit files share the images folder.
const editMetadata = parseJson(existingEdit.metadata, {});
@ -3391,9 +3391,16 @@ export async function deleteLibraryAssetByFilePath(type, filePath, { force = fal
}
}
// Remove each edit's OWN file only — never its directory. Edit files live in
// the shared data/assets/images folder, so deleting path.dirname() here would
// recursively wipe every image. Guard on filePath still being referenced by
// another asset row (edits and sources can share files after attach/link).
for (const childAssetRow of childAssetRows) {
const absoluteEditFilePath = toAbsoluteStoragePath(childAssetRow.filePath);
await fs.rm(path.dirname(absoluteEditFilePath), { recursive: true, force: true }).catch(() => null);
if (!childAssetRow.filePath) continue;
const stillReferenced = await get(db, 'SELECT 1 FROM Assets WHERE filePath = ? LIMIT 1', [childAssetRow.filePath]);
if (!stillReferenced) {
await fs.rm(toAbsoluteStoragePath(childAssetRow.filePath), { force: true }).catch(() => null);
}
}
return { status: 'deleted' };