feat: implement user subscription status checking logic

This commit is contained in:
thecodrr
2020-11-11 15:43:09 +05:00
parent c30856edc5
commit 59cf0cce8f
6 changed files with 45 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import SparkMD5 from "spark-md5";
import { sendCheckUserStatusEvent } from "../common.js";
const invalidKeys = ["user", "t", "lastBackupTime"];
const validTypes = ["mobile", "web", "node"];
@@ -21,8 +22,12 @@ export default class Backup {
* @param {boolean} encrypt
*/
async export(type, encrypt = false) {
if (encrypt && !(await sendCheckUserStatusEvent("backup:encrypt"))) return;
if (!validTypes.some((t) => t === type))
throw new Error("Invalid type. It must be one of 'mobile' or 'web'.");
throw new Error(
"Invalid type. It must be one of 'mobile' or 'web' or 'node'."
);
const keys = (await this._db.context.getAllKeys()).filter(
(key) => !invalidKeys.some((t) => t === key)