"use strict";
/*
Get information about this user's activity to help them
better find things.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const get_account_1 = __importDefault(require("lib/account/get-account"));
const pool_1 = __importDefault(require("@cocalc/database/pool"));
const get_params_1 = __importDefault(require("lib/api/get-params"));
async function handle(req, res) {
    const account_id = await (0, get_account_1.default)(req);
    if (account_id == null) {
        // no usage to list, since not signed in.
        res.json({ files: [] });
        return;
    }
    let { interval } = (0, get_params_1.default)(req);
    try {
        const files = await fileAccess({ account_id, interval });
        res.json({ files });
    }
    catch (err) {
        res.json({ error: `${err.message}` });
    }
}
exports.default = handle;
async function fileAccess({ account_id, interval }) {
    const pool = (0, pool_1.default)("medium");
    const { rows } = await pool.query("SELECT DISTINCT file_access_log.filename AS path, file_access_log.project_id AS project_id, projects.title AS title FROM file_access_log, projects WHERE file_access_log.project_id=projects.project_id  AND file_access_log.time >= NOW() - $2::interval AND file_access_log.account_id=$1 ORDER BY title,path", [account_id, interval ? interval : "1 day"]);
    return rows;
}
//# sourceMappingURL=file-access.js.map