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

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ DirectoryListing)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(920997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var next_link__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(741664);
/* harmony import */ var next_link__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(next_link__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(545725);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(antd__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(371017);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(477389);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__);

/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ 




function DirectoryListing({ id , listing , relativePath , showHidden  }) {
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_2__.Table, {
        rowKey: "name",
        dataSource: filter(listing, showHidden),
        columns: columns(id, relativePath),
        pagination: {
            hideOnSinglePage: true,
            defaultPageSize: 50,
            showSizeChanger: true,
            pageSizeOptions: [
                "50",
                "100",
                "200",
                "500"
            ]
        }
    });
};
function filter(listing, showHidden) {
    if (showHidden) {
        return listing;
    }
    const v = [];
    for (const x of listing){
        var ref;
        if (!((ref = x.name) === null || ref === void 0 ? void 0 : ref.startsWith("."))) {
            v.push(x);
        }
    }
    return v;
}
function columns(id, relativePath) {
    return [
        {
            title: "Name",
            dataIndex: "name",
            key: "name",
            // for style below, see comment in public-paths.tsx.
            render: (name, record)=>{
                return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx((next_link__WEBPACK_IMPORTED_MODULE_1___default()), {
                    href: record.url ?? `/share/public_paths/${id}/${encodeURIComponent((0,path__WEBPACK_IMPORTED_MODULE_3__.join)(relativePath, name))}`,
                    children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("a", {
                        style: {
                            width: "100%",
                            display: "inline-block"
                        },
                        children: record.isdir ? /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("b", {
                            children: [
                                name,
                                "/"
                            ]
                        }) : name
                    })
                });
            },
            sorter: (0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__.field_cmp)("name")
        },
        {
            title: "Size",
            dataIndex: "size",
            key: "size",
            render: (size, record)=>renderSize(size, record.isdir)
            ,
            align: "right",
            sorter: (0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__.field_cmp)("size")
        },
        {
            title: "Last Modified",
            dataIndex: "mtime",
            key: "mtime",
            align: "right",
            render: (mtime)=>mtime ? `${new Date(mtime).toLocaleString()}` : ""
            ,
            sorter: (0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__.field_cmp)("mtime")
        }, 
    ];
}
function renderSize(size, isdir) {
    if (size == null) return "-";
    if (isdir) return `${size} ${(0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__.plural)(size, "item")}`;
    return (0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__.human_readable_size)(size);
}


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ GithubAvatar)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(920997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(545725);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(antd__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var components_misc_A__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(617637);
/* harmony import */ var _cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(807772);
/* harmony import */ var _cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(477389);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__);





function GithubAvatar({ style , size =195 / 2 , name  }) {
    const url = `https://github.com/${name}`;
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_1__.Tooltip, {
        title: `Open the GitHub pag ${url} in a new tab.`,
        placement: "left",
        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
            style: {
                textAlign: "center",
                ...style
            },
            children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(components_misc_A__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z, {
                href: url,
                children: [
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_1__.Avatar, {
                        style: {
                            borderRadius: "7.5px",
                            border: "1px solid #eee"
                        },
                        shape: "square",
                        size: size,
                        icon: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("img", {
                            src: `https://avatars.githubusercontent.com/${name}`
                        })
                    }),
                    /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                        children: [
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_3__.Icon, {
                                name: "external-link"
                            }),
                            " ",
                            (0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_4__.trunc)(name, 28),
                            " ",
                            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_3__.Icon, {
                                name: "github"
                            })
                        ]
                    })
                ]
            })
        })
    });
};


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ Organization)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(920997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lib_share_customize__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(982712);
/* harmony import */ var components_share_layout__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(618532);
/* harmony import */ var components_misc_A__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(617637);
/* harmony import */ var components_share_directory_listing__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(810186);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(545725);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(antd__WEBPACK_IMPORTED_MODULE_5__);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(477389);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_6__);
/* harmony import */ var components_share_site_name__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(312899);
/* harmony import */ var _avatar__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(946284);

/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ 







