Skip to content

Commit ec9960c

Browse files
authored
Merge pull request #223 from RafDevX/pastebin-then-corsanywhere
feat: prefer direct Pastebin fetching to proxying
2 parents 667335c + 8341a2f commit ec9960c

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/lib/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { twMerge } from "tailwind-merge";
44
import {
55
PASTEBIN_API_POST_URL,
66
PASTEBIN_API_RAW_URL,
7+
PASTEBIN_API_RAW_URL_PROXIED,
78
} from "@/maps/api/constants";
89

910
export function cn(...inputs: ClassValue[]) {
@@ -84,7 +85,14 @@ export async function uploadToPastebin(
8485
}
8586

8687
export async function fetchFromPastebin(pasteId: string): Promise<string> {
87-
const response = await fetch(PASTEBIN_API_RAW_URL + pasteId);
88+
let response;
89+
try {
90+
// prefer querying Pastebin directly since CORS proxy is unreliable
91+
response = await fetch(PASTEBIN_API_RAW_URL + pasteId);
92+
} catch {
93+
// CORS error; happens if the paste is not owned by a Pastebin Pro user
94+
response = await fetch(PASTEBIN_API_RAW_URL_PROXIED + pasteId);
95+
}
8896

8997
if (!response.ok) {
9098
throw new Error(

src/maps/api/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export const OVERPASS_API_FALLBACK =
66
export const GEOCODER_API = "https://photon.komoot.io/api/";
77
export const PASTEBIN_API_POST_URL =
88
"https://cors-anywhere.com/https://pastebin.com/api/api_post.php";
9-
export const PASTEBIN_API_RAW_URL =
9+
export const PASTEBIN_API_RAW_URL = "https://pastebin.com/raw/";
10+
export const PASTEBIN_API_RAW_URL_PROXIED =
1011
"https://cors-anywhere.com/https://pastebin.com/raw/";
1112

1213
export const ICON_COLORS = {

0 commit comments

Comments
 (0)