From 19b8fe19fcd46f21a74cd66a7919a2721e7fb00a Mon Sep 17 00:00:00 2001 From: action Date: Tue, 16 Jun 2026 11:35:09 +0800 Subject: [PATCH] update 2026-06-16 11:35:09 --- .../luci-static/resources/tools/momo.js | 35 +++++++++++++++++-- .../luci-static/resources/view/momo/editor.js | 4 +-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/luci-app-momo/htdocs/luci-static/resources/tools/momo.js b/luci-app-momo/htdocs/luci-static/resources/tools/momo.js index c8c78d1d..b820d5cf 100644 --- a/luci-app-momo/htdocs/luci-static/resources/tools/momo.js +++ b/luci-app-momo/htdocs/luci-static/resources/tools/momo.js @@ -19,6 +19,12 @@ const callRCInit = rpc.declare({ expect: { '': {} } }); +const callFileWrite = rpc.declare({ + object: 'file', + method: 'write', + params: ['path', 'data', 'append', 'mode'] +}); + const callMomoGetPaths = rpc.declare({ object: 'luci.momo', method: 'get_paths', @@ -81,6 +87,31 @@ return baseclass.extend({ return callRCInit('momo', 'restart'); }, + writefile: function (path, data, mode) { + data = (data != null) ? String(data) : ''; + mode = (mode != null) ? mode : 0o644; + + const encoder = new TextEncoder(); + const decoder = new TextDecoder(); + const chunkSize = 8 * 1024; + + const bytes = encoder.encode(data); + + if (bytes.length <= chunkSize) { + return callFileWrite(path, data, false, mode); + } + + let promise = Promise.resolve(); + for(let offset = 0; offset < bytes.length; offset += chunkSize) { + const chunkBytes = bytes.slice(offset, Math.min(offset + chunkSize, bytes.length)); + const chunk = decoder.decode(chunkBytes); + const append = offset > 0; + promise = promise.then(() => callFileWrite(path, chunk, append, mode)); + } + + return promise; + }, + version: function () { return callMomoVersion(); }, @@ -138,12 +169,12 @@ return baseclass.extend({ clearAppLog: async function () { const paths = await this.getPaths(); - return fs.write(paths.app_log_path); + return this.writefile(paths.app_log_path); }, clearCoreLog: async function () { const paths = await this.getPaths(); - return fs.write(paths.core_log_path); + return this.writefile(paths.core_log_path); }, debug: function () { diff --git a/luci-app-momo/htdocs/luci-static/resources/view/momo/editor.js b/luci-app-momo/htdocs/luci-static/resources/view/momo/editor.js index 6c26eec2..34018bad 100644 --- a/luci-app-momo/htdocs/luci-static/resources/view/momo/editor.js +++ b/luci-app-momo/htdocs/luci-static/resources/view/momo/editor.js @@ -51,11 +51,11 @@ return view.extend({ o.wrap = false; o.write = function (section_id, formvalue) { const path = m.lookupOption('_file', section_id)[0].formvalue(section_id); - return fs.write(path, formvalue); + return momo.writefile(path, formvalue); }; o.remove = function (section_id) { const path = m.lookupOption('_file', section_id)[0].formvalue(section_id); - return fs.write(path); + return momo.writefile(path); }; return m.render();