@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
56 lines • 2.22 kB
JavaScript
;
/*
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const pool_1 = __importDefault(require("@cocalc/database/pool"));
const software_envs_1 = require("@cocalc/server/software-envs");
const defaults_1 = require("@cocalc/util/db-schema/defaults");
const misc_1 = require("@cocalc/util/misc");
const uuid_1 = require("uuid");
const public_path_1 = require("@cocalc/server/licenses/public-path");
async function createProject({ account_id, title, description, image, license, public_path_id, }) {
if (!(0, misc_1.is_valid_uuid_string)(account_id)) {
throw Error("account_id must be a valid uuid");
}
const project_id = (0, uuid_1.v4)();
const pool = (0, pool_1.default)();
const users = { [account_id]: { group: "owner" } };
let site_license;
if (public_path_id) {
const site_license_id = await (0, public_path_1.associatedLicense)(public_path_id);
if (site_license_id) {
if (!license) {
license = site_license_id;
}
else {
license = license + "," + site_license_id;
}
}
}
if (license) {
site_license = {};
for (const license_id of license.split(",")) {
site_license[license_id] = {};
}
}
else {
site_license = undefined;
}
const envs = await (0, software_envs_1.getSoftwareEnvironments)("server");
await pool.query("INSERT INTO projects (project_id, title, description, users, site_license, compute_image, created, last_edited) VALUES($1, $2, $3, $4, $5, $6, NOW(), NOW())", [
project_id,
title,
description,
JSON.stringify(users),
site_license != null ? JSON.stringify(site_license) : undefined,
image ?? envs?.default ?? defaults_1.DEFAULT_COMPUTE_IMAGE,
]);
return project_id;
}
exports.default = createProject;
//# sourceMappingURL=create.js.map