Path: blob/master/src/packages/next/pages/api/v2/file-access.ts
5827 views
/*1Get information about this user's activity to help them2better find things.3*/45import getAccountId from "lib/account/get-account";6import getPool from "@cocalc/database/pool";7import getParams from "lib/api/get-params";89export default async function handle(req, res) {10const account_id = await getAccountId(req);11if (account_id == null) {12// no usage to list, since not signed in.13res.json({ files: [] });14return;15}1617let { interval } = getParams(req);1819try {20const files = await fileAccess({ account_id, interval });21res.json({ files });22} catch (err) {23res.json({ error: `${err.message}` });24}25}2627interface Access {28project_id: string;29title: string;30path: string;31}3233async function fileAccess({ account_id, interval }): Promise<Access[]> {34const pool = getPool("medium");35const { rows } = await pool.query(36"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",37[account_id, interval ? interval : "1 day"]38);39return rows;40}414243