"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 });
const node_fetch_1 = __importDefault(require("node-fetch"));
const api_1 = require("./api");
async function getPublicPathInfoUrl(url) {
    if (!url.startsWith("url/")) {
        throw Error("url must start with 'url/'");
    }
    // TODO: more than just text documents...
    let content = undefined;
    let err = undefined;
    for (const start of ["https://", "http://"]) {
        try {
            content = await (await (0, node_fetch_1.default)(`${start}${url.slice("url/".length)}`, {
                size: api_1.RAW_MAX_SIZE_BYTES,
            })).text();
            break;
        }
        catch (_err) {
            err = _err;
        }
    }
    if (content == null) {
        throw err;
    }
    return {
        contents: { content, size: content.length },
        relativePath: "",
        projectTitle: `Document at ${url}`,
    };
}
exports.default = getPublicPathInfoUrl;
//# sourceMappingURL=get-public-path-info-url.js.map