You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
import dotenv from 'dotenv'; |
|
dotenv.config(); |
|
import { environmentVariableValidation } from './validation.js'; |
|
import { |
|
getBackups, |
|
exportDatabase, |
|
getFileToken, |
|
downloadBackup, |
|
} from './apiHelper.js'; |
|
import { backupTimeDiff } from './backupHelper.js'; |
|
|
|
const { value, error } = environmentVariableValidation({ |
|
baseUrl: process.env.BASE_URL, |
|
access_token: process.env.TOKEN, |
|
}); |
|
|
|
try { |
|
if (error) throw error?.details[0]?.message; |
|
} catch (error) { |
|
console.error(`[ERROR] ${error}`); |
|
process.exit(0); |
|
} |
|
|
|
const Main = async () => { |
|
await new Promise((resolve) => setTimeout(resolve, 2000)); |
|
const backups = await getBackups(); |
|
const [lastBackup] = backups?.imports; |
|
const secondsDiff = backupTimeDiff(lastBackup?.date); |
|
// TODO: actually make this timer like idk 1 day or something |
|
if (secondsDiff >= 20) { |
|
const { export_path } = await exportDatabase('mealieDb'); |
|
console.log(`database backed up: ${export_path}`); |
|
const { fileToken } = await getFileToken(lastBackup?.name); |
|
await downloadBackup(fileToken, lastBackup?.name); |
|
} |
|
await Main(secondsDiff); |
|
}; |
|
|
|
Main();
|
|
|