fix: take the file edit limit in the panel from the agent's read cap
The limit was repeated in the page; a file of exactly the cap is read in full, so it is editable too.
This commit is contained in:
1 parent
7cb9da8569
commit
08fc2d79a8
4 files changed
+10
-6
No files matched your search
@@ -17,8 +17,8 @@ import (
|
|||||||
"github.com/x-grk/longpolling-remote-access/internal/proto"
|
"github.com/x-grk/longpolling-remote-access/internal/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fsReadCap bounds how many bytes a view/read returns (5 MiB).
|
// fsReadCap bounds how many bytes a view/read returns.
|
||||||
const fsReadCap = 5 * 1024 * 1024
|
const fsReadCap = proto.FSReadCap
|
||||||
|
|
||||||
// fsDownloadCap bounds a browser download (kept under the 64 MiB result/body
|
// fsDownloadCap bounds a browser download (kept under the 64 MiB result/body
|
||||||
// limit once base64-encoded).
|
// limit once base64-encoded).
|
||||||
|
|||||||
@@ -91,6 +91,10 @@ const (
|
|||||||
TaskSysUserAdd = "sys.useradd" // create a new OS user
|
TaskSysUserAdd = "sys.useradd" // create a new OS user
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FSReadCap bounds how many bytes TaskFSRead returns (5 MiB). The panel lets a
|
||||||
|
// file be edited only when it fits, so that a save never cuts it short.
|
||||||
|
const FSReadCap = 5 * 1024 * 1024
|
||||||
|
|
||||||
// TaskEnvelope is what the agent fetches for a task id.
|
// TaskEnvelope is what the agent fetches for a task id.
|
||||||
type TaskEnvelope struct {
|
type TaskEnvelope struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (s *Server) handleFilesPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.render(w, "files.html", map[string]any{"Agent": a})
|
s.render(w, "files.html", map[string]any{"Agent": a, "EditLimit": proto.FSReadCap})
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST /api/panel/agents/{id}/fs/{op} — run a file-manager operation on the
|
// POST /api/panel/agents/{id}/fs/{op} — run a file-manager operation on the
|
||||||
|
|||||||
@@ -107,7 +107,7 @@
|
|||||||
}).then(r => r.json()).catch(e => ({ok:false, error:'ошибка сети'})).finally(() => setBusy(false));
|
}).then(r => r.json()).catch(e => ({ok:false, error:'ошибка сети'})).finally(() => setBusy(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
const EDIT_LIMIT = 5 * 1024 * 1024;
|
const EDIT_LIMIT = {{.EditLimit}};
|
||||||
|
|
||||||
// Monochrome inline icons (inherit button color via currentColor).
|
// Monochrome inline icons (inherit button color via currentColor).
|
||||||
const SVG = '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">';
|
const SVG = '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">';
|
||||||
@@ -190,10 +190,10 @@
|
|||||||
msg.textContent = 'Размер: '+fmtSize(d.size);
|
msg.textContent = 'Размер: '+fmtSize(d.size);
|
||||||
} else {
|
} else {
|
||||||
ta.value = new TextDecoder().decode(b64ToBytes(d.content));
|
ta.value = new TextDecoder().decode(b64ToBytes(d.content));
|
||||||
const editable = d.size < EDIT_LIMIT && !d.truncated;
|
const editable = d.size <= EDIT_LIMIT && !d.truncated;
|
||||||
ta.readOnly = !editable;
|
ta.readOnly = !editable;
|
||||||
save.style.display = editable ? '' : 'none';
|
save.style.display = editable ? '' : 'none';
|
||||||
msg.textContent = 'Размер: '+fmtSize(d.size) + (d.truncated?' · показано первые 5 МБ':'') + (editable?' · редактируемо':' · только чтение (≥ 5 МБ)');
|
msg.textContent = 'Размер: '+fmtSize(d.size) + (d.truncated?' · показано первые '+fmtSize(EDIT_LIMIT):'') + (editable?' · редактируемо':' · только чтение (больше '+fmtSize(EDIT_LIMIT)+')');
|
||||||
save.onclick = async () => {
|
save.onclick = async () => {
|
||||||
const bytes = new TextEncoder().encode(ta.value);
|
const bytes = new TextEncoder().encode(ta.value);
|
||||||
const w = await api('write', {path: join(cwd, e.name), data: bytesToB64(bytes)});
|
const w = await api('write', {path: join(cwd, e.name), data: bytesToB64(bytes)});
|
||||||
|
|||||||
Reference in new issue
Block a user