From 15b09ccc75c1cdeb06ae0fd51e93f5b62a8d5108 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Tue, 19 Oct 2021 11:04:05 +0200 Subject: [PATCH] #156 - Fix for media files in new folder --- CHANGELOG.md | 1 + src/commands/Dashboard.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af9754dd..a936dc65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### 🐞 Fixes - [#153](https://github.com/estruyf/vscode-front-matter/issues/153): Support old date formatting for date-fns +- [#156](https://github.com/estruyf/vscode-front-matter/issues/156): Fix for uploading media files into a new folder ## [5.1.1] - 2021-10-14 diff --git a/src/commands/Dashboard.ts b/src/commands/Dashboard.ts index e8748889..c6ac8102 100644 --- a/src/commands/Dashboard.ts +++ b/src/commands/Dashboard.ts @@ -341,7 +341,15 @@ export class Dashboard { selectedFolder = ''; } - const relSelectedFolderPath = selectedFolder ? selectedFolder.substring((parseWinPath(wsFolder?.fsPath || "")).length + 1) : ''; + let relSelectedFolderPath = selectedFolder; + const parsedPath = parseWinPath(wsFolder?.fsPath || ""); + if (selectedFolder && selectedFolder.startsWith(parsedPath)) { + relSelectedFolderPath = selectedFolder.replace(parsedPath, ''); + } + + if (relSelectedFolderPath.startsWith('/')) { + relSelectedFolderPath = relSelectedFolderPath.substring(1); + } let allMedia: MediaInfo[] = []; @@ -574,9 +582,9 @@ export class Dashboard { if (imgData) { writeFileSync(staticPath, imgData.data); - Notifications.info(`File ${fileName} uploaded to: ${staticFolder}/${folder}`); + Notifications.info(`File ${fileName} uploaded to: ${folder}`); - const folderPath = `${staticFolder}/${folder}`; + const folderPath = `${folder}`; if (Dashboard.timers[folderPath]) { clearTimeout(Dashboard.timers[folderPath]); delete Dashboard.timers[folderPath];