Mentions légales du service

Skip to content
Snippets Groups Projects
Commit a51cd5cb authored by VIAUD Nathan's avatar VIAUD Nathan
Browse files

fix: normalize assets between posix & windows

parent 06927267
No related branches found
No related tags found
1 merge request!97Resolve "WYSIWYG Images not normalized between windows & posix"
Pipeline #895251 passed
...@@ -261,7 +261,7 @@ const copyFileToWorkdir = async function (workdir, filepath, isIcon) { ...@@ -261,7 +261,7 @@ const copyFileToWorkdir = async function (workdir, filepath, isIcon) {
const copyPath = path.join(assetsPath, path.basename(filepath).replace(/[^a-z0-9.]/gi, '_')); const copyPath = path.join(assetsPath, path.basename(filepath).replace(/[^a-z0-9.]/gi, '_'));
if (!fs.existsSync(assetsPath)) fs.mkdirSync(assetsPath); if (!fs.existsSync(assetsPath)) fs.mkdirSync(assetsPath);
fs.copyFileSync(filepath, copyPath); fs.copyFileSync(filepath, copyPath);
return path.relative(workdir, copyPath); return path.relative(workdir, copyPath).replaceAll('\\', '/');
}; };
/** /**
...@@ -345,7 +345,7 @@ const getUsedAssets = function (workdir) { ...@@ -345,7 +345,7 @@ const getUsedAssets = function (workdir) {
if(!matches) return []; if(!matches) return [];
return matches.map(match => { return matches.map(match => {
return match.replace(`assets${path.sep}`, '') return match.replace('assets/', '')
.replaceAll('"', '') .replaceAll('"', '')
// To only keep the slash after icons // To only keep the slash after icons
.replace(/\/+/g, '/') .replace(/\/+/g, '/')
...@@ -363,7 +363,6 @@ const getUnusedAssets = function (workdir) { ...@@ -363,7 +363,6 @@ const getUnusedAssets = function (workdir) {
unusedAssets.push(asset); unusedAssets.push(asset);
} }
} }
console.assert(unusedAssets.length === 0, 'parasite asset detected', unusedAssets);
return unusedAssets; return unusedAssets;
}; };
......
...@@ -60,15 +60,26 @@ module.exports.setupWindow = function (window) { ...@@ -60,15 +60,26 @@ module.exports.setupWindow = function (window) {
console.error('Failed to register protocol:', error); console.error('Failed to register protocol:', error);
} }
const windowsUrl= [
`file:///${encodeURI(path.join(__dirname, '../../dist/assets/').replaceAll('\\', '/'))}*`,
`file:///${encodeURI(path.join(__dirname, '../../dist/images/').replaceAll('\\', '/'))}*`,
`file:///${encodeURI(path.join(__dirname, '../../dist/videos/').replaceAll('\\', '/'))}*`,
];
const posixUrl = [
`file://${encodeURI(path.join(__dirname, '../../dist/assets/'))}*`,
`file://${encodeURI(path.join(__dirname, '../../dist/images/'))}*`,
`file://${encodeURI(path.join(__dirname, '../../dist/videos/'))}*`,
];
// Intercept all url starting with assets/ and redirect it to custom protocol (wysiwyg/quill) // Intercept all url starting with assets/ and redirect it to custom protocol (wysiwyg/quill)
const filter = { const filter = {
urls: [ urls: [
'http://localhost:8000/assets/*', 'http://localhost:8000/assets/*',
'http://localhost:8000/images/*', 'http://localhost:8000/images/*',
'http://localhost:8000/videos/*', 'http://localhost:8000/videos/*',
`file://${encodeURI(path.join(__dirname, '../../dist/assets/'))}*`,
`file://${encodeURI(path.join(__dirname, '../../dist/images/'))}*`, ...(process.platform === 'win32' ? windowsUrl : posixUrl)
`file://${encodeURI(path.join(__dirname, '../../dist/videos/'))}*`
] ]
}; };
......
...@@ -26,7 +26,6 @@ const filetype = computed(() => { ...@@ -26,7 +26,6 @@ const filetype = computed(() => {
return null; return null;
}); });
//! This function have to fetch the image from the back
async function changeImage(e: Event) { async function changeImage(e: Event) {
savedState = getCurrentState(true); savedState = getCurrentState(true);
...@@ -56,6 +55,11 @@ function openFile() { ...@@ -56,6 +55,11 @@ function openFile() {
onMounted(() => { onMounted(() => {
url.value = props.inputValue; url.value = props.inputValue;
if(url.value.includes('\\')) {
//? Backwards support if files contains backslashes (not possible anymore)
// TODO: Remove this in the future
emit('input', url.value.replaceAll('\\', '/'));
}
}); });
watch( watch(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment