Path: blob/master/src/packages/next/lib/share/proxy/get-public-path-info-url.ts
1451 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// provided by nextjs: https://nextjs.org/blog/next-9-4#improved-built-in-fetch-support6declare var fetch;78import { RAW_MAX_SIZE_BYTES } from "./api";910export default async function getPublicPathInfoUrl(url: string) {11if (!url.startsWith("url/")) {12throw Error("url must start with 'url/'");13}14// TODO: more than just text documents...15let content: string | undefined = undefined;16let err: Error | undefined = undefined;17for (const start of ["https://", "http://"]) {18try {19content = await (20await fetch(`${start}${url.slice("url/".length)}`, {21size: RAW_MAX_SIZE_BYTES,22})23).text();24break;25} catch (_err) {26err = _err;27}28}29if (content == null) {30throw err;31}32return {33contents: { content, size: content.length },34relativePath: "",35projectTitle: `Document at ${url}`,36};37}383940