From 78debbe045319b49a291af037266be52901fd472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A7=81Ash=C3=BB=EA=A7=82?= <30575805+Ashu11-A@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:44:23 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9D=8C=20Remove=20dotenv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 12 ------------ package.json | 1 - src/class/crypt.ts | 11 +++++------ src/class/pages.ts | 1 - 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index daa3b86..fd257ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,6 @@ "cloudflare": "^3.4.0", "country-code-to-flag-emoji": "^1.3.3", "crypto-js": "^4.2.0", - "dotenv": "^16.4.5", "enmap": "^6.0.2", "enquirer": "^2.4.1", "glob": "^10.4.3", @@ -5771,17 +5770,6 @@ "node": ">=8" } }, - "node_modules/dotenv": { - "version": "16.4.5", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", - "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://dotenvx.com" - } - }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", diff --git a/package.json b/package.json index 74d25d6..85d3404 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,6 @@ "cloudflare": "^3.4.0", "country-code-to-flag-emoji": "^1.3.3", "crypto-js": "^4.2.0", - "dotenv": "^16.4.5", "enmap": "^6.0.2", "enquirer": "^2.4.1", "glob": "^10.4.3", diff --git a/src/class/crypt.ts b/src/class/crypt.ts index f48108a..be76310 100644 --- a/src/class/crypt.ts +++ b/src/class/crypt.ts @@ -8,7 +8,6 @@ import { passwordStrength } from 'check-password-strength' import { watch } from 'chokidar' import { randomBytes } from 'crypto' import CryptoJS from 'crypto-js' -import 'dotenv/config' import { readFile, rm, writeFile } from 'fs/promises' import forge from 'node-forge' import { join } from 'path' @@ -19,7 +18,7 @@ export const credentials = new Map() export class Crypt { async checker () { - if (!(await exists(join(rootPath, '..', '.env'))) && process.env?.token === undefined) await this.create() + if (!(await exists(join(rootPath, '..', '.env'))) && await this.getToken() === undefined) await this.create() if (!(await exists(join(rootPath, '..', 'privateKey.pem'))) || !(await exists(join(rootPath, '..', 'publicKey.pem')))) await this.genKeys() for (const path of ['.key', '.hash']) { @@ -102,8 +101,8 @@ export class Crypt { } } - getToken (): string | undefined { - let token = process.env.token + async getToken (): Promise { + let token = (await readFile(join(rootPath, '..', '.env'), { encoding: 'utf-8' })).split('=')[1] if (token === undefined) token = credentials.get('token') as string @@ -129,7 +128,7 @@ export class Crypt { } async read (ephemeral?: boolean): Promise { - const token = this.getToken() + const token = await this.getToken() if (token === undefined) return const existKey = await exists(join(rootPath, '..', '.key')) if (!existKey) return undefined @@ -162,7 +161,7 @@ export class Crypt { async write (value: Record | string | object) { if (!isJson(value)) throw new Error(i18('error.invalid', { element: '.key' })) - const token = this.getToken() + const token = await this.getToken() if (token === undefined) return const data = Object.assign(await this.read(true) ?? {}, value) diff --git a/src/class/pages.ts b/src/class/pages.ts index f3aff9c..0b8bbb5 100755 --- a/src/class/pages.ts +++ b/src/class/pages.ts @@ -1,7 +1,6 @@ import { page, rootPath } from '@/index.js' import { PageProps, PageTypes } from '@/types/page.js' import chalk from 'chalk' -import 'dotenv/config' import { glob } from 'glob' import ora from 'ora' import { join } from 'path'