fix edit file limit
This commit is contained in:
@@ -600,7 +600,6 @@ function getModeForFile(fileName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// File Editing Functions.
|
|
||||||
export function editFile(fileName, folder) {
|
export function editFile(fileName, folder) {
|
||||||
console.log("Edit button clicked for:", fileName);
|
console.log("Edit button clicked for:", fileName);
|
||||||
let existingEditor = document.getElementById("editorContainer");
|
let existingEditor = document.getElementById("editorContainer");
|
||||||
@@ -614,7 +613,9 @@ export function editFile(fileName, folder) {
|
|||||||
fetch(fileUrl, { method: "HEAD" })
|
fetch(fileUrl, { method: "HEAD" })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const contentLength = response.headers.get("Content-Length");
|
const contentLength = response.headers.get("Content-Length");
|
||||||
if (contentLength && parseInt(contentLength) > 10485760) {
|
console.log("Content-Length:", contentLength);
|
||||||
|
// If header is missing or file size exceeds threshold, block editing.
|
||||||
|
if (contentLength === null || parseInt(contentLength) > 10485760) {
|
||||||
showToast("This file is larger than 10 MB and cannot be edited in the browser.");
|
showToast("This file is larger than 10 MB and cannot be edited in the browser.");
|
||||||
throw new Error("File too large.");
|
throw new Error("File too large.");
|
||||||
}
|
}
|
||||||
@@ -627,7 +628,6 @@ export function editFile(fileName, folder) {
|
|||||||
return response.text();
|
return response.text();
|
||||||
})
|
})
|
||||||
.then(content => {
|
.then(content => {
|
||||||
// Create the modal with zoom controls in a new controls div.
|
|
||||||
const modal = document.createElement("div");
|
const modal = document.createElement("div");
|
||||||
modal.id = "editorContainer";
|
modal.id = "editorContainer";
|
||||||
modal.classList.add("modal", "editor-modal");
|
modal.classList.add("modal", "editor-modal");
|
||||||
@@ -646,33 +646,25 @@ export function editFile(fileName, folder) {
|
|||||||
document.body.appendChild(modal);
|
document.body.appendChild(modal);
|
||||||
modal.style.display = "block";
|
modal.style.display = "block";
|
||||||
|
|
||||||
// Initialize CodeMirror on the textarea.
|
const mode = getModeForFile(fileName);
|
||||||
const mode = getModeForFile(fileName); // fileName should be the current file's name
|
|
||||||
const editor = CodeMirror.fromTextArea(document.getElementById("fileEditor"), {
|
const editor = CodeMirror.fromTextArea(document.getElementById("fileEditor"), {
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
mode: mode, // dynamic mode based on file extension
|
mode: mode,
|
||||||
theme: "default",
|
theme: "default",
|
||||||
viewportMargin: Infinity
|
viewportMargin: Infinity
|
||||||
});
|
});
|
||||||
// Set editor size to use most of the modal height.
|
|
||||||
editor.setSize("100%", "60vh");
|
editor.setSize("100%", "60vh");
|
||||||
|
|
||||||
// Store the CodeMirror instance globally for saving.
|
|
||||||
window.currentEditor = editor;
|
window.currentEditor = editor;
|
||||||
|
let currentFontSize = 14;
|
||||||
// Set a starting font size and apply it.
|
|
||||||
let currentFontSize = 14; // default font size in px
|
|
||||||
editor.getWrapperElement().style.fontSize = currentFontSize + "px";
|
editor.getWrapperElement().style.fontSize = currentFontSize + "px";
|
||||||
editor.refresh();
|
editor.refresh();
|
||||||
|
|
||||||
// Zoom out button: Decrease font size.
|
|
||||||
document.getElementById("decreaseFont").addEventListener("click", function() {
|
document.getElementById("decreaseFont").addEventListener("click", function() {
|
||||||
currentFontSize = Math.max(8, currentFontSize - 2);
|
currentFontSize = Math.max(8, currentFontSize - 2);
|
||||||
editor.getWrapperElement().style.fontSize = currentFontSize + "px";
|
editor.getWrapperElement().style.fontSize = currentFontSize + "px";
|
||||||
editor.refresh();
|
editor.refresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Zoom in button: Increase font size.
|
|
||||||
document.getElementById("increaseFont").addEventListener("click", function() {
|
document.getElementById("increaseFont").addEventListener("click", function() {
|
||||||
currentFontSize = Math.min(32, currentFontSize + 2);
|
currentFontSize = Math.min(32, currentFontSize + 2);
|
||||||
editor.getWrapperElement().style.fontSize = currentFontSize + "px";
|
editor.getWrapperElement().style.fontSize = currentFontSize + "px";
|
||||||
|
|||||||
Reference in New Issue
Block a user