CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/lib/share/proxy/get-public-path-info-gist.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// provided by nextjs: https://nextjs.org/blog/next-9-4#improved-built-in-fetch-support
7
declare var fetch;
8
9
import { RAW_MAX_SIZE_BYTES } from "./api";
10
11
export default async function getPublicPathInfoGist(
12
url: string // 'gist/user/gistId'
13
) {
14
const v = url.split("/");
15
if (v.length < 3) {
16
throw Error(`invalid gist url - "${url}"`);
17
}
18
const [_, user, gistId] = v;
19
const rawUrl = `https://gist.githubusercontent.com/${user}/${gistId}/raw/`;
20
const content = await (await fetch(rawUrl, { size: RAW_MAX_SIZE_BYTES })).text();
21
return {
22
contents: { content, size: content.length },
23
relativePath: "",
24
projectTitle: `${user}'s GitHub Gists -- https://gist.github.com/${user}`,
25
githubOrg: user,
26
};
27
}
28
29