"use strict";
/*
 *  This file is part of CoCalc: Copyright © 2021 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 });
exports.getServerSideProps = void 0;
/*
Page for a given project.
Show all the public paths in a given project, and maybe other information about the project?
*/
const path_1 = require("path");
const base_path_1 = __importDefault(require("lib/base-path"));
const util_1 = require("lib/share/util");
const with_customize_1 = __importDefault(require("lib/with-customize"));
const get_project_1 = __importDefault(require("lib/share/get-project"));
const info_1 = __importDefault(require("lib/project/info"));
const get_owner_1 = __importDefault(require("lib/project/get-owner"));
const get_name_1 = __importDefault(require("lib/owner/get-name"));
const project_1 = __importDefault(require("components/project/project"));
exports.default = project_1.default;
async function getServerSideProps(context) {
    const { project_id } = context.params;
    if (!(0, util_1.isUUID)(project_id)) {
        return { notFound: true };
    }
    let props;
    try {
        const project = await (0, get_project_1.default)(project_id, [
            "name",
            "title",
            "description",
            "avatar_image_full",
        ]);
        if (project.name) {
            // This project probably has a nice vanity name. Possibly redirect to that instead.
            const owner_id = await (0, get_owner_1.default)(project_id);
            const owner = await (0, get_name_1.default)(owner_id);
            if (owner) {
                return { props: { redirect: (0, path_1.join)(base_path_1.default, owner, project.name) } };
            }
        }
        props = {
            project_id,
            ...(await (0, info_1.default)(project_id, context.req)),
            ...project,
        };
    }
    catch (_err) {
        // console.warn(_err)
        return { notFound: true };
    }
    return await (0, with_customize_1.default)({ context, props });
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=%5Bproject_id%5D.js.map