diff --git a/index.js b/index.js index bf55e03..3d7e9b6 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,10 @@ // helloHelper2 = require('./helper.js') // for organizational proposes // let g_sdapi_path = 'sdapi' +const _log = console.log +const _warn = console.warn +const _error = console.error + let g_version = 'v1.2.6' let g_sd_url = 'http://127.0.0.1:7860' let g_online_data_url = @@ -73,11 +77,12 @@ const { } = require('./typescripts/dist/bundle') const io = require('./utility/io') -const _log = console.log -const _warn = console.warn -const _error = console.error + const should_log = true if (should_log) { + setInterval(async () => { + await io.deleteFileIfLargerThan('log.txt', 200) + }, 2 * 60 * 1000) window.addEventListener('error', (event) => { const [a, b, c, d, e] = [1, 2, 3, 4, 5] console.log(`message: ${a}`) diff --git a/utility/io.js b/utility/io.js index 40e559d..214e603 100644 --- a/utility/io.js +++ b/utility/io.js @@ -1256,6 +1256,31 @@ async function convertGrayscaleToMonochrome(base64) { console.warn(e) } } + +async function deleteFileIfLargerThan(file_name, size_mb = 200) { + // const file = await fs.getEntry('path/to/file.txt') + try { + const plugin_folder = await fs.getDataFolder() + try { + var file = await plugin_folder.getEntry(file_name) + } catch (e) { + _warn(e) + } + if (file) { + const contents = await file.read({ format: storage.formats.binary }) + // storage.formats.utf8 + const fileSizeInBytes = contents.byteLength + const fileSizeInMegabytes = fileSizeInBytes / (1024 * 1024) + + if (fileSizeInMegabytes > size_mb) { + await fs.removeEntry(file) + } + } + } catch (e) { + // console.warn(e) + _warn(e) + } +} module.exports = { IO, snapShotLayerExe, @@ -1281,4 +1306,5 @@ module.exports = { getUniqueDocumentId, getImageSize, convertGrayscaleToMonochrome, + deleteFileIfLargerThan, }