commit dc2b36db5d917f0b78478263ef9bd35093b7f429 Author: Kegongteng Date: Tue Mar 25 21:47:40 2025 +0800 1st diff --git a/app/favicon.ico b/app/favicon.ico new file mode 100644 index 0000000..655ad59 Binary files /dev/null and b/app/favicon.ico differ diff --git a/app/globals.css b/app/globals.css new file mode 100644 index 0000000..ac68442 --- /dev/null +++ b/app/globals.css @@ -0,0 +1,94 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +body { + font-family: Arial, Helvetica, sans-serif; +} + +@layer utilities { + .text-balance { + text-wrap: balance; + } +} + +@layer base { + :root { + --background: 0 0% 100%; + --foreground: 0 0% 3.9%; + --card: 0 0% 100%; + --card-foreground: 0 0% 3.9%; + --popover: 0 0% 100%; + --popover-foreground: 0 0% 3.9%; + --primary: 0 0% 9%; + --primary-foreground: 0 0% 98%; + --secondary: 0 0% 96.1%; + --secondary-foreground: 0 0% 9%; + --muted: 0 0% 96.1%; + --muted-foreground: 0 0% 45.1%; + --accent: 0 0% 96.1%; + --accent-foreground: 0 0% 9%; + --destructive: 0 84.2% 60.2%; + --destructive-foreground: 0 0% 98%; + --border: 0 0% 89.8%; + --input: 0 0% 89.8%; + --ring: 0 0% 3.9%; + --chart-1: 12 76% 61%; + --chart-2: 173 58% 39%; + --chart-3: 197 37% 24%; + --chart-4: 43 74% 66%; + --chart-5: 27 87% 67%; + --radius: 0.5rem; + --sidebar-background: 0 0% 98%; + --sidebar-foreground: 240 5.3% 26.1%; + --sidebar-primary: 240 5.9% 10%; + --sidebar-primary-foreground: 0 0% 98%; + --sidebar-accent: 240 4.8% 95.9%; + --sidebar-accent-foreground: 240 5.9% 10%; + --sidebar-border: 220 13% 91%; + --sidebar-ring: 217.2 91.2% 59.8%; + } + .dark { + --background: 0 0% 3.9%; + --foreground: 0 0% 98%; + --card: 0 0% 3.9%; + --card-foreground: 0 0% 98%; + --popover: 0 0% 3.9%; + --popover-foreground: 0 0% 98%; + --primary: 0 0% 98%; + --primary-foreground: 0 0% 9%; + --secondary: 0 0% 14.9%; + --secondary-foreground: 0 0% 98%; + --muted: 0 0% 14.9%; + --muted-foreground: 0 0% 63.9%; + --accent: 0 0% 14.9%; + --accent-foreground: 0 0% 98%; + --destructive: 0 62.8% 30.6%; + --destructive-foreground: 0 0% 98%; + --border: 0 0% 14.9%; + --input: 0 0% 14.9%; + --ring: 0 0% 83.1%; + --chart-1: 220 70% 50%; + --chart-2: 160 60% 45%; + --chart-3: 30 80% 55%; + --chart-4: 280 65% 60%; + --chart-5: 340 75% 55%; + --sidebar-background: 240 5.9% 10%; + --sidebar-foreground: 240 4.8% 95.9%; + --sidebar-primary: 224.3 76.3% 48%; + --sidebar-primary-foreground: 0 0% 100%; + --sidebar-accent: 240 3.7% 15.9%; + --sidebar-accent-foreground: 240 4.8% 95.9%; + --sidebar-border: 240 3.7% 15.9%; + --sidebar-ring: 217.2 91.2% 59.8%; + } +} + +@layer base { + * { + @apply border-border; + } + body { + @apply bg-background text-foreground; + } +} diff --git a/app/gravatar/[...path]/route.ts b/app/gravatar/[...path]/route.ts new file mode 100644 index 0000000..a06a8a6 --- /dev/null +++ b/app/gravatar/[...path]/route.ts @@ -0,0 +1,120 @@ +import { type NextRequest, NextResponse } from "next/server" + +// Replace with your mirror site's domain +const upstream = "gravatar.com" + +// If it's a mobile-specific site, otherwise keep it the same as upstream +const upstream_mobile = "gravatar.com" + +// Countries you wish to block from accessing +const blocked_region: string[] = [] + +// IP addresses you wish to block from accessing +const blocked_ip_address: string[] = [] + +// Replace the domains in the text response +const replace_dict: Record = { + $upstream: "$custom_domain", + "//gravatar.com": "", +} + +export async function GET(request: NextRequest, { params }: { params: { path: string[] } }) { + const url = new URL(request.url) + const url_host = url.host + const user_agent = request.headers.get("user-agent") || "" + + // Determine if it's a mobile device + const is_desktop = await device_status(user_agent) + const upstream_domain = is_desktop ? upstream : upstream_mobile + + // Construct the upstream URL + const path = params.path.join("/") + const upstream_url = `https://${upstream_domain}/${path}${url.search}` + + try { + // Fetch from upstream + const upstream_response = await fetch(upstream_url, { + headers: { + Host: upstream_domain, + "User-Agent": user_agent, + Referer: url.href, + }, + }) + + // Clone the response so we can read it multiple times + const original_response = upstream_response.clone() + + // Get the response headers + const response_headers = new Headers(upstream_response.headers) + + // Set CORS headers + response_headers.set("access-control-allow-origin", "*") + response_headers.set("access-control-allow-credentials", "true") + + // Remove security headers that might cause issues + response_headers.delete("content-security-policy") + response_headers.delete("content-security-policy-report-only") + response_headers.delete("clear-site-data") + + // Get the content type + const content_type = response_headers.get("content-type") || "" + + // Process the response body + let response_body + if (content_type.includes("text/html") && content_type.includes("UTF-8")) { + // If it's HTML, replace text + const text = await original_response.text() + response_body = replace_response_text(text, upstream_domain, url_host) + } else { + // Otherwise, just pass through the body + response_body = original_response.body + } + + // Create and return the new response + return new NextResponse(response_body, { + status: upstream_response.status, + headers: response_headers, + }) + } catch (error) { + console.error("Gravatar proxy error:", error) + return new NextResponse("Error proxying to Gravatar", { status: 500 }) + } +} + +// Helper function to determine if the request is from a desktop device +function device_status(user_agent_info: string): boolean { + const agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"] + let flag = true + for (let v = 0; v < agents.length; v++) { + if (user_agent_info.indexOf(agents[v]) > 0) { + flag = false + break + } + } + return flag +} + +// Helper function to replace text in the response +function replace_response_text(text: string, upstream_domain: string, host_name: string): string { + for (const [i, j] of Object.entries(replace_dict)) { + let from = i + let to = j + + if (from === "$upstream") { + from = upstream_domain + } else if (from === "$custom_domain") { + from = host_name + } + + if (to === "$upstream") { + to = upstream_domain + } else if (to === "$custom_domain") { + to = host_name + } + + const re = new RegExp(from, "g") + text = text.replace(re, to) + } + return text +} + diff --git a/app/layout.tsx b/app/layout.tsx new file mode 100644 index 0000000..3323586 --- /dev/null +++ b/app/layout.tsx @@ -0,0 +1,19 @@ +import type { Metadata } from 'next' +import './globals.css' + +export const metadata: Metadata = { + title: 'Spircape API', + description: 'Spircape API', +} + +export default function RootLayout({ + children, +}: Readonly<{ + children: React.ReactNode +}>) { + return ( + + {children} + + ) +} diff --git a/app/page.tsx b/app/page.tsx new file mode 100644 index 0000000..ce53a47 --- /dev/null +++ b/app/page.tsx @@ -0,0 +1,264 @@ +"use client" + +import { useState } from "react" +import { Copy, CheckCheck, ExternalLink, ImageIcon, UserCircle, Code } from "lucide-react" +import { Button } from "@/components/ui/button" +import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" +import { AlertTriangle } from "lucide-react" +import { Badge } from "@/components/ui/badge" + +export default function Home() { + const [copied, setCopied] = useState(null) + const baseUrl = typeof window !== "undefined" ? window.location.origin : "" + const randomImageUrl = `${baseUrl}/random-image` + const gravatarProxyUrl = `${baseUrl}/gravatar` + + const copyToClipboard = (text: string, id: string) => { + navigator.clipboard.writeText(text) + setCopied(id) + setTimeout(() => setCopied(null), 2000) + } + + return ( +
+
+
+

