"use strict";
(() => {
var exports = {};
exports.id = 3708;
exports.ids = [3708];
exports.modules = {

/***/ 439491:
/***/ ((module) => {

module.exports = require("assert");

/***/ }),

/***/ 714300:
/***/ ((module) => {

module.exports = require("buffer");

/***/ }),

/***/ 532081:
/***/ ((module) => {

module.exports = require("child_process");

/***/ }),

/***/ 435001:
/***/ ((module) => {

module.exports = require("cluster");

/***/ }),

/***/ 722057:
/***/ ((module) => {

module.exports = require("constants");

/***/ }),

/***/ 706113:
/***/ ((module) => {

module.exports = require("crypto");

/***/ }),

/***/ 809523:
/***/ ((module) => {

module.exports = require("dns");

/***/ }),

/***/ 582361:
/***/ ((module) => {

module.exports = require("events");

/***/ }),

/***/ 657147:
/***/ ((module) => {

module.exports = require("fs");

/***/ }),

/***/ 113685:
/***/ ((module) => {

module.exports = require("http");

/***/ }),

/***/ 795687:
/***/ ((module) => {

module.exports = require("https");

/***/ }),

/***/ 241808:
/***/ ((module) => {

module.exports = require("net");

/***/ }),

/***/ 822037:
/***/ ((module) => {

module.exports = require("os");

/***/ }),

/***/ 371017:
/***/ ((module) => {

module.exports = require("path");

/***/ }),

/***/ 504074:
/***/ ((module) => {

module.exports = require("perf_hooks");

/***/ }),

/***/ 677282:
/***/ ((module) => {

module.exports = require("process");

/***/ }),

/***/ 514521:
/***/ ((module) => {

module.exports = require("readline");

/***/ }),

/***/ 12781:
/***/ ((module) => {

module.exports = require("stream");

/***/ }),

/***/ 371576:
/***/ ((module) => {

module.exports = require("string_decoder");

/***/ }),

/***/ 924404:
/***/ ((module) => {

module.exports = require("tls");

/***/ }),

/***/ 76224:
/***/ ((module) => {

module.exports = require("tty");

/***/ }),

/***/ 257310:
/***/ ((module) => {

module.exports = require("url");

/***/ }),

/***/ 473837:
/***/ ((module) => {

module.exports = require("util");

/***/ }),

/***/ 984655:
/***/ ((module) => {

module.exports = require("v8");

/***/ }),

/***/ 959796:
/***/ ((module) => {

module.exports = require("zlib");

/***/ }),

/***/ 26438:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ getParams)
/* harmony export */ });
function getParams(req) {
    if (req?.method == "POST") {
        return new Proxy({}, {
            get (_, key) {
                return req.body?.[key];
            }
        });
    /*
    // Disabled, since this could lead to a sneaky click on a link attack.
    // Should only be enabled for dev purposes.
    } else if (req?.method == "GET") {
    return new Proxy(
      {},
      {
        get(_, key) {
          if (typeof key != "string") {
            return undefined;
          }
          return req.query?.[key];
        },
      }
    );
*/ } else {
        // only support params for POST requests.
        return {};
    }
};


/***/ }),

/***/ 500252:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ handle)
/* harmony export */ });
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(854006);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(541808);
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_cocalc_database_pool__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _cocalc_database__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(207007);
/* harmony import */ var _cocalc_database__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_cocalc_database__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var lib_api_get_params__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(26438);
/* harmony import */ var _cocalc_server_projects_control_util__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(804534);
/* harmony import */ var _cocalc_server_projects_control_util__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_projects_control_util__WEBPACK_IMPORTED_MODULE_3__);
/*
If the given public path is unlisted and has a license associated to it,
apply it to the given project.
*/ 




async function handle(req, res) {
    const { public_path_id , project_id  } = (0,lib_api_get_params__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)(req);
    try {
        if (!(0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_0__.isValidUUID)(project_id)) {
            throw Error("project_id must be a valid uuid");
        }
        if (public_path_id?.length != 40) {
            throw Error("public_path_id must be a sha1 hash");
        }
        const pool = _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_1___default()("short");
        const { rows  } = await pool.query("SELECT site_license_id, disabled, unlisted FROM public_paths WHERE id=$1", [
            public_path_id
        ]);
        const { disabled , unlisted , site_license_id  } = rows[0] ?? {};
        if (site_license_id && !disabled && unlisted) {
            // These are the only conditions under which we would apply a license.
            // Apply site_license_id to project_id.
            await (0,_cocalc_database__WEBPACK_IMPORTED_MODULE_2__.db)().add_license_to_project(project_id, site_license_id);
            (0,_cocalc_server_projects_control_util__WEBPACK_IMPORTED_MODULE_3__.restartProjectIfRunning)(project_id);
        }
        res.json({});
    } catch (err) {
        res.json({
            error: err.message
        });
    }
};


/***/ }),

/***/ 840336:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getServerSettings = void 0;
var server_settings_1 = __webpack_require__(526177);
Object.defineProperty(exports, "getServerSettings", ({ enumerable: true, get: function () { return server_settings_1.getServerSettings; } }));
//# sourceMappingURL=index.js.map

/***/ })

};
;

// load runtime
var __webpack_require__ = require("../../../../webpack-api-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = __webpack_require__.X(0, [6918,582,8180,2921,9557,6652,6942,6099,5751,2739,6257,9715,9554,1808,9738,8312,7264,8416,4181,3009,5016,6177,9840,4012,5970], () => (__webpack_exec__(500252)));
module.exports = __webpack_exports__;

})();