From 5302d3a62ef24a7b400b97a530c127a57fce2426 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 3 Dec 2024 18:08:08 -0500 Subject: [PATCH 1/2] Added the warning dialog If the system detects any sensitive files, it will pop up the dialog showing the warning and provide the user with options of continuing or not. --- src/dev-center/js/dev-center.js | 116 ++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/src/dev-center/js/dev-center.js b/src/dev-center/js/dev-center.js index 8aa2f4454..7b99939a0 100644 --- a/src/dev-center/js/dev-center.js +++ b/src/dev-center/js/dev-center.js @@ -1638,7 +1638,123 @@ function sort_apps() { } } +/** + * Checks if the items being deployed contain a .git directory + * @param {Array|string} items - Items to check (can be path string or array of items) + * @returns {Promise} - True if .git directory is found + */ +async function hasGitDirectory(items) { + // Case 1: Single Puter path + if (typeof items === 'string' && (items.startsWith('/') || items.startsWith('~'))) { + const stat = await puter.fs.stat(items); + if (stat.is_dir) { + const files = await puter.fs.readdir(items); + return files.some(file => file.name === '.git' && file.is_dir); + } + return false; + } + + // Case 2: Array of Puter items + if (Array.isArray(items) && items[0]?.uid) { + return items.some(item => item.name === '.git' && item.is_dir); + } + + // Case 3: Local items (DataTransferItems) + if (Array.isArray(items)) { + for (let item of items) { + if (item.fullPath?.includes('/.git/') || + item.path?.includes('/.git/') || + item.filepath?.includes('/.git/')) { + return true; + } + } + } + + return false; +} + +/** + * Shows a warning dialog about .git directory deployment + * @returns {Promise} - True if the user wants to proceed with deployment + */ +async function showGitWarningDialog() { + try { + // Check if the user has chosen to skip the warning + const skipWarning = await puter.kv.get('skip-git-warning'); + + // Log retrieved value for debugging + console.log('Retrieved skip-git-warning:', skipWarning); + + // If the user opted to skip the warning, proceed without showing it + if (skipWarning?.result === true) { + return true; + } + } catch (error) { + console.error('Error accessing KV store:', error); + // If KV store access fails, fall back to showing the dialog + } + + // Create the modal dialog + const modal = document.createElement('div'); + modal.innerHTML = ` +
+

Warning: Git Repository Detected

+

A .git directory was found in your deployment files. Deploying .git directories may:

+
    +
  • Expose sensitive information like commit history and configuration
  • +
  • Significantly increase deployment size
  • +
+
+ + +
+
+ + +
+
+
+ `; + document.body.appendChild(modal); + + return new Promise((resolve) => { + // Handle "Continue Deployment" + document.getElementById('continue-deployment').addEventListener('click', async () => { + try { + const skipChecked = document.getElementById('skip-git-warning')?.checked; + if (skipChecked) { + console.log("Saving 'skip-git-warning' preference as true"); + await puter.kv.set('skip-git-warning', true); + } + } catch (error) { + console.error('Error saving user preference to KV store:', error); + } finally { + document.body.removeChild(modal); + resolve(true); // Continue deployment + } + }); + + // Handle "Cancel Deployment" + document.getElementById('cancel-deployment').addEventListener('click', () => { + document.body.removeChild(modal); + resolve(false); // Cancel deployment + }); + }); +} + window.deploy = async function (app, items) { + // Check for .git directory before proceeding + try { + if (await hasGitDirectory(items)) { + const shouldProceed = await showGitWarningDialog(); + if (!shouldProceed) { + reset_drop_area(); + return; + } + } + } catch (err) { + console.error('Error checking for .git directory:', err); + } let appdata_dir, current_app_dir; // disable deploy button From 59ac89db8598ca071b8c3af60b2de0ad35b50f34 Mon Sep 17 00:00:00 2001 From: jelveh Date: Tue, 3 Dec 2024 19:10:14 -0800 Subject: [PATCH 2/2] handle the return value of `skipWarning` --- src/dev-center/js/dev-center.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dev-center/js/dev-center.js b/src/dev-center/js/dev-center.js index 7b99939a0..063f5bb25 100644 --- a/src/dev-center/js/dev-center.js +++ b/src/dev-center/js/dev-center.js @@ -1686,7 +1686,7 @@ async function showGitWarningDialog() { console.log('Retrieved skip-git-warning:', skipWarning); // If the user opted to skip the warning, proceed without showing it - if (skipWarning?.result === true) { + if (skipWarning === true) { return true; } } catch (error) { @@ -1706,7 +1706,7 @@ async function showGitWarningDialog() {
- +