best way to save what you love
Svelte collaborationdownloaderinstagramjavascriptmusicredditsocial-mediasoundcloudsveltetiktoktwittertypescriptvideovimeovkwebappyoutubeyoutube-downloader
api/cookie/manager: pass `cookiePath` to `writeChanges()`
wukko7c516c04686a
diff --git a/api/src/processing/cookie/manager.js b/api/src/processing/cookie/manager.jsindex 060f8695..02eecfda 100644--- a/api/src/processing/cookie/manager.js+++ b/api/src/processing/cookie/manager.js@@ -1,18 +1,28 @@import Cookie from './cookie.js';+import { readFile, writeFile } from 'fs/promises';-import { parse as parseSetCookie, splitCookiesString } from 'set-cookie-parser';import { Green, Yellow } from '../../misc/console-text.js';+import { parse as parseSetCookie, splitCookiesString } from 'set-cookie-parser';const WRITE_INTERVAL = 60000,COUNTER = Symbol('counter');let cookies = {}, dirty = false, intervalId;+function writeChanges(cookiePath) {+ if (!dirty) return;+ dirty = false;++ writeFile(cookiePath, JSON.stringify(cookies, null, 4)).catch(() => {+ clearInterval(intervalId)+ })+}+export const setup = async (cookiePath) => {try {cookies = await readFile(cookiePath, 'utf8');cookies = JSON.parse(cookies);- intervalId = setInterval(writeChanges, WRITE_INTERVAL);+ intervalId = setInterval(() => writeChanges(cookiePath), WRITE_INTERVAL);console.log(`${Green('[✓]')} cookies loaded successfully!`)} catch(e) {console.error(`${Yellow('[!]')} failed to load cookies.`);@@ -20,15 +30,6 @@ export const setup = async (cookiePath) => {}}-function writeChanges() {- if (!dirty) return;- dirty = false;-- writeFile(cookiePath, JSON.stringify(cookies, null, 4)).catch(() => {- clearInterval(intervalId)- })-}-export function getCookie(service) {if (!cookies[service] || !cookies[service].length) return;@@ -46,6 +47,11 @@ export function getCookie(service) {return cookies[service][n]}+export function updateCookieValues(cookie, values) {+ cookie.set(values);+ if (Object.keys(values).length) dirty = true+}+export function updateCookie(cookie, headers) {if (!cookie) return;@@ -58,8 +64,3 @@ export function updateCookie(cookie, headers) {parsed.filter(c => !c.expires || c.expires > new Date()).forEach(c => values[c.name] = c.value);updateCookieValues(cookie, values);}--export function updateCookieValues(cookie, values) {- cookie.set(values);- if (Object.keys(values).length) dirty = true-}