Spaces:
Paused
Paused
Download server/src/services/github-fetch.ts from testfirela/paperclip-app: direct link, hf CLI and curl.
- Browser
- Download file 946 Bytes
-
https://huggingface.co/spaces/testfirela/paperclip-app/resolve/main/server/src/services/github-fetch.ts
- Command line
-
hf download hf://spaces/testfirela/paperclip-app/server/src/services/github-fetch.ts
-
curl -L -o github-fetch.ts https://huggingface.co/spaces/testfirela/paperclip-app/resolve/main/server/src/services/github-fetch.ts
946 Bytes
| import { unprocessable } from "../errors.js"; | |
| function isGitHubDotCom(hostname: string) { | |
| const h = hostname.toLowerCase(); | |
| return h === "github.com" || h === "www.github.com"; | |
| } | |
| export function gitHubApiBase(hostname: string) { | |
| return isGitHubDotCom(hostname) ? "https://api.github.com" : `https://${hostname}/api/v3`; | |
| } | |
| export function resolveRawGitHubUrl(hostname: string, owner: string, repo: string, ref: string, filePath: string) { | |
| const p = filePath.replace(/^\/+/, ""); | |
| return isGitHubDotCom(hostname) | |
| ? `https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${p}` | |
| : `https://${hostname}/raw/${owner}/${repo}/${ref}/${p}`; | |
| } | |
| export async function ghFetch(url: string, init?: RequestInit): Promise<Response> { | |
| try { | |
| return await fetch(url, init); | |
| } catch { | |
| throw unprocessable(`Could not connect to ${new URL(url).hostname} — ensure the URL points to a GitHub or GitHub Enterprise instance`); | |
| } | |
| } | |