mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-07-27 17:01:53 +08:00
update 2026-06-16 11:35:09
This commit is contained in:
parent
16ccfae4f6
commit
19b8fe19fc
@ -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 () {
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user