+ API Services +

+

+ Connect the world with us +

+
+ + + + Access Restricted + + The API is not open to the public. If you need it, please contact us at{" "} + + 10010@spircape.com + + + + + + + + + Integration Guide + + Follow these examples to integrate our services into your application + + + + + + + Random Image + + + + Gravatar Proxy + + + + +
+
+

Random Image API

+ + GET + +
+

+ This API randomly serves an image from a predefined collection. Perfect for placeholder images, + random backgrounds, or testing purposes. +

+ +
+
+

+ + HTML Usage +

+
+
+                          {`Random image`}
+                        
+ +
+
+ +
+

+ + React Usage +

+
+
+                          {`import { useState } from 'react';\n\nfunction RandomImage() {\n  const [refresh, setRefresh] = useState(0);\n  \n  return (\n    Random image setRefresh(Date.now())}\n      className="cursor-pointer transition-opacity hover:opacity-90"\n    />\n  );\n}`}
+                        
+ +
+
+
+
+
+ + +
+
+

Gravatar Proxy

+ + GET + +
+

+ Our Gravatar proxy service improves loading speed and reliability for Gravatar images. It caches and + optimizes avatar delivery for your applications. +

+ +
+
+

+ + Basic Usage +

+
+
+                          {`\nUser avatar`}
+                        
+ +
+
+ +
+

