- 视频上传生成缩略图并提供占位封面和失败原因展示 - 支持 HLS 按需重新封装 MP4,并限制临时文件生命周期与访问权限 - 完善视频、文件 API 文档、搜索、批量删除和单次转码质量参数 - 修复备份恢复与跨后端迁移遗漏缩略图、HLS 清单和分片的问题 - 将备份任务、归档和下载权限按用户隔离 - 增加仅清理当前用户数据的高危存储清空流程和二次文字确认 - 修复 S3 中文文件名元数据及 CLI 数据库连接问题 - 补充备份恢复、用户隔离、媒体资源和转码相关测试
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type { ImageIndexRow } from './image-index'
|
|
import type { StorageBackend } from './storage/types'
|
|
import { hlsSegmentNames } from './transcode'
|
|
|
|
async function streamToString(stream: NodeJS.ReadableStream): Promise<string> {
|
|
const chunks: Buffer[] = []
|
|
for await (const chunk of stream) {
|
|
chunks.push(Buffer.from(chunk as Uint8Array))
|
|
}
|
|
return Buffer.concat(chunks).toString('utf8')
|
|
}
|
|
|
|
/** 一个媒体记录对应的全部存储对象,包括原文件、缩略图和 HLS 附属文件。 */
|
|
export async function collectMediaAssetKeys(
|
|
row: ImageIndexRow,
|
|
backend: Pick<StorageBackend, 'createStream'>
|
|
): Promise<string[]> {
|
|
const keys = new Set<string>()
|
|
|
|
if (Number(row.source_deleted ?? 0) !== 1) {
|
|
keys.add(row.key)
|
|
}
|
|
if (row.thumb_key) {
|
|
keys.add(row.thumb_key)
|
|
}
|
|
if (row.hls_key) {
|
|
keys.add(row.hls_key)
|
|
const dir = row.hls_key.slice(0, row.hls_key.lastIndexOf('/'))
|
|
const playlist = await streamToString(await backend.createStream(row.hls_key))
|
|
for (const name of hlsSegmentNames(playlist)) {
|
|
keys.add(`${dir}/${name}`)
|
|
}
|
|
}
|
|
|
|
return [...keys]
|
|
}
|