function Organization({ customize , contents , error , organization  }) {
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(lib_share_customize__WEBPACK_IMPORTED_MODULE_1__/* .Customize */ .l, {
        value: customize,
        children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(components_share_layout__WEBPACK_IMPORTED_MODULE_2__/* .Layout */ .A, {
            title: `GitHub - ${organization}`,
            children: [
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_avatar__WEBPACK_IMPORTED_MODULE_8__/* ["default"] */ .Z, {
                    name: organization,
                    style: {
                        float: "right"
                    }
                }),
                /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("h1", {
                    children: [
                        (0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_6__.capitalize)(organization),
                        "'s GitHub Repositories"
                    ]
                }),
                "These are the",
                " ",
                /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(components_misc_A__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z, {
                    href: `https://github.com/${organization}`,
                    children: [
                        "GitHub repositories that are owned by ",
                        organization
                    ]
                }),
                ". You can browse and work with them via ",
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_share_site_name__WEBPACK_IMPORTED_MODULE_7__/* ["default"] */ .Z, {}),
                ".",
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("br", {}),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("br", {}),
                error && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_5__.Alert, {
                    type: "error",
                    message: error,
                    showIcon: true
                }),
                (contents === null || contents === void 0 ? void 0 : contents.listing) && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_share_directory_listing__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z, {
                    listing: contents.listing
                })
            ]
        })
    });
};


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ SiteName)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(920997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lib_use_customize__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1198);


function SiteName({ full  }) {
    const { siteName , siteDescription  } = (0,lib_use_customize__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z)();
    if (full) {
        return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
            children: [
                siteName,
                ": ",
                siteDescription
            ]
        });
    }
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
        children: siteName
    });
};


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ getProjectId)
/* harmony export */ });
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(17763);
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _owner__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(938450);
/* harmony import */ var lib_share_proxy_project__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(849450);
/*
Get basic information about a user or organization
from the database.  This should be enough to render
a nice "homepage" for that user or organization.

*/ 


// Throws an exception if there is no project with this name.
// TODO: take into account redirects for when name is changed.
async function getProjectId(owner, project) {
    if (owner == "github") {
        return await (0,lib_share_proxy_project__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)();
    }
    const { owner_id  } = await (0,_owner__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z)(owner);
    const pool = _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0___default()("long"); // map from owner/project --> project_id unlikely to change and when it does, stale data is ok.
    // NOTE: it's not enough that owner is a collab on the project -- they have to be the owner.
    // We do users ? $2 also, since it's fast/indexed, then dig in to the JSON...
    // Note that we have put owner_id in the query string explicitly (as far as I know),
    // though it is NOT user supplied so that's safe.
    const result = await pool.query(`SELECT project_id FROM projects WHERE LOWER(name)=$1 AND users ? $2 AND users#>>'{${owner_id},group}' = 'owner'`, [
        project.toLowerCase(),
        owner_id
    ]);
    if (result.rows.length > 0) {
        return result.rows[0].project_id;
    }
    throw Error(`no project ${owner}/${project}`);
};


/***/ }),

/***/ 300265:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "ES": () => (/* binding */ defaultBranch),
/* harmony export */   "IQ": () => (/* binding */ contents),
/* harmony export */   "Kd": () => (/* binding */ rawText),
/* harmony export */   "br": () => (/* binding */ fileInGist),
/* harmony export */   "en": () => (/* binding */ repos),
/* harmony export */   "eo": () => (/* binding */ RAW_MAX_SIZE_BYTES)
/* harmony export */ });
/* unused harmony export api */
/* harmony import */ var node_fetch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(96544);
/* harmony import */ var base_64__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(102574);
/* harmony import */ var base_64__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(base_64__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(371017);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(17763);
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_cocalc_database_pool__WEBPACK_IMPORTED_MODULE_3__);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([node_fetch__WEBPACK_IMPORTED_MODULE_0__]);
node_fetch__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
/*
api.github.com is very nice to use to get info, but

"Unauthenticated clients can make **60 requests per hour**."
https://docs.github.com/en/rest/guides/getting-started-with-the-rest-api

So it's completely useless for our purposes without authentication.

"When authenticating, you should see your rate limit bumped to 5,000 requests an hour,"

which is also hopefully sufficient, but worrisome.

Thoughts:

- Since all rendering could be done client side, I could actually have
the client browser grab content instead of the server, then render there to
massively reduce api load, although even users could quickly hit "60 requests
per hour", so the api still wouldn't help.

- If we do hit the 5K/hour limit, maybe we can use more than one api key?

- Upgrading to enterprise doesn't increase this much.

- We could switch to mirroring and cloning files locally, and that might
  work around this problem in practice, but be a lot of work. We'll see.


Get at https://github.com/settings/tokens
*/ 



