@faiber/faiber-drm

中文文档
2.7.0发布于 2026/11/05TypeScriptES Module近 30 天下载 3802

Typed media storage, protected playback, resumable uploads, DRM packaging, content libraries, compositions, analysis, and Knowledge synchronization.

原始使用文档

@faiber/faiber-drm

Typed media storage, protected playback, resumable uploads, DRM packaging, content libraries, compositions, analysis, and Knowledge synchronization.

npm install @faiber/faiber-drm
import { DrmApi, FaiberClient, MemoryTokenProvider } from "@faiber/faiber-drm";

const drm = new DrmApi(new FaiberClient("drm", {
  domains: { drm: "https://drm.example.com" },
  tokenProvider: new MemoryTokenProvider({ accessToken }),
  axios: { timeout: 15_000 },
}));

const page = await drm.media({ search: "intro", media_type: "video", page: 1, size: 30 });
const uploaded = await drm.uploadMedia({ file, filename: "intro.mp4", name: "Introduction", tag_ids: [tagId] });
const original = await drm.playback(uploaded.data.id);
const statuses = await drm.drmStatuses({ ids: uploaded.data.id });
const packages = await drm.mediaPackages(uploaded.data.id);

Configure the service origin without /api/v1. Use an in-memory token provider or secure HttpOnly cookies with axios: { withCredentials: true }. The pinned backend's IDP middleware extracts trusted identity headers with development fallback; it does not itself verify Bearer tokens. Deploy behind an enforcing identity gateway that verifies credentials and controls those headers. The SDK sends configured credentials through the shared FaiberClient on every call. The public status endpoint needs no identity. Gateway authority and native service acceptance require deployment verification.

Media includes audio, video, and images. Multipart uploads use standard FormData; metadata fields are text and tag_ids is a JSON UUID array. Video upload automatically queues packaging and optional transcription. Original playback is a signed URL valid for 900 seconds and works independently of package readiness; archived media is unavailable. Media records include nullable transcription, original filename, checksum and archive timestamp. Batch media deduplicates IDs, returns at most 50 existing records in request order and omits missing records.

For large files, create a resumable upload session, send numbered raw byte parts, then complete it:

const session = await drm.createUploadSession({
  filename: "lecture.mp4", mime_type: file.type, total_bytes: file.size,
});
for (let start = 0, part = 1; start < file.size; start += session.data.part_size, part++) {
  await drm.uploadPart(session.data.id, part, file.slice(start, start + session.data.part_size));
}
const completed = await drm.completeUpload(session.data.id, {});

Sessions expire after 24 hours. Parts are numbered 1–10000, must be nonempty, and cannot exceed part_size (default 10 MiB, bounded to 5–64 MiB). Reuploading a part replaces its metadata. Completion checks the total uploaded and stored byte counts; repeating completed completion returns the existing media with HTTP 200 instead of 201. The supplied checksum is stored metadata. Cancel returns HTTP 204.

packageFile(packageId, "video/segment-1.m4s", { headers: { Range: "bytes=0-1023" } }) returns raw ArrayBuffer data and preserves HTTP 200/206, content type and range headers. Package files and ClearKey licenses require authenticated shared transport. Wildcard paths use raw nonempty segments; separators remain intact. Percent escapes, dot traversal, query/fragment syntax and backslashes fail locally. A package must be ready; otherwise downloads return 409. ClearKey requires { package_id } and returns temporary JWK key material; keep it private.

The client exposes all 96 mounted operations through drm.operations, with convenience methods for common workflows. Each operation documents its source permission: media, package, composition, content, library, license and audit grants apply by route. Operations settings and transcription model catalog require drm:manage; permanent library deletion requires drm:library:delete. Listing libraries includes public libraries only; direct library access follows the route permission. Category and item deletes archive them, while deleting a library permanently removes its content and compositions. Knowledge sync/catalog additionally require an x-organization-id UUID header unless the server configures a default organization.

Paginated media, compositions, item queries, jobs, analyses and audit events return { data, page, page_size, total_items }, without an extra envelope. Pages start at 1 and sizes clamp to 1–100. Defaults are 30 for media/items/jobs, 20 for compositions/analyses, and 50 for audit. Other endpoints return bare records or arrays. An absent composition analysis returns JSON null; successful deletes return no body. Requests retain snake_case fields. category_id: null clears a mixed-media category; the pinned backend's ordinary nested optional fields such as media folder_id and composition description treat JSON null as no change. Workflow nodes/edges must be arrays; nested editor data, historical documents and metadata remain documented dynamic JSON. The Knowledge catalog is an unmodified upstream JSON response.

Every call returns the complete Axios response and supports request options including headers, cancellation signals, timeout, credentials and adapters. Axios errors retain backend status and { error } payloads for local validation (400), authorization (401/403), missing resources (404), conflicts (409) and internal failures (500); extractor failures may use framework error bodies. Cancellation rejects with the Axios cancellation error. The complete Faiber SDK includes the same service client as sdk.drm.

Preview a classroom composition

With the complete SDK, pass any LMS session row to sdk.drm.classroomSessionComposition(row, { signal }). The method uses row.media.drm_mixed_media_id, with row.course_session.drm_mixed_media_id as a fallback, and returns the full Axios response containing the published manifest (data.document and data.version). drm.compositionManifest(compositionId) accepts an ID directly.

Both methods require drm:composition:read and use the DRM client's authenticated transport. They are independent of classroom type, start time, lock and room provisioning. No linked composition throws TypeError before HTTP; no published manifest returns 404. The manifest is player input, not a public MP4 URL. Media/package/license access retains its own DRM grants.

版本与发布记录

@faiber/faiber-drm 共发布 57 个版本,首次发布于 2026/08/09;过去 12 个月发布了 57 个版本。

版本发布日期距今
2.7.0latest2026/11/059 天前
2.6.02026/11/049 天前
2.5.02026/11/049 天前
2.4.02026/11/0310 天前
2.3.02026/11/0211 天前
2.2.02026/11/0212 天前

关于 @faiber/faiber-drm 的常见问题

@faiber/faiber-drm 是什么?

Typed media storage, protected playback, resumable uploads, DRM packaging, content libraries, compositions, analysis, and Knowledge synchronization.

如何安装 @faiber/faiber-drm?

在项目目录运行 npm install @faiber/faiber-drm,或使用 pnpm add / yarn add / bun add。

@faiber/faiber-drm 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@faiber/faiber-drm 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@faiber/faiber-drm 可以商用吗?

@faiber/faiber-drm 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@faiber/faiber-drm 的下载量有多少?

根据 npm 官方下载统计,@faiber/faiber-drm 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,802 次,日均约 127 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@faiber/faiber-drm 还在维护吗?

最新版本 2.7.0 发布于 2026/11/05(9 天前);至今共发布 57 个版本,其中过去 12 个月发布了 57 个;首次发布于 2026/08/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。