Relax canvas import asset file matching
This commit is contained in:
@@ -325,12 +325,23 @@ function looksLikeExternalAssetPath(value: string) {
|
||||
|| /\.(png|jpe?g|webp|gif|avif)$/i.test(value);
|
||||
}
|
||||
|
||||
function isImageFilePath(value: string) {
|
||||
return /\.(png|jpe?g|webp|gif|avif|bmp|svg)$/i.test(value.split('?')[0] || value);
|
||||
}
|
||||
|
||||
function isVideoFilePath(value: string) {
|
||||
return /\.(mp4|mov|webm|m4v|avi|mkv)$/i.test(value.split('?')[0] || value);
|
||||
}
|
||||
|
||||
function getAssetLookupKeys(pathOrName: string) {
|
||||
const normalized = pathOrName.replace(/\\/g, '/').replace(/^\.?\//, '');
|
||||
const name = normalized.split('/').pop() || normalized;
|
||||
const withoutExt = normalized.replace(/\.[^.]+$/, '');
|
||||
const nameWithoutExt = name.replace(/\.[^.]+$/, '');
|
||||
const afterAssets = normalized.includes('/assets/') ? normalized.split('/assets/').pop() || normalized : normalized.startsWith('assets/') ? normalized.slice('assets/'.length) : '';
|
||||
const afterResourceDir = normalized.match(/(?:^|\/)(?:assets|images|image|resources|resource|uploads|files|media)\//i)?.[0]
|
||||
? normalized.replace(/^.*?(?:assets|images|image|resources|resource|uploads|files|media)\//i, '')
|
||||
: '';
|
||||
return Array.from(new Set([
|
||||
normalized,
|
||||
withoutExt,
|
||||
@@ -338,6 +349,8 @@ function getAssetLookupKeys(pathOrName: string) {
|
||||
nameWithoutExt,
|
||||
afterAssets,
|
||||
afterAssets ? afterAssets.replace(/\.[^.]+$/, '') : '',
|
||||
afterResourceDir,
|
||||
afterResourceDir ? afterResourceDir.replace(/\.[^.]+$/, '') : '',
|
||||
].filter(Boolean)));
|
||||
}
|
||||
|
||||
@@ -1247,8 +1260,9 @@ export function InfiniteCanvasWorkspace() {
|
||||
const requiredAssetKeys = collectExternalAssetKeys(importCandidate);
|
||||
const assetFiles = allFiles.filter((file) => {
|
||||
const relativePath = file.webkitRelativePath || file.name;
|
||||
if (!relativePath.includes('/assets/') && !relativePath.startsWith('assets/')) return false;
|
||||
if (file.type.startsWith('video/')) return false;
|
||||
if (file.type.startsWith('video/') || isVideoFilePath(relativePath)) return false;
|
||||
if (file.type && !file.type.startsWith('image/') && !isImageFilePath(relativePath)) return false;
|
||||
if (!file.type && !isImageFilePath(relativePath)) return false;
|
||||
return getAssetLookupKeys(relativePath).some(key => requiredAssetKeys.has(key));
|
||||
});
|
||||
const assetMap: ExternalAssetMap = new Map();
|
||||
|
||||
Reference in New Issue
Block a user