mirror of
https://github.com/imputnet/cobalt.git
synced 2025-01-16 03:45:14 +00:00
api/cookies: trigger cookie load from api entrypoint
This commit is contained in:
parent
af50852815
commit
5a5a65b373
|
@ -18,6 +18,7 @@ import { friendlyServiceName } from "../processing/service-alias.js";
|
|||
import { verifyStream, getInternalStream } from "../stream/manage.js";
|
||||
import { createResponse, normalizeRequest, getIP } from "../processing/request.js";
|
||||
import * as APIKeys from "../security/api-keys.js";
|
||||
import * as Cookies from "../processing/cookie/manager.js";
|
||||
|
||||
const git = {
|
||||
branch: await getBranch(),
|
||||
|
@ -348,6 +349,10 @@ export const runAPI = (express, app, __dirname) => {
|
|||
APIKeys.setup(env.apiKeyURL);
|
||||
}
|
||||
|
||||
if (env.cookiePath) {
|
||||
Cookies.setup(env.cookiePath);
|
||||
}
|
||||
|
||||
app.listen(env.apiPort, env.listenAddress, () => {
|
||||
console.log(`\n` +
|
||||
Bright(Cyan("cobalt ")) + Bright("API ^ω^") + "\n" +
|
||||
|
|
|
@ -1,26 +1,20 @@
|
|||
import Cookie from './cookie.js';
|
||||
import { readFile, writeFile } from 'fs/promises';
|
||||
import { parse as parseSetCookie, splitCookiesString } from 'set-cookie-parser';
|
||||
import { env } from '../../config.js';
|
||||
|
||||
const WRITE_INTERVAL = 60000,
|
||||
cookiePath = env.cookiePath,
|
||||
COUNTER = Symbol('counter');
|
||||
|
||||
let cookies = {}, dirty = false, intervalId;
|
||||
|
||||
const setup = async () => {
|
||||
export const setup = async (cookiePath) => {
|
||||
try {
|
||||
if (!cookiePath) return;
|
||||
|
||||
cookies = await readFile(cookiePath, 'utf8');
|
||||
cookies = JSON.parse(cookies);
|
||||
intervalId = setInterval(writeChanges, WRITE_INTERVAL)
|
||||
intervalId = setInterval(writeChanges, WRITE_INTERVAL);
|
||||
} catch { /* no cookies for you */ }
|
||||
}
|
||||
|
||||
setup();
|
||||
|
||||
function writeChanges() {
|
||||
if (!dirty) return;
|
||||
dirty = false;
|
||||
|
|
Loading…
Reference in a new issue