// We don't allow just fetching content that is arbitrarily large, since that could cause
// the server to just run out of memory.  However, we want this to reasonably big.
const RAW_MAX_SIZE_BYTES = 10000000; // 10MB
// TODO: we will also have a raw blob or stream or something for serving up images, etc.,
async function rawText(githubOrg, githubRepo, segments) {
    const url = rawURL(githubOrg, githubRepo, segments);
    //console.log("raw:", { url });
    return await (await (0,node_fetch__WEBPACK_IMPORTED_MODULE_0__["default"])(url, {
        size: RAW_MAX_SIZE_BYTES
    })).text();
}
function rawURL(githubOrg, githubRepo, segments) {
    return `https://raw.githubusercontent.com/${githubOrg}/${githubRepo}/${(0,path__WEBPACK_IMPORTED_MODULE_2__.join)(...segments.slice(1))}`;
}
async function credentials() {
    const pool = _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_3___default()("long");
    const { rows  } = await pool.query("SELECT name, value FROM server_settings WHERE name='github_username' OR name='github_token'");
    let result = {};
    for (const row of rows){
        result[row.name] = row.value;
    }
    return result;
}
async function api(path) {
    const url = `https://api.github.com/${path}`;
    const options = {};
    const { github_username , github_token  } = await credentials();
    if (github_username && github_token) {
        options.headers = new node_fetch__WEBPACK_IMPORTED_MODULE_0__.Headers({
            Authorization: "Basic " + (0,base_64__WEBPACK_IMPORTED_MODULE_1__.encode)(`${github_username}:${github_token}`),
            "Content-Type": "application/json"
        });
    }
    //console.log(options);
    const response = await (0,node_fetch__WEBPACK_IMPORTED_MODULE_0__["default"])(url, options);
    //console.log(response.headers);
    const data = await response.json();
    //console.log({ url, response });
    if (data.message) {
        throw Error(`${data.message}  (see ${data.documentation_url})`);
    }
    return data;
}
// Use the github api to get the contents of a path on github.
// We are planning to use this just to get directory listings,
// since individual files have their content base64 encoded, etc.,
// and that has to be much slower than just grabbing the
// file form raw (and also only works up to 1MB according to
// github docs).
// How to do auth + fetch with node: https://stackoverflow.com/questions/43842793/basic-authentication-with-fetch
async function contents(githubOrg, githubRepo, segments) {
    let ref, path;
    if (segments.length == 0) {
        ref = ""; // the default;
        path = ""; // root
    } else {
        // tree/[ref]/[path ...]
        ref = segments[1];
        path = (0,path__WEBPACK_IMPORTED_MODULE_2__.join)(...segments.slice(2));
    }
    const result = await api(`repos/${githubOrg}/${githubRepo}/contents/${path}${ref ? "?ref=" + ref : ""}`);
    if (result.name != null) {
        throw Error("only use contents to get directory listing, not to get file contents");
    }
    return result;
}
async function defaultBranch(githubOrg, githubRepo) {
    return (await api(`repos/${githubOrg}/${githubRepo}`)).default_branch;
}
// Return all the repositories in a GitHub organization or user:
async function repos(githubOrg) {
    let result;
    try {
        result = await api(`orgs/${githubOrg}/repos`);
    } catch (err) {
        result = await api(`users/${githubOrg}/repos`);
    }
    return result.filter((repo)=>!repo.private
    ).map((repo)=>{
        return {
            isdir: true,
            name: repo.name,
            mtime: new Date(repo.updated_at).valueOf(),
            url: `/github/${githubOrg}/${repo.name}`
        };
    });
}
async function fileInGist(gistId) {
    const info = await api(`gists/${gistId}`);
    for(const filename in info.files){
        return filename;
    }
    throw Error("no files in the gist");
}

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

/***/ 294549:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ getContents)
/* harmony export */ });
/* harmony import */ var _api__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(300265);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(371017);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _cocalc_util_cmp__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(463981);
/* harmony import */ var _cocalc_util_cmp__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_cmp__WEBPACK_IMPORTED_MODULE_2__);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_api__WEBPACK_IMPORTED_MODULE_0__]);
_api__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];



async function getContents(githubOrg, githubRepo, segments) {
    if (!githubRepo) {
        // get all repos attached to an org
        const listing = await (0,_api__WEBPACK_IMPORTED_MODULE_0__/* .repos */ .en)(githubOrg);
        listing.sort((0,_cocalc_util_cmp__WEBPACK_IMPORTED_MODULE_2__.field_cmp)("mtime"));
        listing.reverse();
        return {
            listing
        };
    }
    switch(segments[0]){
        case undefined:
        case "tree":
            // directory listing
            const response = await (0,_api__WEBPACK_IMPORTED_MODULE_0__/* .contents */ .IQ)(githubOrg, githubRepo, segments);
            if (response["name"] != null) {
                // it's a file rather than a directory
                throw Error("not implemented");
            }
            const branch = segments[0] == null ? await (0,_api__WEBPACK_IMPORTED_MODULE_0__/* .defaultBranch */ .ES)(githubOrg, githubRepo) : segments[1];
            const listing = [];
            for (const file of response){
                const isdir = file.type == "dir";
                let url;
                if (isdir) {
                    if (segments[0] == null) {
                        url = `/github/${githubOrg}/${githubRepo}/${(0,path__WEBPACK_IMPORTED_MODULE_1__.join)("tree", branch, ...segments, file.name)}`;
                    } else {
                        url = `/github/${githubOrg}/${githubRepo}/${(0,path__WEBPACK_IMPORTED_MODULE_1__.join)(...segments, file.name)}`;
                    }
                } else {
                    if (segments[0] == null) {
                        url = `/github/${githubOrg}/${githubRepo}/${(0,path__WEBPACK_IMPORTED_MODULE_1__.join)("blob", branch, ...segments, file.name)}`;
                    } else {
                        url = `/github/${githubOrg}/${githubRepo}/${(0,path__WEBPACK_IMPORTED_MODULE_1__.join)("blob", segments[1], ...segments.slice(2), file.name)}`;
                    }
                }
                listing.push({
                    url,
                    name: file.name,
                    isdir,
                    ...file.type == "file" ? {
                        size: file.size
                    } : undefined
                });
            }
            return {
                isdir: true,
                listing
            };
            break;
        case "blob":
            const content = await (0,_api__WEBPACK_IMPORTED_MODULE_0__/* .rawText */ .Kd)(githubOrg, githubRepo, segments);
            return {
                content,
                size: content.length
            };
        default:
            throw Error("not implemented");
    }
};

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

/***/ 879081:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ getPublicPathInfoGithub)
/* harmony export */ });
/* harmony import */ var _get_contents__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(294549);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(371017);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_1__);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_get_contents__WEBPACK_IMPORTED_MODULE_0__]);
_get_contents__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ 

async function getPublicPathInfoGithub(url) {
    const segments = url.split("/");
    const githubOrg = segments[1];
    if (!githubOrg) {
        throw Error(`invalid url ${url} -- must include github organization`);
    }
    const githubRepo = segments[2];
    const relativePath = (0,path__WEBPACK_IMPORTED_MODULE_1__.join)(...segments.slice(3));
    if (!githubRepo) {
        // only getting the repos for a single org.
        const contents = await (0,_get_contents__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .Z)(githubOrg, "", []);
        const projectTitle = `GitHub Repositories owned by ${githubOrg}`;
        return {
            contents,
            relativePath,
            projectTitle,
            githubOrg
        };
    }
    const contents = await (0,_get_contents__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .Z)(githubOrg, githubRepo, segments.slice(3));
    const projectTitle = `GitHub repository ${githubOrg} / ${githubRepo}`;
    return {
        contents,
        relativePath,
        projectTitle,
        githubOrg,
        githubRepo,
        url
    };
};

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ getGithubProjectId)
/* harmony export */ });
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(17763);
/* harmony import */ var _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(477389);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_1__);


async function getGithubProjectId() {
    const pool = _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0___default()("long");
    const { rows  } = await pool.query("SELECT value FROM server_settings WHERE name='github_project_id'");
    if (rows.length == 0 || !(0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_1__.isValidUUID)(rows[0].value)) {
        throw Error("github_project_id is not configured");
    }
    return rows[0].value;
};


/***/ }),

/***/ 227439:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ Page),
/* harmony export */   "getServerSideProps": () => (/* binding */ getServerSideProps)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(920997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lib_names_project__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(270263);
/* harmony import */ var lib_with_customize__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(422638);
/* harmony import */ var lib_project_info__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(336284);
/* harmony import */ var lib_share_get_project__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(123925);
/* harmony import */ var components_project_project__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(166455);
/* harmony import */ var components_share_proxy_organization__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(118644);
/* harmony import */ var lib_share_proxy_get_public_path_info_github__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(879081);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([lib_share_proxy_get_public_path_info_github__WEBPACK_IMPORTED_MODULE_7__]);
lib_share_proxy_get_public_path_info_github__WEBPACK_IMPORTED_MODULE_7__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];

/*
 *  This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ // Page for a project that is owned by a named account
// or organization.







function Page(props) {
    if (props.project_id) {
        return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_project_project__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
            ...props
        });
    } else {
        // e.g., for listing all github repos in an org:
        return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_share_proxy_organization__WEBPACK_IMPORTED_MODULE_6__/* ["default"] */ .Z, {
            ...props
        });
    }
};
async function getServerSideProps(context) {
    const { owner , project  } = context.params;
    try {
        let props;
        if (owner == "github") {
            // special case for special github URL's
            // This is a URL like   https://cocalc.com/github/cocalc,
            // which will end up listing all public repos under the cocalc org (say).
            props = {
                ...await (0,lib_share_proxy_get_public_path_info_github__WEBPACK_IMPORTED_MODULE_7__/* ["default"] */ .Z)(`${owner}/${project}`),
                organization: project
            };
        } else {
            const project_id = await (0,lib_names_project__WEBPACK_IMPORTED_MODULE_1__/* ["default"] */ .Z)(owner, project);
            props = {
                project_id,
                ...await (0,lib_project_info__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z)(project_id, context.req),
                ...await (0,lib_share_get_project__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)(project_id)
            };
        }
        return (0,lib_with_customize__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z)({
            context,
            props
        });
    } catch (err) {
        console.log(err);
        return {
            notFound: true
        };
    }
}

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

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

module.exports = require("antd");

/***/ }),

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

module.exports = require("base-64");

/***/ }),

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

module.exports = require("cookies");

/***/ }),

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

module.exports = require("lodash");

/***/ }),

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

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

/***/ }),

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

/***/ }),

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

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

/***/ }),

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

module.exports = require("next/dist/shared/lib/router/utils/querystring.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");

/***/ }),

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

module.exports = import("node-fetch");;

/***/ }),

/***/ 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,1746,9505,1748,3734,2208,5654,9925,9715,2448,1107,9521,5114,8278,722,3624,9924,5379,2620,2712,9858,2983,2259,8450], () => (__webpack_exec__(227439)));
module.exports = __webpack_exports__;

})();