Skip to content

Build your personal knowledge base with Trilium Notes

862 B
Raw Blame
import type FNote from "../entities/fnote.js";
import server from "./server.js";

function enableProtectedSession() {
    glob.isProtectedSessionAvailable = true;

    touchProtectedSession();
}

async function resetProtectedSession() {
    await server.post("logout/protected");
}

function isProtectedSessionAvailable() {
    return glob.isProtectedSessionAvailable;
}

async function touchProtectedSession() {
    if (isProtectedSessionAvailable()) {
        await server.post("login/protected/touch");
    }
}

function touchProtectedSessionIfNecessary(note: FNote | null) {
    if (note && note.isProtected && isProtectedSessionAvailable()) {
        touchProtectedSession();
    }
}

export default {
    enableProtectedSession,
    resetProtectedSession,
    isProtectedSessionAvailable,
    touchProtectedSession,
    touchProtectedSessionIfNecessary
};