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

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

module.exports = require("cookies");

/***/ }),

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

module.exports = require("assert");

/***/ }),

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

module.exports = require("buffer");

/***/ }),

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

module.exports = require("crypto");

/***/ }),

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

module.exports = require("dns");

/***/ }),

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

module.exports = require("events");

/***/ }),

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

module.exports = require("fs");

/***/ }),

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

module.exports = require("net");

/***/ }),

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

module.exports = require("os");

/***/ }),

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

module.exports = require("path");

/***/ }),

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

module.exports = require("process");

/***/ }),

/***/ 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");

/***/ }),

/***/ 79614:
/***/ ((__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 */   "getOneProject": () => (/* binding */ getOneProject)
/* harmony export */ });
/* harmony import */ var lib_account_get_account__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(677793);
/* harmony import */ var _cocalc_server_projects_create__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(713428);
/* harmony import */ var _cocalc_server_projects_create__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_projects_create__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _cocalc_server_projects_get__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(483533);
/* harmony import */ var _cocalc_server_projects_get__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_projects_get__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(854006);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_3__);
/* Get projects that belongs to the authenticated user.
   If the user has no projects, creates one.
   If they have projects, returns the most recently active one.
*/ 



async function handle(req, res) {
    const account_id = await (0,lib_account_get_account__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .Z)(req);
    try {
        res.json(await getOneProject(account_id));
    } catch (err) {
        res.json({
            error: err.message
        });
    }
};
// This is also used by the latex api endpoint.
async function getOneProject(account_id) {
    if (!(0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_3__.isValidUUID)(account_id)) {
        throw Error("user must be authenticated");
    }
    const projects = await _cocalc_server_projects_get__WEBPACK_IMPORTED_MODULE_2___default()({
        account_id,
        limit: 1
    });
    if (projects.length >= 1) {
        return projects[0];
    }
    const title = "Untitled Project";
    return {
        project_id: await _cocalc_server_projects_create__WEBPACK_IMPORTED_MODULE_1___default()({
            account_id,
            title
        }),
        title
    };
}


/***/ })

};
;

// 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, [8180,2921,2185,2014,1808,9738,8312,540,7793,8416,672,3533], () => (__webpack_exec__(79614)));
module.exports = __webpack_exports__;

})();