@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
35 lines • 1.56 kB
JavaScript
;
/*
Handle a syncdoc history request
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const message_1 = require("@cocalc/util/message");
const database_1 = require("@cocalc/database");
const pool_1 = __importDefault(require("@cocalc/database/pool"));
async function handleSyncdoc({ project_id, mesg, sendResponse, }) {
const { patches, string_id } = mesg;
// this raises an error if user does not have access
await checkSyncdocAccess(project_id, string_id);
// get the history
const history = await (0, database_1.db)().syncdoc_history_async(string_id, patches);
sendResponse((0, message_1.syncdoc_history)({ history }));
}
exports.default = handleSyncdoc;
async function checkSyncdocAccess(project_id, string_id) {
if (typeof string_id != "string" && string_id.length == 40) {
throw Error("invalid string_id");
}
const pool = (0, pool_1.default)("long"); // caching is fine since a "no" result isn't cached and a yes result doesn't change.
const { rows } = await pool.query("SELECT project_id FROM syncstrings WHERE string_id = $1::CHAR(40)", [string_id]);
if (rows.length == 0) {
throw Error("no such syncdoc");
}
if (rows[0].project_id != project_id) {
throw Error("project does NOT have access to this syncdoc");
}
// everything is fine -- nothing more to do
}
//# sourceMappingURL=handle-syncdoc.js.map