MCPcopy Create free account
hub / github.com/IsAvaible/AngularModUpdater / GET

Function GET

api/proxy-file.js:1–86  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

1export async function GET(request) {
2 return new Response("Vercel function file tunneling is currently disabled, due to quota limits.", {
3 status: 409
4 });
5
6 try {
7 // Get the file URL from query parameters
8 const { searchParams } = new URL(request.url);
9 const fileUrl = searchParams.get("url");
10
11 if (!fileUrl) {
12 return new Response("Missing file URL parameter", {
13 status: 400
14 });
15 }
16
17 // Validate URL format
18 let parsedUrl;
19 try {
20 parsedUrl = new URL(fileUrl);
21 } catch {
22 return new Response("Invalid URL format", {
23 status: 400
24 });
25 }
26
27 // Fetch the file from the provided URL
28 const response = await fetch(fileUrl);
29
30 if (!response.ok) {
31 return new Response(`Failed to fetch file: ${response.statusText}`, {
32 status: response.status
33 });
34 }
35
36 // Extract filename from URL or content-disposition header
37 const contentDisposition = response.headers.get("content-disposition");
38 let filename = fileUrl.split("/").pop(); // Default to last segment of URL
39
40 if (contentDisposition) {
41 const filenameMatch = contentDisposition.match(
42 /filename[^;=\n]*=(['"]*)(.*?)\1/
43 );
44 if (filenameMatch && filenameMatch[2]) {
45 filename = filenameMatch[2];
46 }
47 } else {
48 // Try to extract filename from URL path
49 const lastSegment = parsedUrl.pathname.split("/").pop();
50 if (lastSegment && lastSegment.includes(".")) {
51 filename = lastSegment;
52 }
53 }
54
55 // Get content type from the original response
56 const contentType =
57 response.headers.get("content-type") || "application/octet-stream";
58 const contentLength = response.headers.get("content-length");
59
60 // Create headers for file download

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected