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

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

// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "default": () => (/* binding */ _project_id_),
  "getServerSideProps": () => (/* binding */ getServerSideProps)
});

// EXTERNAL MODULE: external "path"
var external_path_ = __webpack_require__(371017);
// EXTERNAL MODULE: ./lib/base-path.ts
var base_path = __webpack_require__(348397);
// EXTERNAL MODULE: ./lib/share/util.ts
var util = __webpack_require__(809774);
// EXTERNAL MODULE: ./lib/with-customize.ts
var with_customize = __webpack_require__(601880);
// EXTERNAL MODULE: ./lib/share/get-project.ts
var get_project = __webpack_require__(710949);
// EXTERNAL MODULE: ./lib/project/info.ts + 2 modules
var info = __webpack_require__(270088);
// EXTERNAL MODULE: ../database/dist/pool/index.js
var dist_pool = __webpack_require__(17763);
var pool_default = /*#__PURE__*/__webpack_require__.n(dist_pool);
;// CONCATENATED MODULE: ./lib/project/get-owner.ts

// Returns account_id or organization_id of the owner of this project.
async function getOwner(project_id) {
    const pool = pool_default()("minutes"); // we don't even have a way to change the owner ever in cocalc.
    // TODO: this seems *really* stupid/inefficient in general, e.g., what if
    // there are 1000 users?  I don't know JSONB PostgreSQL enough to come up
    // with a better query...
    const result = await pool.query("SELECT users FROM projects WHERE project_id=$1", [
        project_id
    ]);
    if (result.rows.length == 0) {
        throw Error(`no project with id ${project_id}`);
    }
    const { users  } = result.rows[0] ?? {};
    for(const account_id in users){
        if (users[account_id].group == "owner") {
            return account_id;
        }
    }
    throw Error(`project ${project_id} has no owner`);
};

;// CONCATENATED MODULE: ./lib/owner/get-name.ts
// Get the name of an owner, i.e., an account_id or organization_id.

// Returns "" if owner doesn't have a name set.
async function getName(owner_id) {
    const pool = pool_default()("medium");
    for (const type of [
        "account",
        "organization"
    ]){
        const result = await pool.query(`SELECT name FROM ${type}s WHERE ${type}_id=$1`, [
            owner_id
        ]);
        if (result.rows.length > 0) {
            return result.rows[0].name;
        }
    }
    return "";
};

// EXTERNAL MODULE: ./components/project/project.tsx + 3 modules
var project = __webpack_require__(652208);
;// CONCATENATED MODULE: ./pages/share/projects/[project_id].tsx
/*
 *  This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ /*
Page for a given project.
Show all the public paths in a given project, and maybe other information about the project?
*/ 








/* harmony default export */ const _project_id_ = (project/* default */.Z);
async function getServerSideProps(context) {
    const { project_id  } = context.params;
    if (!(0,util/* isUUID */.t)(project_id)) {
        return {
            notFound: true
        };
    }
    let props;
    try {
        const project = await (0,get_project/* default */.Z)(project_id);
        if (project.name) {
            // This project probably has a nice vanity name. Possibly redirect to that instead.
            const owner_id = await getOwner(project_id);
            const owner = await getName(owner_id);
            if (owner) {
                const { res  } = context;
                res.writeHead(302, {
                    location: (0,external_path_.join)(base_path/* default */.Z, owner, project.name)
                });
                res.end();
                return {
                    props: {}
                };
            }
        }
        props = {
            project_id,
            ...await (0,info/* default */.Z)(project_id, context.req),
            ...project
        };
    } catch (_err) {
        // console.warn(_err)
        return {
            notFound: true
        };
    }
    return await (0,with_customize/* default */.Z)({
        context,
        props
    });
}


/***/ }),

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

module.exports = require("antd");

/***/ }),

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

module.exports = require("cookies");

/***/ }),

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

module.exports = require("lodash");

/***/ }),

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

module.exports = require("lru-cache");

/***/ }),

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

module.exports = require("next/dist/shared/lib/app-router-context.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/head-manager-context.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/head.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/i18n/detect-domain-locale.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/i18n/normalize-locale-path.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/image-config-context.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/image-config.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/is-plain-object.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/mitt.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/page-path/denormalize-page-path.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router-context.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/add-locale.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/add-path-prefix.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/compare-states.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/format-next-pathname-info.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/format-url.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/get-asset-path-from-route.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/get-next-pathname-info.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/is-dynamic.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/parse-path.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/parse-relative-url.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/path-has-prefix.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/querystring.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/remove-trailing-slash.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/resolve-rewrites.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/route-matcher.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/route-regex.js");

/***/ }),

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

module.exports = require("next/dist/shared/lib/utils.js");

/***/ }),

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

module.exports = require("next/head");

/***/ }),

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

module.exports = require("next/router");

/***/ }),

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

module.exports = require("react");

/***/ }),

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

module.exports = require("react-dom");

/***/ }),

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

module.exports = require("react/jsx-runtime");

/***/ }),

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

/***/ }),

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

module.exports = require("punycode");

/***/ }),

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

/***/ })

};
;

// load runtime
var __webpack_require__ = require("../../../webpack-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = __webpack_require__.X(0, [549,6918,3429,2952,1746,1664,7545,3734,2208,5654,9925,9715,2448,9066,981,5997,5409,6087,722,3624,9924,5379,4868,8742,686,6348,5416], () => (__webpack_exec__(374918)));
module.exports = __webpack_exports__;

})();