delete log file when exceeding 200mb
parent
7bddee230f
commit
bfa02a00a7
11
index.js
11
index.js
|
|
@ -2,6 +2,10 @@
|
||||||
// helloHelper2 = require('./helper.js')
|
// helloHelper2 = require('./helper.js')
|
||||||
// for organizational proposes
|
// for organizational proposes
|
||||||
// let g_sdapi_path = 'sdapi'
|
// 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_version = 'v1.2.6'
|
||||||
let g_sd_url = 'http://127.0.0.1:7860'
|
let g_sd_url = 'http://127.0.0.1:7860'
|
||||||
let g_online_data_url =
|
let g_online_data_url =
|
||||||
|
|
@ -73,11 +77,12 @@ const {
|
||||||
} = require('./typescripts/dist/bundle')
|
} = require('./typescripts/dist/bundle')
|
||||||
|
|
||||||
const io = require('./utility/io')
|
const io = require('./utility/io')
|
||||||
const _log = console.log
|
|
||||||
const _warn = console.warn
|
|
||||||
const _error = console.error
|
|
||||||
const should_log = true
|
const should_log = true
|
||||||
if (should_log) {
|
if (should_log) {
|
||||||
|
setInterval(async () => {
|
||||||
|
await io.deleteFileIfLargerThan('log.txt', 200)
|
||||||
|
}, 2 * 60 * 1000)
|
||||||
window.addEventListener('error', (event) => {
|
window.addEventListener('error', (event) => {
|
||||||
const [a, b, c, d, e] = [1, 2, 3, 4, 5]
|
const [a, b, c, d, e] = [1, 2, 3, 4, 5]
|
||||||
console.log(`message: ${a}`)
|
console.log(`message: ${a}`)
|
||||||
|
|
|
||||||
|
|
@ -1256,6 +1256,31 @@ async function convertGrayscaleToMonochrome(base64) {
|
||||||
console.warn(e)
|
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 = {
|
module.exports = {
|
||||||
IO,
|
IO,
|
||||||
snapShotLayerExe,
|
snapShotLayerExe,
|
||||||
|
|
@ -1281,4 +1306,5 @@ module.exports = {
|
||||||
getUniqueDocumentId,
|
getUniqueDocumentId,
|
||||||
getImageSize,
|
getImageSize,
|
||||||
convertGrayscaleToMonochrome,
|
convertGrayscaleToMonochrome,
|
||||||
|
deleteFileIfLargerThan,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue