"use strict";
exports.id = 5886;
exports.ids = [5886];
exports.modules = {

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ EditRow)
/* 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__);

function EditRow({ label , description , children , style  }) {
    return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
        style: {
            marginBottom: "20px",
            ...style
        },
        children: [
            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("h4", {
                children: label
            }),
            description == null ? children : /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
                style: {
                    width: "100%"
                },
                children: [
                    children,
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                        style: {
                            color: "#666",
                            fontSize: "10pt",
                            marginTop: "10px"
                        },
                        children: description
                    })
                ]
            })
        ]
    });
}


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ SanitizedMarkdown)
/* 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 _cocalc_frontend_lib_file_context__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(732586);
/* harmony import */ var _cocalc_frontend_editors_slate_static_markdown__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(695379);
/* harmony import */ var _cocalc_frontend_editors_slate_static_markdown__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_cocalc_frontend_editors_slate_static_markdown__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var components_misc_A__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(940981);
/*
 *  This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ 



function SanitizedMarkdown({ style , value  }) {
    const ctx = {
        AnchorTagComponent: components_misc_A__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z,
        noSanitize: false
    };
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_cocalc_frontend_lib_file_context__WEBPACK_IMPORTED_MODULE_1__.FileContext.Provider, {
        value: ctx,
        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx((_cocalc_frontend_editors_slate_static_markdown__WEBPACK_IMPORTED_MODULE_2___default()), {
            value: value,
            style: style
        })
    });
}


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ SaveButton)
/* 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 react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(616689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(546517);
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(545725);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(antd__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var lib_hooks_mounted__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(900686);
/* harmony import */ var components_share_loading__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(976087);
/* harmony import */ var lib_api_post__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(194184);
/* harmony import */ var _cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(807772);
/* harmony import */ var _cocalc_util_schema__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(685219);
/* harmony import */ var _cocalc_util_schema__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_schema__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(477389);
/* harmony import */ var _cocalc_util_misc__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_9__);










const DEBOUNCE_MS = 1500;
function SaveButton({ disabled , edited , original , setOriginal , table , style , onSave , isValid , debounce_ms  }) {
    if (debounce_ms == null) debounce_ms = DEBOUNCE_MS;
    const { 0: saving , 1: setSaving  } = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(false);
    const { 0: error , 1: setError  } = (0,react__WEBPACK_IMPORTED_MODULE_1__.useState)("");
    // Tricky hooks: We have to store the state in a ref as well so that
    // we can use it in the save function, since that function
    // is memoized and called from a debounced function.
    const saveRef = (0,react__WEBPACK_IMPORTED_MODULE_1__.useRef)({
        edited,
        original,
        table
    });
    saveRef.current = {
        edited,
        original,
        table
    };
    const isMounted = (0,lib_hooks_mounted__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z)();
    const save = (0,react__WEBPACK_IMPORTED_MODULE_1__.useMemo)(()=>{
        return async ()=>{
            const { edited , original , table  } = saveRef.current;
            let changes = false;
            const e = {};
            for(const field in edited){
                if (!(0,lodash__WEBPACK_IMPORTED_MODULE_2__.isEqual)(original[field], edited[field])) {
                    e[field] = (0,lodash__WEBPACK_IMPORTED_MODULE_2__.cloneDeep)(edited[field]);
                    changes = true;
                }
            }
            if (!changes) {
                // no changes to save.
                return false;
            }
            for (const field1 of preserveFields(table)){
                e[field1] = (0,lodash__WEBPACK_IMPORTED_MODULE_2__.cloneDeep)(edited[field1]);
            }
            const query = {
                [table]: e
            };
            if (isMounted.current) {
                setSaving(true);
                setError("");
            }
            let result;
            try {
                // Note -- we definitely do want to do the save
                // itself, even if the component is already unmounted,
                // so we don't loose changes.
                result = await (0,lib_api_post__WEBPACK_IMPORTED_MODULE_6__/* ["default"] */ .Z)("/user-query", {
                    query
                });
            } catch (err) {
                if (!isMounted.current) return;
                setError(err.message);
                return false;
            } finally{
                if (isMounted.current) {
                    setSaving(false);
                }
            }
            if (!isMounted.current) return;
            if (result.error) {
                setError(result.error);
            } else {
                setOriginal((0,lodash__WEBPACK_IMPORTED_MODULE_2__.cloneDeep)(edited));
            }
            return true; // successful save
        };
    }, []);
    async function doSave() {
        const e = (0,lodash__WEBPACK_IMPORTED_MODULE_2__.cloneDeep)(saveRef.current.edited);
        if (table) {
            const didSave = await save();
            if (!isMounted.current) return;
            if (didSave) {
                await onSave?.(e);
            }
            return;
        }
        try {
            await onSave?.(e);
            if (!isMounted.current) return;
            setOriginal(e);
            setError("");
        } catch (err) {
            setError(err.toString());
        }
    }
    const doSaveDebounced = (0,react__WEBPACK_IMPORTED_MODULE_1__.useMemo)(()=>(0,lodash__WEBPACK_IMPORTED_MODULE_2__.debounce)(doSave, debounce_ms), [
        onSave
    ]);
    (0,react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(()=>{
        doSaveDebounced();
        return doSaveDebounced;
    }, [
        edited
    ]);
    const same = (0,lodash__WEBPACK_IMPORTED_MODULE_2__.isEqual)(edited, original);
    return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
        style: style,
        children: [
            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_3__.Button, {
                type: "primary",
                disabled: disabled ?? (saving || same || isValid != null && !isValid(edited)),
                onClick: doSave,
                children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(antd__WEBPACK_IMPORTED_MODULE_3__.Space, {
                    children: [
                        /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_7__.Icon, {
                            name: "save"
                        }),
                        saving ? /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_share_loading__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
                            delay: 250,
                            before: "Save",
                            children: "Saving..."
                        }) : "Save"
                    ]
                })
            }),
            !same && error && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_3__.Alert, {
                type: "error",
                message: error,
                style: {
                    marginTop: "15px"
                }
            })
        ]
    });
}
function preserveFields(table) {
    return (0,_cocalc_util_misc__WEBPACK_IMPORTED_MODULE_9__.keys)(_cocalc_util_schema__WEBPACK_IMPORTED_MODULE_8__.SCHEMA[table].user_query?.set?.required_fields ?? {});
}


/***/ }),

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


// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "Z": () => (/* binding */ Project)
});

// EXTERNAL MODULE: external "react/jsx-runtime"
var jsx_runtime_ = __webpack_require__(920997);
// EXTERNAL MODULE: external "react"
var external_react_ = __webpack_require__(616689);
// EXTERNAL MODULE: external "next/router"
var router_ = __webpack_require__(371853);
// EXTERNAL MODULE: ./components/share/public-paths.tsx
var public_paths = __webpack_require__(113419);
// EXTERNAL MODULE: ./node_modules/next/link.js
var next_link = __webpack_require__(741664);
var link_default = /*#__PURE__*/__webpack_require__.n(next_link);
// EXTERNAL MODULE: ./lib/share/util.ts
var util = __webpack_require__(809774);
// EXTERNAL MODULE: ./components/account/avatar.tsx
var avatar = __webpack_require__(673169);
;// CONCATENATED MODULE: ./components/share/user.tsx




function User({ account_id , first_name , last_name  }) {
    return /*#__PURE__*/ jsx_runtime_.jsx((link_default()), {
        href: `/share/accounts/${account_id}`,
        children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)("a", {
            children: [
                /*#__PURE__*/ jsx_runtime_.jsx(avatar/* default */.Z, {
                    account_id: account_id,
                    style: {
                        marginRight: "5px"
                    }
                }),
                (0,util/* trunc */.RF)(`${first_name} ${last_name}`, 50)
            ]
        })
    });
}

;// CONCATENATED MODULE: ./components/share/collaborators.tsx


function Collaborators({ collaborators  }) {
    const v = [];
    for (const user of collaborators ?? []){
        v.push(/*#__PURE__*/ jsx_runtime_.jsx(User, {
            ...user
        }, user.account_id));
        v.push(/*#__PURE__*/ (0,jsx_runtime_.jsxs)("span", {
            children: [
                ", ",
                "\xa0\xa0"
            ]
        }, user.account_id + ","));
    }
    v.pop(); // discard last comma.
    return /*#__PURE__*/ jsx_runtime_.jsx(jsx_runtime_.Fragment, {
        children: v
    });
}

// EXTERNAL MODULE: ./components/share/loading.tsx
var loading = __webpack_require__(976087);
// EXTERNAL MODULE: ./components/share/layout.tsx + 1 modules
var layout = __webpack_require__(216284);
// EXTERNAL MODULE: ./components/misc/A.tsx
var A = __webpack_require__(940981);
// EXTERNAL MODULE: ./lib/share/customize.tsx
var share_customize = __webpack_require__(158742);
// EXTERNAL MODULE: external "antd"
var external_antd_ = __webpack_require__(545725);
// EXTERNAL MODULE: ../frontend/dist/components/icon.js
var icon = __webpack_require__(807772);
// EXTERNAL MODULE: ./components/misc/edit-row.tsx
var edit_row = __webpack_require__(336309);
// EXTERNAL MODULE: ./components/misc/save-button.tsx
var save_button = __webpack_require__(196348);
;// CONCATENATED MODULE: ./components/project/edit.tsx
/*
Edit some very basic configuration of a project, mainly that is relevant for sharing for now,
but maybe later everything.
*/ 






function Edit(props) {
    const router = (0,router_.useRouter)();
    const { 0: expanded , 1: setExpanded  } = (0,external_react_.useState)(!!router.query.edit);
    return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
        style: {
            marginBottom: "15px"
        },
        children: [
            /*#__PURE__*/ (0,jsx_runtime_.jsxs)(external_antd_.Button, {
                disabled: expanded,
                onClick: (e)=>{
                    e.preventDefault();
                    setExpanded(true);
                },
                size: "small",
                children: [
                    /*#__PURE__*/ jsx_runtime_.jsx(icon.Icon, {
                        name: "pencil"
                    }),
                    " Edit..."
                ]
            }, "edit"),
            expanded && /*#__PURE__*/ jsx_runtime_.jsx(EditFields, {
                info: props,
                onClose: ()=>{
                    setExpanded(false);
                    // This reloads the page, but with no flicker, so user sees new information reflected.
                    router.push({
                        pathname: router.asPath.split("?")[0]
                    });
                }
            })
        ]
    });
}
function EditFields({ info , onClose  }) {
    const { 0: edited , 1: setEdited  } = (0,external_react_.useState)(info);
    const { 0: original , 1: setOriginal  } = (0,external_react_.useState)(info);
    return /*#__PURE__*/ (0,jsx_runtime_.jsxs)("div", {
        style: {
            width: "100%",
            border: "1px solid #eee",
            padding: "15px",
            marginTop: "15px"
        },
        children: [
            /*#__PURE__*/ jsx_runtime_.jsx("div", {
                children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)(external_antd_.Space, {
                    style: {
                        float: "right"
                    },
                    children: [
                        /*#__PURE__*/ jsx_runtime_.jsx(save_button/* default */.Z, {
                            edited: edited,
                            original: original,
                            setOriginal: setOriginal,
                            table: "projects"
                        }),
                        /*#__PURE__*/ jsx_runtime_.jsx(external_antd_.Button, {
                            style: {
                                float: "right"
                            },
                            onClick: onClose,
                            children: "Close"
                        })
                    ]
                })
            }),
            /*#__PURE__*/ jsx_runtime_.jsx("br", {}),
            /*#__PURE__*/ jsx_runtime_.jsx(edit_row/* default */.Z, {
                label: "Title",
                children: /*#__PURE__*/ jsx_runtime_.jsx(external_antd_.Input, {
                    value: edited.title,
                    onChange: (e)=>setEdited({
                            ...edited,
                            title: e.target.value
                        })
                })
            }),
            /*#__PURE__*/ jsx_runtime_.jsx(edit_row/* default */.Z, {
                label: "Description",
                children: /*#__PURE__*/ jsx_runtime_.jsx(external_antd_.Input.TextArea, {
                    value: edited.description,
                    onChange: (e)=>setEdited({
                            ...edited,
                            description: e.target.value
                        }),
                    autoSize: {
                        minRows: 2
                    }
                })
            }),
            /*#__PURE__*/ jsx_runtime_.jsx(edit_row/* default */.Z, {
                label: "Name (for nicer URLs)",
                children: /*#__PURE__*/ jsx_runtime_.jsx(external_antd_.Input, {
                    value: edited.name,
                    onChange: (e)=>setEdited({
                            ...edited,
                            name: e.target.value
                        })
                })
            })
        ]
    });
}

// EXTERNAL MODULE: ./lib/share/edit-url.ts
var edit_url = __webpack_require__(34868);
// EXTERNAL MODULE: ../frontend/dist/editors/slate/static-markdown.js
var static_markdown = __webpack_require__(695379);
var static_markdown_default = /*#__PURE__*/__webpack_require__.n(static_markdown);
;// CONCATENATED MODULE: ./components/project/project.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?
*/ 












function Project({ project_id , publicPaths , collaborators , title , description , name , customize , avatar_image_full , redirect ,  }) {
    const router = (0,router_.useRouter)();
    (0,external_react_.useEffect)(()=>{
        if (redirect) {
            router.push(redirect);
        }
    }, [
        redirect
    ]);
    if (publicPaths == null || collaborators == null || title == null) {
        return /*#__PURE__*/ jsx_runtime_.jsx(loading/* default */.Z, {
            style: {
                fontSize: "30px"
            }
        });
    }
    const collab = isCollaborator(customize.account, collaborators);
    return /*#__PURE__*/ jsx_runtime_.jsx(share_customize/* Customize */.l, {
        value: customize,
        children: /*#__PURE__*/ (0,jsx_runtime_.jsxs)(layout/* Layout */.A, {
            title: title,
            children: [
                /*#__PURE__*/ (0,jsx_runtime_.jsxs)("h1", {
                    children: [
                        avatar_image_full && /*#__PURE__*/ jsx_runtime_.jsx(external_antd_.Avatar, {
                            icon: /*#__PURE__*/ jsx_runtime_.jsx("img", {
                                src: avatar_image_full
                            }),
                            size: 160,
                            shape: "square",
                            style: {
                                float: "right"
                            }
                        }),
                        "Project:",
                        " ",
                        collab ? /*#__PURE__*/ jsx_runtime_.jsx(A/* default */.Z, {
                            href: (0,edit_url/* default */.Z)({
                                project_id,
                                type: "collaborator"
                            }),
                            external: true,
                            children: title
                        }) : title
                    ]
                }),
                /*#__PURE__*/ jsx_runtime_.jsx("div", {
                    style: {
                        color: "#666"
                    },
                    children: /*#__PURE__*/ jsx_runtime_.jsx((static_markdown_default()), {
                        value: description
                    })
                }),
                collab && /*#__PURE__*/ jsx_runtime_.jsx(Edit, {
                    project_id: project_id,
                    title: title,
                    description: description,
                    name: name
                }),
                collaborators != null && collaborators.length > 0 && /*#__PURE__*/ (0,jsx_runtime_.jsxs)(jsx_runtime_.Fragment, {
                    children: [
                        /*#__PURE__*/ jsx_runtime_.jsx("h2", {
                            children: "Collaborators"
                        }),
                        /*#__PURE__*/ jsx_runtime_.jsx(Collaborators, {
                            collaborators: collaborators
                        }),
                        /*#__PURE__*/ jsx_runtime_.jsx("br", {}),
                        " ",
                        /*#__PURE__*/ jsx_runtime_.jsx("br", {})
                    ]
                }),
                /*#__PURE__*/ jsx_runtime_.jsx("h2", {
                    children: "Public Paths"
                }),
                collab && /*#__PURE__*/ jsx_runtime_.jsx("div", {
                    style: {
                        marginBottom: "15px"
                    },
                    children: "You are a collaborator on this project, so unlisted and disabled public paths are also listed here, so you can more easily edit them."
                }),
                publicPaths != null && publicPaths.length == 0 ? /*#__PURE__*/ jsx_runtime_.jsx("div", {
                    children: "No public paths."
                }) : /*#__PURE__*/ jsx_runtime_.jsx(public_paths/* default */.Z, {
                    publicPaths: publicPaths
                })
            ]
        })
    });
}
function isCollaborator(account, collaborators) {
    const account_id = account?.account_id;
    if (account_id == null) return false;
    for (const user of collaborators){
        if (user.account_id == account_id) return true;
    }
    return false;
}


/***/ }),

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


// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "Z": () => (/* binding */ getProjectInfo)
});

// EXTERNAL MODULE: ../database/dist/pool/index.js
var dist_pool = __webpack_require__(17763);
var pool_default = /*#__PURE__*/__webpack_require__.n(dist_pool);
// EXTERNAL MODULE: ./lib/share/util.ts
var util = __webpack_require__(809774);
;// CONCATENATED MODULE: ./lib/share/get-collaborators.ts
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ /*
Get the collaborators on a given project.  Unlisted collaborators are NOT included.
*/ 

async function getCollaborators(project_id) {
    if (!(0,util/* isUUID */.t)(project_id)) {
        throw Error("project_id must be a uuid");
    }
    const pool = pool_default()("medium");
    const result = await pool.query("SELECT accounts.account_id, accounts.first_name, accounts.last_name FROM accounts, (SELECT jsonb_object_keys(users) AS account_id FROM projects WHERE project_id=$1) AS users WHERE accounts.account_id=users.account_id::UUID AND accounts.unlisted IS NOT TRUE", [
        project_id
    ]);
    return result.rows;
}

// EXTERNAL MODULE: ../server/dist/projects/is-collaborator.js
var is_collaborator = __webpack_require__(954314);
var is_collaborator_default = /*#__PURE__*/__webpack_require__.n(is_collaborator);
// EXTERNAL MODULE: ./lib/account/get-account.ts
var get_account = __webpack_require__(661879);
;// CONCATENATED MODULE: ./lib/share/project-avatar-image.ts

async function getProjectAvatarTiny(project_id) {
    const pool = pool_default()("long");
    const { rows  } = await pool.query("SELECT avatar_image_tiny FROM projects WHERE project_id=$1", [
        project_id
    ]);
    return rows[0].avatar_image_tiny;
}

;// CONCATENATED MODULE: ./lib/share/get-public-paths.ts
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ /*
Get the public paths associated to a given project.  Unlisted paths are NOT included.
*/ 




async function getPublicPaths(project_id, req //  use to get account_id if necessary
) {
    if (!(0,util/* isUUID */.t)(project_id)) {
        throw Error("project_id must be a uuid");
    }
    // short: user might create a new public path then want to look at it shortly thereafter
    const pool = pool_default()("short");
    const result = await pool.query(`SELECT id, path, description, ${(0,dist_pool.timeInSeconds)("last_edited")}, disabled, unlisted, authenticated,
    counter::INT,
     (SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=id) AS stars
    FROM public_paths WHERE project_id=$1 ORDER BY stars DESC, last_edited DESC`, [
        project_id
    ]);
    const v = await filterNonPublicAndNotAuthenticated(result.rows, project_id, req);
    const avatar_image_tiny = await getProjectAvatarTiny(project_id);
    if (avatar_image_tiny) {
        for (const x of v){
            x.avatar_image_tiny = avatar_image_tiny;
        }
    }
    return v;
}
async function filterNonPublicAndNotAuthenticated(rows, project_id, req) {
    const v = [];
    let isCollab = undefined;
    let isAuthenticated = undefined;
    for (const row of rows){
        if (!row.disabled && !row.unlisted && !row.authenticated) {
            v.push(row);
            continue;
        }
        if (isCollab == null) {
            const account_id = await (0,get_account/* default */.Z)(req);
            isAuthenticated = account_id != null;
            if (account_id) {
                isCollab = await is_collaborator_default()({
                    account_id,
                    project_id
                });
            } else {
                isCollab = false;
            }
        }
        if (isCollab) {
            v.push(row);
        } else if (row.authenticated && isAuthenticated) {
            v.push(row);
        }
    }
    return v;
}

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

async function getProjectInfo(project_id, req) {
    return {
        publicPaths: await getPublicPaths(project_id, req),
        collaborators: await getCollaborators(project_id)
    };
}


/***/ }),

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ getProjectInfo)
/* 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 _util__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(809774);
/*
 *  This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ /*
Get information about a project.
*/ 

async function getProjectInfo(project_id, columns = [
    "title",
    "description",
    "name"
], // not cached by default since editing then reloading is confusing with this cached.
cache) {
    const pool = _cocalc_database_pool__WEBPACK_IMPORTED_MODULE_0___default()(cache);
    if (!(0,_util__WEBPACK_IMPORTED_MODULE_1__/* .isUUID */ .t)(project_id)) {
        throw Error(`project_id ${project_id} must be a uuid`);
    }
    const project = await pool.query(`SELECT ${columns.join(",")} FROM projects WHERE project_id=$1`, [
        project_id
    ]);
    if (project.rows.length == 0) {
        throw Error(`no project with id ${project_id}`);
    }
    const info = {};
    for (const name of columns){
        info[name] = project.rows[0][name] ?? "";
    }
    return info;
}


/***/ })

};
;