Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: add trash cleanup duration settings

ammarahm-eda07c8b9e11ca
diff --git a/packages/core/api/settings.js b/packages/core/api/settings.js
index 2e979a068..aee33aaf9 100644
--- a/packages/core/api/settings.js
+++ b/packages/core/api/settings.js
@@ -124,6 +124,18 @@ class Settings {
getAlias(id) {
return this._settings.aliases[id];
}
+ /**
+ * Setting to -1 means never clear trash.
+ * @param {7 | 30 | 365 | -1} time
+ */
+ async setTrashCleanupInterval(time) {
+ this._settings.trashCleanupInterval = time;
+ await this._saveSettings();
+ }
+
+ getTrashCleanupInterval() {
+ return this._settings.trashCleanupInterval || 7;
+ }
_initSettings(settings) {
this._settings = {
@@ -134,6 +146,7 @@ class Settings {
aliases: {},
dateModified: 0,
dateCreated: 0,
+ trashCleanupInterval: 7,
...(settings || {})
};
}
diff --git a/packages/core/collections/trash.js b/packages/core/collections/trash.js
index 3f40eda0d..7ef91aab1 100644
--- a/packages/core/collections/trash.js
+++ b/packages/core/collections/trash.js
@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import dayjs from "dayjs";
-import Config from "../../../apps/web/src/utils/config";
export default class Trash {
/**
@@ -39,13 +38,12 @@ export default class Trash {
async cleanup() {
const now = dayjs().unix();
- const duration = trashDuration(Config.get("trashDuration", 0));
- if (duration)
- for (const item of this.all) {
- if (dayjs(item.dateDeleted).add(duration, "days").unix() > now)
- continue;
- await this.delete(item.id);
- }
+ const duration = this._db.settings.getTrashCleanupInterval();
+ if (duration === -1 || !duration) return;
+ for (const item of this.all) {
+ if (dayjs(item.dateDeleted).add(duration, "days").unix() > now) continue;
+ await this.delete(item.id);
+ }
}
get all() {