UNPKG

@cocalc/database

Version:

CoCalc: code for working with our PostgreSQL database

64 lines 2.12 kB
"use strict"; /* * This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. * License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details */ Object.defineProperty(exports, "__esModule", { value: true }); exports.file_use_times = void 0; const async_utils_1 = require("@cocalc/util/async-utils"); const query_1 = require("./query"); async function file_use_times(db, opts) { if (!opts.access_times && !opts.edit_times) { // trivial edge case. return {}; } // Verify that that user has access. Throws exception if not allowed. if (!(await (0, async_utils_1.callback2)(db.user_is_in_project_group.bind(db), { account_id: opts.user_account_id, project_id: opts.project_id, cache: true, }))) { throw Error("user does not have read access to the given project"); } const resp = {}; if (opts.access_times) { // Query the file_access_log file. const file_access_times = await (0, query_1.query)({ db, table: "file_access_log", select: ["time"], where: { project_id: opts.project_id, filename: opts.path, account_id: opts.account_id, }, one: false, order_by: "time desc", limit: opts.limit, }); resp.access_times = []; for (const d of file_access_times) { resp.access_times.push(d.time.valueOf()); } } // The patches data if (opts.edit_times) { const string_id = db.sha1(opts.project_id, opts.path); const edit_times = await (0, query_1.query)({ db, table: "patches", select: ["time"], where: { string_id }, one: false, order_by: "time desc", limit: opts.limit, }); resp.edit_times = []; for (const d of edit_times) { resp.edit_times.push(d.time.valueOf()); } } return resp; } exports.file_use_times = file_use_times; //# sourceMappingURL=file-use-times.js.map