mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-31 05:45:13 +08:00
update 2026-06-16 11:35:09
This commit is contained in:
1 parent
16ccfae4f6
commit
19b8fe19fc
2 files changed
+35
-4
No files matched your search
@@ -19,6 +19,12 @@ const callRCInit = rpc.declare({
|
|||||||
expect: { '': {} }
|
expect: { '': {} }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const callFileWrite = rpc.declare({
|
||||||
|
object: 'file',
|
||||||
|
method: 'write',
|
||||||
|
params: ['path', 'data', 'append', 'mode']
|
||||||
|
});
|
||||||
|
|
||||||
const callMomoGetPaths = rpc.declare({
|
const callMomoGetPaths = rpc.declare({
|
||||||
object: 'luci.momo',
|
object: 'luci.momo',
|
||||||
method: 'get_paths',
|
method: 'get_paths',
|
||||||
@@ -81,6 +87,31 @@ return baseclass.extend({
|
|||||||
return callRCInit('momo', 'restart');
|
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 () {
|
version: function () {
|
||||||
return callMomoVersion();
|
return callMomoVersion();
|
||||||
},
|
},
|
||||||
@@ -138,12 +169,12 @@ return baseclass.extend({
|
|||||||
|
|
||||||
clearAppLog: async function () {
|
clearAppLog: async function () {
|
||||||
const paths = await this.getPaths();
|
const paths = await this.getPaths();
|
||||||
return fs.write(paths.app_log_path);
|
return this.writefile(paths.app_log_path);
|
||||||
},
|
},
|
||||||
|
|
||||||
clearCoreLog: async function () {
|
clearCoreLog: async function () {
|
||||||
const paths = await this.getPaths();
|
const paths = await this.getPaths();
|
||||||
return fs.write(paths.core_log_path);
|
return this.writefile(paths.core_log_path);
|
||||||
},
|
},
|
||||||
|
|
||||||
debug: function () {
|
debug: function () {
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ return view.extend({
|
|||||||
o.wrap = false;
|
o.wrap = false;
|
||||||
o.write = function (section_id, formvalue) {
|
o.write = function (section_id, formvalue) {
|
||||||
const path = m.lookupOption('_file', section_id)[0].formvalue(section_id);
|
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) {
|
o.remove = function (section_id) {
|
||||||
const path = m.lookupOption('_file', section_id)[0].formvalue(section_id);
|
const path = m.lookupOption('_file', section_id)[0].formvalue(section_id);
|
||||||
return fs.write(path);
|
return momo.writefile(path);
|
||||||
};
|
};
|
||||||
|
|
||||||
return m.render();
|
return m.render();
|
||||||
|
|||||||
Reference in new issue
Block a user