在原仓库历史之上同步本服务器上的全部演进: - 迁移至新服务器并重建 PG 数据库 + ddnc 开发域名绑定 - 全部依赖升级至最新(Next 16.3.5 / React 19.3 / better-auth 1.7.5 / Drizzle 0.45 / TS 7), overrides 消除已知 CVE,安全审计 19 项发现全部修复闭环 - 设计统一:各站宽度 token(--container + site-container)、classic hero 重设计、 头部换行修复、页面过渡与 View Transitions - 截图功能:api.adx9.com 截图服务接入(ow=800 本地化 webp、cf=1、去重/限流/占位图) - SEO 底座化:canonical/hreflang/sitemap/JSON-LD/robots 全部收进 core,新站自动继承 - 加载体验:五站五形态路由骨架(data-theme 切换、shimmer 微光、延迟淡入)+ 过滤 useTransition 交叉淡入淡出(card-enter 错峰入场) - 构建:experimental.cpus 限流防 PG 连接打满;清理死组件链
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
buildScreenshotUrl,
|
|
isValidSlug,
|
|
screenshotFilePath,
|
|
} from "../src/lib/screenshot";
|
|
|
|
describe("buildScreenshotUrl", () => {
|
|
test("包含必填的编码后 url 与默认参数", () => {
|
|
const url = buildScreenshotUrl("https://example.com/a?b=1&c=2");
|
|
expect(url.startsWith("https://api.adx9.com/screenshot/v1?")).toBe(true);
|
|
expect(url).toContain(`url=${encodeURIComponent("https://example.com/a?b=1&c=2")}`);
|
|
expect(url).toContain("mode=viewport");
|
|
expect(url).toContain("w=1440");
|
|
expect(url).toContain("h=900");
|
|
expect(url).toContain("ow=800");
|
|
expect(url).toContain("cf=1");
|
|
expect(url).toContain("format=webp");
|
|
expect(url).toContain("q=85");
|
|
expect(url).toContain("wait=3");
|
|
});
|
|
|
|
test("支持覆盖视口/输出参数", () => {
|
|
const url = buildScreenshotUrl("https://example.com", {
|
|
w: 1280,
|
|
h: 800,
|
|
format: "jpeg",
|
|
q: 70,
|
|
wait: 5,
|
|
ow: 640,
|
|
fit: "contain",
|
|
});
|
|
expect(url).toContain("w=1280");
|
|
expect(url).toContain("h=800");
|
|
expect(url).toContain("format=jpeg");
|
|
expect(url).toContain("q=70");
|
|
expect(url).toContain("wait=5");
|
|
expect(url).toContain("ow=640");
|
|
expect(url).toContain("fit=contain");
|
|
});
|
|
});
|
|
|
|
describe("isValidSlug", () => {
|
|
test("合法 slug", () => {
|
|
expect(isValidSlug("github-copilot")).toBe(true);
|
|
expect(isValidSlug("chatgpt")).toBe(true);
|
|
expect(isValidSlug("a1-b2")).toBe(true);
|
|
});
|
|
|
|
test("拒绝路径穿越与非法字符", () => {
|
|
expect(isValidSlug("../etc/passwd")).toBe(false);
|
|
expect(isValidSlug("a/b")).toBe(false);
|
|
expect(isValidSlug("a b")).toBe(false);
|
|
expect(isValidSlug("")).toBe(false);
|
|
expect(isValidSlug("-abc")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("screenshotFilePath", () => {
|
|
test("slug 映射为 <目录>/<slug>.webp", () => {
|
|
const p = screenshotFilePath("github-copilot");
|
|
expect(p.endsWith("github-copilot.webp")).toBe(true);
|
|
});
|
|
});
|