1721
This commit is contained in:
1 parent
f00372d0a7
commit
79e5d3abb6
3 files changed
+32
-5
No files matched your search
@@ -5842,6 +5842,17 @@ a.link-card:hover .link-card-arrow {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
/* GIF 模式:自动播放、循环、无控制栏 */
|
||||
.video-player.gif-mode {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.video-player.gif-mode video {
|
||||
width: 100%;
|
||||
max-height: 500px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .video-player {
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
@@ -38,21 +38,28 @@
|
||||
{{ $src := .Get "src" }}
|
||||
{{ $poster := .Get "poster" }}
|
||||
{{ $caption := .Get "caption" }}
|
||||
{{ $loop := .Get "loop" | default "false" }}
|
||||
{{ $muted := .Get "muted" | default "false" }}
|
||||
{{ $isGifMode := or (eq $loop "true") (eq $muted "true") }}
|
||||
{{ $videoSrc := $src }}
|
||||
{{ if not (hasPrefix $src "http") }}
|
||||
{{ $videoSrc = printf "/%s/%s" .Page.Slug $src }}
|
||||
{{ end }}
|
||||
|
||||
<div class="video-wrap">
|
||||
<figure class="video-player" onclick="toggleVideo(this)">
|
||||
<figure class="video-player{{ if $isGifMode }} gif-mode{{ end }}" onclick="toggleVideo(this)">
|
||||
<video
|
||||
preload="metadata"
|
||||
playsinline
|
||||
webkit-playsinline
|
||||
{{ if eq $loop "true" }}loop{{ end }}
|
||||
{{ if eq $muted "true" }}muted{{ end }}
|
||||
{{ if $isGifMode }}autoplay{{ end }}
|
||||
{{ with $poster }}poster="{{ . }}"{{ end }}
|
||||
>
|
||||
<source src="{{ $videoSrc }}">
|
||||
</video>
|
||||
{{ if not $isGifMode }}
|
||||
<div class="video-play-icon">
|
||||
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
|
||||
</div>
|
||||
@@ -73,6 +80,7 @@
|
||||
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
{{ end }}
|
||||
</figure>
|
||||
{{ with $caption }}
|
||||
<figcaption class="video-caption">{{ . }}</figcaption>
|
||||
|
||||
@@ -100,9 +100,10 @@ export async function startPolling(): Promise<void> {
|
||||
|
||||
// 处理 GIF / 文档 / 视频
|
||||
if ((msg.animation || msg.document || msg.video) && hasSession(chatId)) {
|
||||
const fileType = msg.animation ? "animation" : msg.video ? "video" : "document";
|
||||
const file = msg.animation || msg.document || msg.video;
|
||||
if (file) {
|
||||
await handleDocument(chatId, file.file_id, file.file_name, msg.caption);
|
||||
await handleDocument(chatId, file.file_id, file.file_name, msg.caption, fileType);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -228,7 +229,7 @@ async function handlePhoto(chatId: number, photos: { file_id: string }[], captio
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDocument(chatId: number, fileId: string, fileName?: string, caption?: string) {
|
||||
async function handleDocument(chatId: number, fileId: string, fileName?: string, caption?: string, fileType?: string) {
|
||||
try {
|
||||
const fs = await import("fs");
|
||||
const path = await import("path");
|
||||
@@ -257,14 +258,21 @@ async function handleDocument(chatId: number, fileId: string, fileName?: string,
|
||||
const filename = Date.now() + "-" + fileId.slice(0, 8) + "." + ext;
|
||||
fs.writeFileSync(path.join(articleDir, filename), Buffer.from(fileBuffer));
|
||||
|
||||
// GIF 用图片语法,视频用 shortcode,其他用链接
|
||||
// 根据 Telegram 消息类型判断,而不是猜文件名
|
||||
const extLower = ext.toLowerCase();
|
||||
const isImage = ["gif", "webp", "png", "jpg", "jpeg"].includes(extLower);
|
||||
const isVideo = ["mp4", "webm", "mov", "avi", "mkv", "flv"].includes(extLower);
|
||||
const fileCaption = caption || fileName || "file";
|
||||
|
||||
if (isImage) {
|
||||
appendContent(chatId, `\n\n`);
|
||||
} else if (isVideo) {
|
||||
} else if (fileType === "animation") {
|
||||
// Telegram GIF 动画 → 自动播放、循环、静音
|
||||
appendContent(chatId, `\n{{< video src="${filename}" loop="true" muted="true" >}}\n`);
|
||||
await sendMessage(chatId, `🎞️ GIF 已保存:${filename}`);
|
||||
return;
|
||||
} else if (fileType === "video" || isVideo) {
|
||||
// 普通视频 → 带控制栏
|
||||
appendContent(chatId, `\n{{< video src="${filename}" caption="${fileCaption}" >}}\n`);
|
||||
await sendMessage(chatId, `🎬 视频已保存:${filename}`);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user