🔨 Remove moment

This commit is contained in:
SebClem 2022-05-02 11:39:59 +02:00
parent 1dcc52144a
commit 065bfae223
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
9 changed files with 39 additions and 47 deletions

View File

@ -19,7 +19,7 @@
"got": "12.0.4",
"http-errors": "~2.0.0",
"jquery": "^3.6.0",
"moment": "^2.29.3",
"luxon": "^2.3.2",
"morgan": "~1.10.0",
"webdav": "^4.8.0",
"winston": "^3.6.0"

View File

@ -1,5 +1,4 @@
import express from 'express';
import moment from "moment";
import * as statusTools from "../tools/status.js"
import webdav from "../tools/webdavTools.js"
import * as settingsTools from "../tools/settingsTools.js"
@ -8,6 +7,7 @@ import * as hassioApiTools from "../tools/hassioApiTools.js"
import { humanFileSize } from "../tools/toolbox.js";
import cronTools from "../tools/cronTools.js"
import logger from "../config/winston.js"
import {DateTime} from "luxon";
var router = express.Router();
@ -21,14 +21,10 @@ router.get("/formated-local-snap", function (req, res, next) {
hassioApiTools.getSnapshots()
.then((snaps) => {
snaps.sort((a, b) => {
if (moment(a.date).isBefore(moment(b.date))) {
return 1;
} else {
return -1;
}
return a.date < b.date ? 1 : -1
});
res.render("localSnaps", { snaps: snaps, moment: moment });
res.render("localSnaps", { snaps: snaps, DateTime: DateTime });
})
.catch((err) => {
logger.error(err);
@ -47,17 +43,17 @@ router.get("/formated-backup-manual", function (req, res, next) {
.getFolderContent(webdav.getConf().back_dir + pathTools.manual)
.then((contents) => {
contents.sort((a, b) => {
if (moment(a.lastmod).isBefore(moment(b.lastmod))) return 1;
else return -1;
return a.date < b.date ? 1 : -1
});
//TODO Remove this when bug is fixed, etag contain '&quot;' at start and end ?
for (let backup of contents) {
backup.etag = backup.etag.replace(/&quot;/g, '');
}
res.render("backupSnaps", { backups: contents, moment: moment, humanFileSize: humanFileSize });
res.render("backupSnaps", { backups: contents, DateTime: DateTime, humanFileSize: humanFileSize });
})
.catch(() => {
res.send("");
.catch((err) => {
res.status(500)
res.send(err);
});
});
@ -71,17 +67,17 @@ router.get("/formated-backup-auto", function (req, res, next) {
.getFolderContent(url)
.then((contents) => {
contents.sort((a, b) => {
if (moment(a.lastmod).isBefore(moment(b.lastmod))) return 1;
else return -1;
return a.date < b.date ? 1 : -1
});
//TODO Remove this when bug is fixed, etag contain '&quot;' at start and end ?
for (let backup of contents) {
backup.etag = backup.etag.replace(/&quot;/g, '');
}
res.render("backupSnaps", { backups: contents, moment: moment, humanFileSize: humanFileSize });
res.render("backupSnaps", { backups: contents, DateTime: DateTime, humanFileSize: humanFileSize });
})
.catch(() => {
res.send("");
.catch((err) => {
res.status(500)
res.send(err);
});
});

View File

@ -68,7 +68,7 @@ class CronContainer {
updateNextDate() {
let date;
if (this.cronJob == null) date = null;
else date = this.cronJob.nextDate().format("MMM D, YYYY HH:mm");
else date = this.cronJob.nextDate().setLocale("en").toFormat("dd MMM yyyy, HH:mm");
let status = statusTools.getStatus();
status.next_backup = date;
statusTools.setStatus(status);

View File

@ -1,5 +1,5 @@
import fs from "fs"
import moment from "moment";
import stream from "stream"
import { promisify } from "util";
import got from "got";
@ -8,6 +8,7 @@ import * as statusTools from "../tools/status.js"
import * as settingsTools from "../tools/settingsTools.js"
import logger from "../config/winston.js"
import {DateTime} from "luxon";
const pipeline = promisify(stream.pipeline);
@ -300,9 +301,7 @@ function clean() {
return;
}
snaps.sort((a, b) => {
if (moment(a.date).isBefore(moment(b.date))) return 1;
else
return -1;
return a.date < b.date ? 1 : -1
});
let toDel = snaps.slice(limit);
for (let i of toDel) {

View File

@ -1,8 +1,8 @@
import fs from "fs"
import moment from "moment";
import { CronJob } from "cron";
import logger from "../config/winston.js"
import {DateTime} from "luxon";
const settingsPath = "/data/backup_conf.json";
@ -170,10 +170,10 @@ function getFormatedName(is_manual, ha_version) {
template = template.replace("{type_low}", is_manual ? "manual" : "auto");
template = template.replace("{type}", is_manual ? "Manual" : "Auto");
template = template.replace("{ha_version}", ha_version);
let mmt = moment();
template = template.replace("{hour_12}", mmt.format("hhmmA"));
template = template.replace("{hour}", mmt.format("HHmm"));
template = template.replace("{date}", mmt.format("YYYY-MM-DD"));
const now = DateTime.now().setLocale('en');
template = template.replace("{hour_12}", now.toFormat("hhmma"));
template = template.replace("{hour}", now.toFormat("HHmm"));
template = template.replace("{date}", now.toFormat("yyyy-MM-dd"));
return template;
}

View File

@ -1,6 +1,5 @@
import { createClient } from "webdav";
import fs from "fs"
import moment from "moment";
import https from "https"
import path from "path";
import got from "got";
@ -12,6 +11,7 @@ import * as settingsTools from "../tools/settingsTools.js"
import * as pathTools from "../tools/pathTools.js"
import * as hassioApiTools from "../tools/hassioApiTools.js"
import logger from "../config/winston.js"
import {DateTime} from "luxon";
const endpoint = "/remote.php/webdav";
const configPath = "/data/webdav_conf.json";
@ -258,7 +258,7 @@ class WebdavTools {
status.progress = -1;
status.message = null;
status.error_code = null;
status.last_backup = moment().format("MMM D, YYYY HH:mm");
status.last_backup = DateTime.now().toFormat("dd MMM yyyy, HH:mm")
statusTools.setStatus(status);
cleanTempFolder();
let autoCleanCloud = settingsTools.getSettings().auto_clean_backup;
@ -316,7 +316,7 @@ class WebdavTools {
logger.info("Downloading backup...");
if (!fs.existsSync("./temp/"))
fs.mkdirSync("./temp/");
let tmpFile = `./temp/restore_${moment().format("MMM-DD-YYYY_HH_mm")}.tar`;
let tmpFile = `./temp/restore_${DateTime.now().toFormat("MMM-dd-yyyy_HH_mm")}.tar`;
let stream = fs.createWriteStream(tmpFile);
let conf = this.getConf();
let options = {
@ -383,10 +383,7 @@ class WebdavTools {
return;
}
contents.sort((a, b) => {
if (moment(a.lastmod).isBefore(moment(b.lastmod)))
return 1;
else
return -1;
return a.date < b.date ? 1 : -1
});
let toDel = contents.slice(limit);

View File

@ -8,7 +8,7 @@
data-bs-target="#modal-<%= backups[index].etag %>">
<%= backups[index].basename %>
<span class="badge bg-primary">
<%= moment(backups[index].lastmod).format('MMM D, YYYY HH:mm') %>
<%= DateTime.fromRFC2822(backups[index].lastmod).toFormat("MMM dd, yyyy HH:mm") %>
</span>
</a>
@ -34,7 +34,7 @@
<label for="date-<%= backups[index].etag %>" class="form-label">Date</label>
<input disabled type="text" class="form-control bg-secondary border-dark text-accent"
id="date-<%= backups[index].etag %>"
value="<%= moment(backups[index].lastmod).format('MMM D, YYYY HH:mm') %>"/>
value="<%= DateTime.fromRFC2822(backups[index].lastmod).toFormat("MMM dd, yyyy HH:mm") %>"/>
</div>
<div class="input-field col s12">

View File

@ -8,7 +8,7 @@
data-bs-target="#modal-<%= snaps[index].slug %>">
<%= snaps[index].name ? snaps[index].name : snaps[index].slug %>
<span class="badge bg-primary">
<%= moment(snaps[index].date).format('MMM D, YYYY HH:mm') %>
<%= DateTime.fromISO(snaps[index].date).toFormat("MMM dd, yyyy HH:mm") %>
</span>
</a>
@ -32,7 +32,7 @@
<div class="mb-3">
<label for="date-<%= snaps[index].slug %>" class="form-label">Date</label>
<input disabled type="text" class="form-control bg-secondary border-dark text-accent" id="date-<%= snaps[index].slug %>"
value="<%= moment(snaps[index].date).format('MMM D, YYYY HH:mm') %>"/>
value="<%= DateTime.fromISO(snaps[index].date).setLocale("en").toFormat("MMM dd, yyyy HH:mm") %>"/>
</div>

View File

@ -937,6 +937,13 @@ __metadata:
languageName: node
linkType: hard
"luxon@npm:^2.3.2":
version: 2.3.2
resolution: "luxon@npm:2.3.2"
checksum: ba4f9daa56d03771c2ddf00e3bf996ec7937badfdc2f85f5b58d63c75bb511369b3316f54ab9ce5ab42bfc9118513971f6599128529b68620b876a4b7c16570b
languageName: node
linkType: hard
"md5@npm:^2.3.0":
version: 2.3.0
resolution: "md5@npm:2.3.0"
@ -1026,13 +1033,6 @@ __metadata:
languageName: node
linkType: hard
"moment@npm:^2.29.3":
version: 2.29.3
resolution: "moment@npm:2.29.3"
checksum: 2e780e36d9a1823c08a1b6313cbb08bd01ecbb2a9062095820a34f42c878991ccba53abaa6abb103fd5c01e763724f295162a8c50b7e95b4f1c992ef0772d3f0
languageName: node
linkType: hard
"morgan@npm:~1.10.0":
version: 1.10.0
resolution: "morgan@npm:1.10.0"
@ -1097,7 +1097,7 @@ __metadata:
got: 12.0.4
http-errors: ~2.0.0
jquery: ^3.6.0
moment: ^2.29.3
luxon: ^2.3.2
morgan: ~1.10.0
webdav: ^4.8.0
winston: ^3.6.0