@dazl/wix-media-客户端
通过 dazl API 服务器为 Wix 媒体平台浏览器客户端.
特征
- 列出带有光标的媒体文件
- 带有进度跟踪和自动媒体记录创建的文件上传
- 带有转换的图像 URL 生成( 填充、 适应、 裁剪)
- 非图像的直接文件 URL 生成
- 响应图像集生成
- 类型脚本, 零依赖, 浏览器安全
快速启动
所有 API 函数都使用 endpoint 指向媒体API. 客户端在内部附加子路由.
const endpoint = "https://api.dazl.dev/api/media";
列表文件
import { listFiles } from "@dazl/wix-media-client";
const result = await listFiles({ endpoint, projectId: "project-uuid" });
// Filter by type
const images = await listFiles({ endpoint, projectId: "project-uuid", mimeType: "image/" });
// Paginate
const page2 = await listFiles({ endpoint, projectId: "project-uuid", cursor: result.nextCursor! });
上传文件
import { uploadFile } from "@dazl/wix-media-client";
const result = await uploadFile({
endpoint,
projectId: "project-uuid",
file: selectedFile,
onProgress: (progress) => console.log(`${progress.toFixed(0)}%`),
});
上传流量 :
POST {endpoint}/upload-configuration——获得一个预先签名的Wix上传URLPUT直接到 Wix CDN (通过 XHR 跟踪进度)POST {endpoint}在数据库中创建媒体记录
图像 URL
import { getFileUrl } from "@dazl/wix-media-client";
const MEDIA_HOST = "wixmp-abc123.appspot.com";
// Image with transforms
const thumbnail = getFileUrl(MEDIA_HOST, { path: "/projects/xxx/photo.jpg", mimeType: "image/jpeg" }, {
operation: "fill",
width: 200,
height: 200,
quality: 85,
format: "webp",
});
// Fit within bounds — both `width` and `height` are required by the wixmp
// image service. `fit` preserves aspect ratio so the actual output is bounded
// by whichever axis hits first.
const url = getFileUrl(MEDIA_HOST, { path: "/projects/xxx/photo.jpg", mimeType: "image/jpeg" }, {
operation: "fit",
width: 800,
height: 800,
});
// No transform commands — defaults to fit 1000x1000 (handy for LLM URL fetchers).
const defaultUrl = getFileUrl(MEDIA_HOST, { path: "/projects/xxx/photo.jpg", mimeType: "image/jpeg" });
// Non-image (returns direct URL automatically)
const pdfUrl = getFileUrl(MEDIA_HOST, { path: "/projects/xxx/doc.pdf", mimeType: "application/pdf" });
API 参考
listFiles(options): Promise<ListFilesResponse>
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
endpoint | string | 所需经费 | 媒体 API 端点 |
projectId | string | 所需经费 | 项目标识符 |
mimeType | string | - 说吧 | 由 MIME 类型前缀过滤( 例如 ), 'image/'(中文(简体) ) |
cursor | string | - 说吧 | 下一页的光标符 |
pageSize | number | 20 | 每页项目 |
回返 { items: MediaItem[], nextCursor: string | null, total: number }
uploadFile(options): Promise<UploadResult>
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
endpoint | string | 所需经费 | 媒体 API 端点 |
projectId | string | 所需经费 | 项目标识符 |
file | File | 所需经费 | 要上传的文件 |
acl | 'public' | 'private' | 'public' | 访问控制 |
onProgress | (progress: number) => void | - 说吧 | 进度回调 (0- 100) |
createMediaRecord | false | - 说吧 | 设定为 false 以跳过 DB 记录创建 |
回返 { success, path, filename, descriptor }
getFileUrl(mediaHost, file, commands?): string
生成文件的适当 URL 。 可缩放的图像(PNG,JPEG,GIF,WebP)通过有变换功能的Wix图像服务. 非可缩放图像(SVG,ICO)和非相片获得直接URL.
何时 commands 中,漏出光栅图像 fit 1000×1000 默认(a) console.warn 用于鼓励来电者指定自己的。 Wixmp 图像服务需要 两者 width 财务报告和审定财务报表 height 页:1 fit编号 :fill编号 :crop 操作——单凹变换回HTTP 400 missing h。 。 。 .
isImageMimeType(mimeType): boolean
createResponsiveImageSet(mediaHost, path, options): Record<number, string>
每个条目 dimensions 生成为 fit dimension×dimension (平分盖. fit 保存宽比,所以实际输出以先击后击的轴为界.
createSrcSet(mediaHost, path, options): string
许可证
无效