summaryrefslogtreecommitdiff
path: root/cookies-storage.js
diff options
context:
space:
mode:
Diffstat (limited to 'cookies-storage.js')
-rw-r--r--cookies-storage.js50
1 files changed, 0 insertions, 50 deletions
diff --git a/cookies-storage.js b/cookies-storage.js
deleted file mode 100644
index 8c9231b..0000000
--- a/cookies-storage.js
+++ /dev/null
@@ -1,50 +0,0 @@
-const fs = require('fs').promises
-
-let storageFileName = null
-
-async function exists(path) {
- try {
- await fs.access(path)
- return true
- } catch {
- return false
- }
-}
-
-module.exports = {
- async save(newCookies) {
- let currentCookies = await this.get()
- if (currentCookies.length) {
- for (let newCookie of newCookies) {
- if (!currentCookies.length)
- break
- let i = currentCookies.findIndex((c) => {
- return c.domain === newCookie.domain
- && c.path === newCookie.path
- && c.name === newCookie.name
- })
- if (i !== -1)
- currentCookies.splice(i, 1)
- }
- }
- currentCookies.push(...newCookies)
- // console.log('[cookies.save] saving cookies:', currentCookies)
- await fs.writeFile(storageFileName, JSON.stringify(currentCookies, null, 2), 'utf-8')
- },
-
- async get() {
- if (!(await exists(storageFileName)))
- return []
-
- try {
- return JSON.parse(await fs.readFile(storageFileName, 'utf-8'))
- } catch (e) {
- console.error(e)
- return []
- }
- },
-
- setFileName(name) {
- storageFileName = name
- }
-}; \ No newline at end of file