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 { verifyStream, getInternalStream } from "../stream/manage.js";
|
||||||
import { createResponse, normalizeRequest, getIP } from "../processing/request.js";
|
import { createResponse, normalizeRequest, getIP } from "../processing/request.js";
|
||||||
import * as APIKeys from "../security/api-keys.js";
|
import * as APIKeys from "../security/api-keys.js";
|
||||||
|
import * as Cookies from "../processing/cookie/manager.js";
|
||||||
|
|
||||||
const git = {
|
const git = {
|
||||||
branch: await getBranch(),
|
branch: await getBranch(),
|
||||||
|
@ -348,6 +349,10 @@ export const runAPI = (express, app, __dirname) => {
|
||||||
APIKeys.setup(env.apiKeyURL);
|
APIKeys.setup(env.apiKeyURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (env.cookiePath) {
|
||||||
|
Cookies.setup(env.cookiePath);
|
||||||
|
}
|
||||||
|
|
||||||
app.listen(env.apiPort, env.listenAddress, () => {
|
app.listen(env.apiPort, env.listenAddress, () => {
|
||||||
console.log(`\n` +
|
console.log(`\n` +
|
||||||
Bright(Cyan("cobalt ")) + Bright("API ^ω^") + "\n" +
|
Bright(Cyan("cobalt ")) + Bright("API ^ω^") + "\n" +
|
||||||
|
|
|
@ -1,26 +1,20 @@
|
||||||
import Cookie from './cookie.js';
|
import Cookie from './cookie.js';
|
||||||
import { readFile, writeFile } from 'fs/promises';
|
import { readFile, writeFile } from 'fs/promises';
|
||||||
import { parse as parseSetCookie, splitCookiesString } from 'set-cookie-parser';
|
import { parse as parseSetCookie, splitCookiesString } from 'set-cookie-parser';
|
||||||
import { env } from '../../config.js';
|
|
||||||
|
|
||||||
const WRITE_INTERVAL = 60000,
|
const WRITE_INTERVAL = 60000,
|
||||||
cookiePath = env.cookiePath,
|
|
||||||
COUNTER = Symbol('counter');
|
COUNTER = Symbol('counter');
|
||||||
|
|
||||||
let cookies = {}, dirty = false, intervalId;
|
let cookies = {}, dirty = false, intervalId;
|
||||||
|
|
||||||
const setup = async () => {
|
export const setup = async (cookiePath) => {
|
||||||
try {
|
try {
|
||||||
if (!cookiePath) return;
|
|
||||||
|
|
||||||
cookies = await readFile(cookiePath, 'utf8');
|
cookies = await readFile(cookiePath, 'utf8');
|
||||||
cookies = JSON.parse(cookies);
|
cookies = JSON.parse(cookies);
|
||||||
intervalId = setInterval(writeChanges, WRITE_INTERVAL)
|
intervalId = setInterval(writeChanges, WRITE_INTERVAL);
|
||||||
} catch { /* no cookies for you */ }
|
} catch { /* no cookies for you */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
setup();
|
|
||||||
|
|
||||||
function writeChanges() {
|
function writeChanges() {
|
||||||
if (!dirty) return;
|
if (!dirty) return;
|
||||||
dirty = false;
|
dirty = false;
|
||||||
|
|
Loading…
Reference in a new issue