1721
This commit is contained in:
1 parent
0cc176e867
commit
60354b982e
3 files changed
+32
-5
No files matched your search
@@ -5842,6 +5842,17 @@ a.link-card:hover .link-card-arrow {
|
|||||||
color: #9ca3af;
|
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 {
|
[data-theme="dark"] .video-player {
|
||||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,21 +38,28 @@
|
|||||||
{{ $src := .Get "src" }}
|
{{ $src := .Get "src" }}
|
||||||
{{ $poster := .Get "poster" }}
|
{{ $poster := .Get "poster" }}
|
||||||
{{ $caption := .Get "caption" }}
|
{{ $caption := .Get "caption" }}
|
||||||
|
{{ $loop := .Get "loop" | default "false" }}
|
||||||
|
{{ $muted := .Get "muted" | default "false" }}
|
||||||
|
{{ $isGifMode := or (eq $loop "true") (eq $muted "true") }}
|
||||||
{{ $videoSrc := $src }}
|
{{ $videoSrc := $src }}
|
||||||
{{ if not (hasPrefix $src "http") }}
|
{{ if not (hasPrefix $src "http") }}
|
||||||
{{ $videoSrc = printf "/%s/%s" .Page.Slug $src }}
|
{{ $videoSrc = printf "/%s/%s" .Page.Slug $src }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<div class="video-wrap">
|
<div class="video-wrap">
|
||||||
<figure class="video-player" onclick="toggleVideo(this)">
|
<figure class="video-player{{ if $isGifMode }} gif-mode{{ end }}" onclick="toggleVideo(this)">
|
||||||
<video
|
<video
|
||||||
preload="metadata"
|
preload="metadata"
|
||||||
playsinline
|
playsinline
|
||||||
webkit-playsinline
|
webkit-playsinline
|
||||||
|
{{ if eq $loop "true" }}loop{{ end }}
|
||||||
|
{{ if eq $muted "true" }}muted{{ end }}
|
||||||
|
{{ if $isGifMode }}autoplay{{ end }}
|
||||||
{{ with $poster }}poster="{{ . }}"{{ end }}
|
{{ with $poster }}poster="{{ . }}"{{ end }}
|
||||||
>
|
>
|
||||||
<source src="{{ $videoSrc }}">
|
<source src="{{ $videoSrc }}">
|
||||||
</video>
|
</video>
|
||||||
|
{{ if not $isGifMode }}
|
||||||
<div class="video-play-icon">
|
<div class="video-play-icon">
|
||||||
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
|
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>
|
||||||
</div>
|
</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>
|
<svg viewBox="0 0 24 24" fill="currentColor"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{{ end }}
|
||||||
</figure>
|
</figure>
|
||||||
{{ with $caption }}
|
{{ with $caption }}
|
||||||
<figcaption class="video-caption">{{ . }}</figcaption>
|
<figcaption class="video-caption">{{ . }}</figcaption>
|
||||||
|
|||||||
@@ -100,9 +100,10 @@ export async function startPolling(): Promise<void> {
|
|||||||
|
|
||||||
// 处理 GIF / 文档 / 视频
|
// 处理 GIF / 文档 / 视频
|
||||||
if ((msg.animation || msg.document || msg.video) && hasSession(chatId)) {
|
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;
|
const file = msg.animation || msg.document || msg.video;
|
||||||
if (file) {
|
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;
|
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 {
|
try {
|
||||||
const fs = await import("fs");
|
const fs = await import("fs");
|
||||||
const path = await import("path");
|
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;
|
const filename = Date.now() + "-" + fileId.slice(0, 8) + "." + ext;
|
||||||
fs.writeFileSync(path.join(articleDir, filename), Buffer.from(fileBuffer));
|
fs.writeFileSync(path.join(articleDir, filename), Buffer.from(fileBuffer));
|
||||||
|
|
||||||
// GIF 用图片语法,视频用 shortcode,其他用链接
|
// 根据 Telegram 消息类型判断,而不是猜文件名
|
||||||
const extLower = ext.toLowerCase();
|
const extLower = ext.toLowerCase();
|
||||||
const isImage = ["gif", "webp", "png", "jpg", "jpeg"].includes(extLower);
|
const isImage = ["gif", "webp", "png", "jpg", "jpeg"].includes(extLower);
|
||||||
const isVideo = ["mp4", "webm", "mov", "avi", "mkv", "flv"].includes(extLower);
|
const isVideo = ["mp4", "webm", "mov", "avi", "mkv", "flv"].includes(extLower);
|
||||||
const fileCaption = caption || fileName || "file";
|
const fileCaption = caption || fileName || "file";
|
||||||
|
|
||||||
if (isImage) {
|
if (isImage) {
|
||||||
appendContent(chatId, `\n\n`);
|
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`);
|
appendContent(chatId, `\n{{< video src="${filename}" caption="${fileCaption}" >}}\n`);
|
||||||
await sendMessage(chatId, `🎬 视频已保存:${filename}`);
|
await sendMessage(chatId, `🎬 视频已保存:${filename}`);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user