import axios from "npm:axios";
import FormData from "npm:form-data";
const config = {
file: '/var/log/rclone/backup-log-$(date +"%d-%m-%Y").txt',
token: "TOKEN",
endpoint: "LINK"
};
async function getFile() {
const process = Deno.run({
cmd: ["bash", "-c", "echo " + config.file],
stdout: "piped",
});
const output = await process.output();
const outStr = new TextDecoder().decode(output);
process.close();
return outStr;
}
async function getName() {
const process = Deno.run({
cmd: ["bash", "-c", "echo backup-log-$(date +\"%d-%m-%Y\").txt"],
stdout: "piped",
});
const output = await process.output();
const outStr = new TextDecoder().decode(output);
process.close();
return outStr;
}
async function post() {
const fileName = (await getFile()).replace("\n", "");
try {
const file = Deno.readTextFileSync(fileName);
const name = (await getName()).replace("\n", "");
const form = new FormData();
form.append("token", config.token);
form.append("file", file, name);
axios
.request(config.endpoint, {
method: "POST",
maxBodyLength: Infinity,
headers: {
...form.getHeaders(),
},
data: form,
})
.then((response) => console.log(response.data));
} catch (e) {
console.log(e);
console.error("An error occured. This is normally due to the backup log file missing. Please confirm the log actually generated.");
Deno.exit(1);
}
}
post();
import axios from "npm:axios";
import FormData from "npm:form-data";
const config = {
file: '/var/log/rclone/backup-log-$(date +"%d-%m-%Y").txt',
token: "TOKEN",
endpoint: "LINK"
};
async function getFile() {
const process = Deno.run({
cmd: ["bash", "-c", "echo " + config.file],
stdout: "piped",
});
const output = await process.output();
const outStr = new TextDecoder().decode(output);
process.close();
return outStr;
}
async function getName() {
const process = Deno.run({
cmd: ["bash", "-c", "echo backup-log-$(date +\"%d-%m-%Y\").txt"],
stdout: "piped",
});
const output = await process.output();
const outStr = new TextDecoder().decode(output);
process.close();
return outStr;
}
async function post() {
const fileName = (await getFile()).replace("\n", "");
try {
const file = Deno.readTextFileSync(fileName);
const name = (await getName()).replace("\n", "");
const form = new FormData();
form.append("token", config.token);
form.append("file", file, name);
axios
.request(config.endpoint, {
method: "POST",
maxBodyLength: Infinity,
headers: {
...form.getHeaders(),
},
data: form,
})
.then((response) => console.log(response.data));
} catch (e) {
console.log(e);
console.error("An error occured. This is normally due to the backup log file missing. Please confirm the log actually generated.");
Deno.exit(1);
}
}
post();