Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit 065bfae

Browse files
committed
🔨 Remove moment
1 parent 1dcc521 commit 065bfae

File tree

9 files changed

+39
-47
lines changed

9 files changed

+39
-47
lines changed

nextcloud_backup/rootfs/opt/nextcloud_backup/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"got": "12.0.4",
2020
"http-errors": "~2.0.0",
2121
"jquery": "^3.6.0",
22-
"moment": "^2.29.3",
22+
"luxon": "^2.3.2",
2323
"morgan": "~1.10.0",
2424
"webdav": "^4.8.0",
2525
"winston": "^3.6.0"

nextcloud_backup/rootfs/opt/nextcloud_backup/routes/api.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import express from 'express';
2-
import moment from "moment";
32
import * as statusTools from "../tools/status.js"
43
import webdav from "../tools/webdavTools.js"
54
import * as settingsTools from "../tools/settingsTools.js"
@@ -8,6 +7,7 @@ import * as hassioApiTools from "../tools/hassioApiTools.js"
87
import { humanFileSize } from "../tools/toolbox.js";
98
import cronTools from "../tools/cronTools.js"
109
import logger from "../config/winston.js"
10+
import {DateTime} from "luxon";
1111

1212
var router = express.Router();
1313

@@ -21,14 +21,10 @@ router.get("/formated-local-snap", function (req, res, next) {
2121
hassioApiTools.getSnapshots()
2222
.then((snaps) => {
2323
snaps.sort((a, b) => {
24-
if (moment(a.date).isBefore(moment(b.date))) {
25-
return 1;
26-
} else {
27-
return -1;
28-
}
24+
return a.date < b.date ? 1 : -1
2925
});
3026

31-
res.render("localSnaps", { snaps: snaps, moment: moment });
27+
res.render("localSnaps", { snaps: snaps, DateTime: DateTime });
3228
})
3329
.catch((err) => {
3430
logger.error(err);
@@ -47,17 +43,17 @@ router.get("/formated-backup-manual", function (req, res, next) {
4743
.getFolderContent(webdav.getConf().back_dir + pathTools.manual)
4844
.then((contents) => {
4945
contents.sort((a, b) => {
50-
if (moment(a.lastmod).isBefore(moment(b.lastmod))) return 1;
51-
else return -1;
46+
return a.date < b.date ? 1 : -1
5247
});
5348
//TODO Remove this when bug is fixed, etag contain '&quot;' at start and end ?
5449
for (let backup of contents) {
5550
backup.etag = backup.etag.replace(/&quot;/g, '');
5651
}
57-
res.render("backupSnaps", { backups: contents, moment: moment, humanFileSize: humanFileSize });
52+
res.render("backupSnaps", { backups: contents, DateTime: DateTime, humanFileSize: humanFileSize });
5853
})
59-
.catch(() => {
60-
res.send("");
54+
.catch((err) => {
55+
res.status(500)
56+
res.send(err);
6157
});
6258
});
6359

@@ -71,17 +67,17 @@ router.get("/formated-backup-auto", function (req, res, next) {
7167
.getFolderContent(url)
7268
.then((contents) => {
7369
contents.sort((a, b) => {
74-
if (moment(a.lastmod).isBefore(moment(b.lastmod))) return 1;
75-
else return -1;
70+
return a.date < b.date ? 1 : -1
7671
});
7772
//TODO Remove this when bug is fixed, etag contain '&quot;' at start and end ?
7873
for (let backup of contents) {
7974
backup.etag = backup.etag.replace(/&quot;/g, '');
8075
}
81-
res.render("backupSnaps", { backups: contents, moment: moment, humanFileSize: humanFileSize });
76+
res.render("backupSnaps", { backups: contents, DateTime: DateTime, humanFileSize: humanFileSize });
8277
})
83-
.catch(() => {
84-
res.send("");
78+
.catch((err) => {
79+
res.status(500)
80+
res.send(err);
8581
});
8682
});
8783

nextcloud_backup/rootfs/opt/nextcloud_backup/tools/cronTools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CronContainer {
6868
updateNextDate() {
6969
let date;
7070
if (this.cronJob == null) date = null;
71-
else date = this.cronJob.nextDate().format("MMM D, YYYY HH:mm");
71+
else date = this.cronJob.nextDate().setLocale("en").toFormat("dd MMM yyyy, HH:mm");
7272
let status = statusTools.getStatus();
7373
status.next_backup = date;
7474
statusTools.setStatus(status);

nextcloud_backup/rootfs/opt/nextcloud_backup/tools/hassioApiTools.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from "fs"
2-
import moment from "moment";
2+
33
import stream from "stream"
44
import { promisify } from "util";
55
import got from "got";
@@ -8,6 +8,7 @@ import * as statusTools from "../tools/status.js"
88
import * as settingsTools from "../tools/settingsTools.js"
99

1010
import logger from "../config/winston.js"
11+
import {DateTime} from "luxon";
1112

1213
const pipeline = promisify(stream.pipeline);
1314

@@ -300,9 +301,7 @@ function clean() {
300301
return;
301302
}
302303
snaps.sort((a, b) => {
303-
if (moment(a.date).isBefore(moment(b.date))) return 1;
304-
else
305-
return -1;
304+
return a.date < b.date ? 1 : -1
306305
});
307306
let toDel = snaps.slice(limit);
308307
for (let i of toDel) {

nextcloud_backup/rootfs/opt/nextcloud_backup/tools/settingsTools.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import fs from "fs"
2-
import moment from "moment";
32
import { CronJob } from "cron";
43

54
import logger from "../config/winston.js"
5+
import {DateTime} from "luxon";
66

77
const settingsPath = "/data/backup_conf.json";
88

@@ -170,10 +170,10 @@ function getFormatedName(is_manual, ha_version) {
170170
template = template.replace("{type_low}", is_manual ? "manual" : "auto");
171171
template = template.replace("{type}", is_manual ? "Manual" : "Auto");
172172
template = template.replace("{ha_version}", ha_version);
173-
let mmt = moment();
174-
template = template.replace("{hour_12}", mmt.format("hhmmA"));
175-
template = template.replace("{hour}", mmt.format("HHmm"));
176-
template = template.replace("{date}", mmt.format("YYYY-MM-DD"));
173+
const now = DateTime.now().setLocale('en');
174+
template = template.replace("{hour_12}", now.toFormat("hhmma"));
175+
template = template.replace("{hour}", now.toFormat("HHmm"));
176+
template = template.replace("{date}", now.toFormat("yyyy-MM-dd"));
177177
return template;
178178
}
179179

nextcloud_backup/rootfs/opt/nextcloud_backup/tools/webdavTools.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createClient } from "webdav";
22
import fs from "fs"
3-
import moment from "moment";
43
import https from "https"
54
import path from "path";
65
import got from "got";
@@ -12,6 +11,7 @@ import * as settingsTools from "../tools/settingsTools.js"
1211
import * as pathTools from "../tools/pathTools.js"
1312
import * as hassioApiTools from "../tools/hassioApiTools.js"
1413
import logger from "../config/winston.js"
14+
import {DateTime} from "luxon";
1515

1616
const endpoint = "/remote.php/webdav";
1717
const configPath = "/data/webdav_conf.json";
@@ -258,7 +258,7 @@ class WebdavTools {
258258
status.progress = -1;
259259
status.message = null;
260260
status.error_code = null;
261-
status.last_backup = moment().format("MMM D, YYYY HH:mm");
261+
status.last_backup = DateTime.now().toFormat("dd MMM yyyy, HH:mm")
262262
statusTools.setStatus(status);
263263
cleanTempFolder();
264264
let autoCleanCloud = settingsTools.getSettings().auto_clean_backup;
@@ -316,7 +316,7 @@ class WebdavTools {
316316
logger.info("Downloading backup...");
317317
if (!fs.existsSync("./temp/"))
318318
fs.mkdirSync("./temp/");
319-
let tmpFile = `./temp/restore_${moment().format("MMM-DD-YYYY_HH_mm")}.tar`;
319+
let tmpFile = `./temp/restore_${DateTime.now().toFormat("MMM-dd-yyyy_HH_mm")}.tar`;
320320
let stream = fs.createWriteStream(tmpFile);
321321
let conf = this.getConf();
322322
let options = {
@@ -383,10 +383,7 @@ class WebdavTools {
383383
return;
384384
}
385385
contents.sort((a, b) => {
386-
if (moment(a.lastmod).isBefore(moment(b.lastmod)))
387-
return 1;
388-
else
389-
return -1;
386+
return a.date < b.date ? 1 : -1
390387
});
391388

392389
let toDel = contents.slice(limit);

nextcloud_backup/rootfs/opt/nextcloud_backup/views/backupSnaps.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
data-bs-target="#modal-<%= backups[index].etag %>">
99
<%= backups[index].basename %>
1010
<span class="badge bg-primary">
11-
<%= moment(backups[index].lastmod).format('MMM D, YYYY HH:mm') %>
11+
<%= DateTime.fromRFC2822(backups[index].lastmod).toFormat("MMM dd, yyyy HH:mm") %>
1212
</span>
1313
</a>
1414
@@ -34,7 +34,7 @@
3434
<label for="date-<%= backups[index].etag %>" class="form-label">Date</label>
3535
<input disabled type="text" class="form-control bg-secondary border-dark text-accent"
3636
id="date-<%= backups[index].etag %>"
37-
value="<%= moment(backups[index].lastmod).format('MMM D, YYYY HH:mm') %>"/>
37+
value="<%= DateTime.fromRFC2822(backups[index].lastmod).toFormat("MMM dd, yyyy HH:mm") %>"/>
3838
3939
</div>
4040
<div class="input-field col s12">

nextcloud_backup/rootfs/opt/nextcloud_backup/views/localSnaps.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
data-bs-target="#modal-<%= snaps[index].slug %>">
99
<%= snaps[index].name ? snaps[index].name : snaps[index].slug %>
1010
<span class="badge bg-primary">
11-
<%= moment(snaps[index].date).format('MMM D, YYYY HH:mm') %>
11+
<%= DateTime.fromISO(snaps[index].date).toFormat("MMM dd, yyyy HH:mm") %>
1212
</span>
1313
</a>
1414
@@ -32,7 +32,7 @@
3232
<div class="mb-3">
3333
<label for="date-<%= snaps[index].slug %>" class="form-label">Date</label>
3434
<input disabled type="text" class="form-control bg-secondary border-dark text-accent" id="date-<%= snaps[index].slug %>"
35-
value="<%= moment(snaps[index].date).format('MMM D, YYYY HH:mm') %>"/>
35+
value="<%= DateTime.fromISO(snaps[index].date).setLocale("en").toFormat("MMM dd, yyyy HH:mm") %>"/>
3636
3737
</div>
3838

nextcloud_backup/rootfs/opt/nextcloud_backup/yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,13 @@ __metadata:
937937
languageName: node
938938
linkType: hard
939939

940+
"luxon@npm:^2.3.2":
941+
version: 2.3.2
942+
resolution: "luxon@npm:2.3.2"
943+
checksum: ba4f9daa56d03771c2ddf00e3bf996ec7937badfdc2f85f5b58d63c75bb511369b3316f54ab9ce5ab42bfc9118513971f6599128529b68620b876a4b7c16570b
944+
languageName: node
945+
linkType: hard
946+
940947
"md5@npm:^2.3.0":
941948
version: 2.3.0
942949
resolution: "md5@npm:2.3.0"
@@ -1026,13 +1033,6 @@ __metadata:
10261033
languageName: node
10271034
linkType: hard
10281035

1029-
"moment@npm:^2.29.3":
1030-
version: 2.29.3
1031-
resolution: "moment@npm:2.29.3"
1032-
checksum: 2e780e36d9a1823c08a1b6313cbb08bd01ecbb2a9062095820a34f42c878991ccba53abaa6abb103fd5c01e763724f295162a8c50b7e95b4f1c992ef0772d3f0
1033-
languageName: node
1034-
linkType: hard
1035-
10361036
"morgan@npm:~1.10.0":
10371037
version: 1.10.0
10381038
resolution: "morgan@npm:1.10.0"
@@ -1097,7 +1097,7 @@ __metadata:
10971097
got: 12.0.4
10981098
http-errors: ~2.0.0
10991099
jquery: ^3.6.0
1100-
moment: ^2.29.3
1100+
luxon: ^2.3.2
11011101
morgan: ~1.10.0
11021102
webdav: ^4.8.0
11031103
winston: ^3.6.0

0 commit comments

Comments
 (0)