+ + With Size Parameter +

+
+
+                          {`\nUser avatar`}
+                        
+ +
+
+ +
+

+ + With Default Image +

+
+
+                          {`\nUser avatar`}
+                        
+ +
+
+
+
+
+
+
+ +
+ + The above is for example only, please adjust according to the specific development environment +
+
+
+ +
+
+

© {new Date().getFullYear()} Spircape. All rights reserved.

+
+
+
+
+ ) +} + diff --git a/app/random-image/route.ts b/app/random-image/route.ts new file mode 100644 index 0000000..893b856 --- /dev/null +++ b/app/random-image/route.ts @@ -0,0 +1,21 @@ +import { type NextRequest, NextResponse } from "next/server" + +export async function GET(request: NextRequest) { + // List of image URLs + const imageUrls = [ + "https://zh.yuazhi.cn/apipng/18CD3BE92227887D576B2D4B7A9C9960.jpg", + "https://zh.yuazhi.cn/apipng/1.jpg", + "https://zh.yuazhi.cn/apipng/2.jpg", + "https://zh.yuazhi.cn/apipng/3.jpg", + "https://zh.yuazhi.cn/apipng/4.jpg", + "https://zh.yuazhi.cn/apipng/5.jpg", + ] + + // Select a random image URL + const randomIndex = Math.floor(Math.random() * imageUrls.length) + const randomImageUrl = imageUrls[randomIndex] + + // Redirect to the random image + return NextResponse.redirect(randomImageUrl) +} + diff --git a/components.json b/components.json new file mode 100644 index 0000000..d9ef0ae --- /dev/null +++ b/components.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://ui.shadcn.com/schema.json", + "style": "default", + "rsc": true, + "tsx": true, + "tailwind": { + "config": "tailwind.config.ts", + "css": "app/globals.css", + "baseColor": "neutral", + "cssVariables": true, + "prefix": "" + }, + "aliases": { + "components": "@/components", + "utils": "@/lib/utils", + "ui": "@/components/ui", + "lib": "@/lib", + "hooks": "@/hooks" + }, + "iconLibrary": "lucide" +} \ No newline at end of file diff --git a/components/theme-provider.tsx b/components/theme-provider.tsx new file mode 100644 index 0000000..55c2f6e --- /dev/null +++ b/components/theme-provider.tsx @@ -0,0 +1,11 @@ +'use client' + +import * as React from 'react' +import { + ThemeProvider as NextThemesProvider, + type ThemeProviderProps, +} from 'next-themes' + +export function ThemeProvider({ children, ...props }: ThemeProviderProps) { + return {children} +} diff --git a/components/ui/accordion.tsx b/components/ui/accordion.tsx new file mode 100644 index 0000000..24c788c --- /dev/null +++ b/components/ui/accordion.tsx @@ -0,0 +1,58 @@ +"use client" + +import * as React from "react" +import * as AccordionPrimitive from "@radix-ui/react-accordion" +import { ChevronDown } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Accordion = AccordionPrimitive.Root + +const AccordionItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AccordionItem.displayName = "AccordionItem" + +const AccordionTrigger = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + + svg]:rotate-180", + className + )} + {...props} + > + {children} + + + +)) +AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName + +const AccordionContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, children, ...props }, ref) => ( + +
{children}
+
+)) + +AccordionContent.displayName = AccordionPrimitive.Content.displayName + +export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } diff --git a/components/ui/alert-dialog.tsx b/components/ui/alert-dialog.tsx new file mode 100644 index 0000000..25e7b47 --- /dev/null +++ b/components/ui/alert-dialog.tsx @@ -0,0 +1,141 @@ +"use client" + +import * as React from "react" +import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog" + +import { cn } from "@/lib/utils" +import { buttonVariants } from "@/components/ui/button" + +const AlertDialog = AlertDialogPrimitive.Root + +const AlertDialogTrigger = AlertDialogPrimitive.Trigger + +const AlertDialogPortal = AlertDialogPrimitive.Portal + +const AlertDialogOverlay = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName + +const AlertDialogContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + + +)) +AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName + +const AlertDialogHeader = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +AlertDialogHeader.displayName = "AlertDialogHeader" + +const AlertDialogFooter = ({ + className, + ...props +}: React.HTMLAttributes) => ( +
+) +AlertDialogFooter.displayName = "AlertDialogFooter" + +const AlertDialogTitle = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName + +const AlertDialogDescription = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogDescription.displayName = + AlertDialogPrimitive.Description.displayName + +const AlertDialogAction = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName + +const AlertDialogCancel = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName + +export { + AlertDialog, + AlertDialogPortal, + AlertDialogOverlay, + AlertDialogTrigger, + AlertDialogContent, + AlertDialogHeader, + AlertDialogFooter, + AlertDialogTitle, + AlertDialogDescription, + AlertDialogAction, + AlertDialogCancel, +} diff --git a/components/ui/alert.tsx b/components/ui/alert.tsx new file mode 100644 index 0000000..41fa7e0 --- /dev/null +++ b/components/ui/alert.tsx @@ -0,0 +1,59 @@ +import * as React from "react" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const alertVariants = cva( + "relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground", + { + variants: { + variant: { + default: "bg-background text-foreground", + destructive: + "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", + }, + }, + defaultVariants: { + variant: "default", + }, + } +) + +const Alert = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes & VariantProps +>(({ className, variant, ...props }, ref) => ( +
+)) +Alert.displayName = "Alert" + +const AlertTitle = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +AlertTitle.displayName = "AlertTitle" + +const AlertDescription = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +AlertDescription.displayName = "AlertDescription" + +export { Alert, AlertTitle, AlertDescription } diff --git a/components/ui/aspect-ratio.tsx b/components/ui/aspect-ratio.tsx new file mode 100644 index 0000000..d6a5226 --- /dev/null +++ b/components/ui/aspect-ratio.tsx @@ -0,0 +1,7 @@ +"use client" + +import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio" + +const AspectRatio = AspectRatioPrimitive.Root + +export { AspectRatio } diff --git a/components/ui/avatar.tsx b/components/ui/avatar.tsx new file mode 100644 index 0000000..51e507b --- /dev/null +++ b/components/ui/avatar.tsx @@ -0,0 +1,50 @@ +"use client" + +import * as React from "react" +import * as AvatarPrimitive from "@radix-ui/react-avatar" + +import { cn } from "@/lib/utils" + +const Avatar = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +Avatar.displayName = AvatarPrimitive.Root.displayName + +const AvatarImage = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AvatarImage.displayName = AvatarPrimitive.Image.displayName + +const AvatarFallback = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName + +export { Avatar, AvatarImage, AvatarFallback } diff --git a/components/ui/badge.tsx b/components/ui/badge.tsx new file mode 100644 index 0000000..f000e3e --- /dev/null +++ b/components/ui/badge.tsx @@ -0,0 +1,36 @@ +import * as React from "react" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const badgeVariants = cva( + "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", + { + variants: { + variant: { + default: + "border-transparent bg-primary text-primary-foreground hover:bg-primary/80", + secondary: + "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", + destructive: + "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", + outline: "text-foreground", + }, + }, + defaultVariants: { + variant: "default", + }, + } +) + +export interface BadgeProps + extends React.HTMLAttributes, + VariantProps {} + +function Badge({ className, variant, ...props }: BadgeProps) { + return ( +
+ ) +} + +export { Badge, badgeVariants } diff --git a/components/ui/breadcrumb.tsx b/components/ui/breadcrumb.tsx new file mode 100644 index 0000000..60e6c96 --- /dev/null +++ b/components/ui/breadcrumb.tsx @@ -0,0 +1,115 @@ +import * as React from "react" +import { Slot } from "@radix-ui/react-slot" +import { ChevronRight, MoreHorizontal } from "lucide-react" + +import { cn } from "@/lib/utils" + +const Breadcrumb = React.forwardRef< + HTMLElement, + React.ComponentPropsWithoutRef<"nav"> & { + separator?: React.ReactNode + } +>(({ ...props }, ref) =>