"use strict";
/*
 *  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 });
exports.getServerSideProps = void 0;
const path_1 = require("path");
const base_path_1 = __importDefault(require("lib/base-path"));
const get_public_path_info_1 = __importDefault(require("lib/share/get-public-path-info"));
const with_customize_1 = __importDefault(require("lib/with-customize"));
const public_path_1 = require("lib/names/public-path");
const path_2 = __importDefault(require("components/path/path"));
exports.default = path_2.default;
async function getServerSideProps(context) {
    const id = context.params.id[0];
    const relativePath = context.params.id.slice(1).join("/");
    try {
        const names = await (0, public_path_1.getPublicPathNames)(id);
        if (names != null) {
            // redirect
            let location = (0, path_1.join)(base_path_1.default, names.owner, names.project, names.public_path);
            if (context.params.id.length > 1) {
                location = (0, path_1.join)(location, "files", context.params.id.slice(1).join("/"));
            }
            return { props: { redirect: location } };
        }
        const props = await (0, get_public_path_info_1.default)({
            id,
            relativePath,
            req: context.req,
        });
        return await (0, with_customize_1.default)({ context, props });
    }
    catch (_err) {
        console.log(_err);
        return { notFound: true };
    }
}
exports.getServerSideProps = getServerSideProps;
//# sourceMappingURL=%5B...id%5D.js.map