Compare commits

..

11 Commits

Author SHA1 Message Date
Tim
abbdb224e0 fix: restrict image preview to markdown images 2025-09-12 10:50:15 +08:00
Tim
37bef0b2d7 fix: remove 依赖 2025-09-12 10:15:17 +08:00
Tim
3519a41a2e Merge pull request #975 from nagisa77/feature/ffmpeg_load
Feature/ffmpeg load
2025-09-11 19:12:16 +08:00
tim
ab04a8b6b1 fix: ffmpeg 压缩适配 2025-09-11 19:10:14 +08:00
tim
ea079e8b8a fix: 简化ffmpeg配置 2025-09-11 18:36:47 +08:00
Tim
519656359f Merge pull request #974 from 4twocc/feat/message-box-shortcut
feat(MessageEditor): 添加发送消息的快捷键支持
2025-09-11 17:56:22 +08:00
jiahaosheng
dc64785279 feat: rename is.js to device.js 2025-09-11 17:53:08 +08:00
jiahaosheng
9421d004d4 feat(MessageEditor): 添加发送消息的快捷键支持 2025-09-11 17:27:54 +08:00
tim
90bd41e740 Revert "feat: switch video compression to webcodecs"
This reverts commit 3f35add587.
2025-09-11 17:20:08 +08:00
Tim
7d5c864f64 Merge pull request #973 from nagisa77/codex/switch-video-upload-to-webcodec-and-mp4box.js-bkkx49
feat: replace ffmpeg with WebCodecs and MP4Box.js
2025-09-11 17:02:08 +08:00
Tim
3f35add587 feat: switch video compression to webcodecs 2025-09-11 17:01:54 +08:00
14 changed files with 90 additions and 2500 deletions

View File

@@ -10,8 +10,3 @@ NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liOlrZnPKRF7s7NN
NUXT_PUBLIC_DISCORD_CLIENT_ID=1394985417044000779
NUXT_PUBLIC_TWITTER_CLIENT_ID=ZTRTU05KSk9KTTJrTTdrVC1tc1E6MTpjaQ
NUXT_PUBLIC_TELEGRAM_BOT_ID=8450237135
# 视频压缩配置 - FFmpeg.wasm 专用
# 支持 Chrome 60+ 和 Safari 11.1+
NUXT_PUBLIC_VIDEO_MAX_SIZE=52428800 # 20MB (字节)
NUXT_PUBLIC_VIDEO_TARGET_SIZE=20971520 # 5MB (字节)

View File

@@ -17,8 +17,3 @@ NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liVkO1NPAX5JyWxJ
NUXT_PUBLIC_DISCORD_CLIENT_ID=1394985417044000779
NUXT_PUBLIC_TWITTER_CLIENT_ID=ZTRTU05KSk9KTTJrTTdrVC1tc1E6MTpjaQ
NUXT_PUBLIC_TELEGRAM_BOT_ID=8450237135
# 视频压缩配置 - FFmpeg.wasm 专用
# 支持 Chrome 60+ 和 Safari 11.1+
NUXT_PUBLIC_VIDEO_MAX_SIZE=52428800 # 20MB (字节)
NUXT_PUBLIC_VIDEO_TARGET_SIZE=20971520 # 5MB (字节)

View File

@@ -15,8 +15,3 @@ NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liVkO1NPAX5JyWxJ
NUXT_PUBLIC_DISCORD_CLIENT_ID=1394985417044000779
NUXT_PUBLIC_TWITTER_CLIENT_ID=ZTRTU05KSk9KTTJrTTdrVC1tc1E6MTpjaQ
NUXT_PUBLIC_TELEGRAM_BOT_ID=8450237135
# 视频压缩配置 - FFmpeg.wasm 专用
# 支持 Chrome 60+ 和 Safari 11.1+
NUXT_PUBLIC_VIDEO_MAX_SIZE=52428800 # 20MB (字节)
NUXT_PUBLIC_VIDEO_TARGET_SIZE=20971520 # 5MB (字节)

View File

@@ -342,7 +342,7 @@ const copyCommentLink = () => {
const handleContentClick = (e) => {
handleMarkdownClick(e)
if (e.target.tagName === 'IMG') {
if (e.target.tagName === 'IMG' && !e.target.classList.contains('emoji')) {
const container = e.target.parentNode
const imgs = [...container.querySelectorAll('img')].map((i) => i.src)
lightboxImgs.value = imgs

View File

@@ -5,7 +5,10 @@
</div>
<div class="message-bottom-container">
<div class="message-submit" :class="{ disabled: isDisabled }" @click="submit">
<template v-if="!loading"> 发送 </template>
<template v-if="!loading">
发送
<span class="shortcut-icon" v-if="!isMobile"> {{ isMac ? '' : 'Ctrl' }} </span>
</template>
<template v-else> <loading-four /> 发送中... </template>
</div>
</div>
@@ -21,6 +24,8 @@ import {
getEditorTheme as getEditorThemeUtil,
getPreviewTheme as getPreviewThemeUtil,
} from '~/utils/vditor'
import { useIsMobile } from '~/utils/screen'
import { isMac } from '~/utils/device'
import '~/assets/global.css'
export default {
@@ -44,6 +49,7 @@ export default {
const vditorInstance = ref(null)
const text = ref('')
const editorId = ref(props.editorId)
const isMobile = useIsMobile()
if (!editorId.value) {
editorId.value = 'editor-' + useId()
}
@@ -84,6 +90,28 @@ export default {
applyTheme()
},
})
// 不是手机的情况下不添加快捷键
if (!isMobile.value) {
// 添加快捷键监听 (Ctrl+Enter 或 Cmd+Enter)
const handleKeydown = (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
e.preventDefault()
submit()
}
}
const el = document.getElementById(editorId.value)
if (el) {
el.addEventListener('keydown', handleKeydown)
}
onUnmounted(() => {
if (el) {
el.removeEventListener('keydown', handleKeydown)
}
})
}
})
onUnmounted(() => {
@@ -121,7 +149,7 @@ export default {
},
)
return { submit, isDisabled, editorId }
return { submit, isDisabled, editorId, isMac, isMobile }
},
}
</script>
@@ -168,4 +196,17 @@ export default {
.message-submit:not(.disabled):hover {
background-color: var(--primary-color-hover);
}
/** 评论按钮快捷键样式 */
.shortcut-icon {
padding: 2px 6px;
border-radius: 6px;
font-size: 12px;
font-weight: 500;
line-height: 1.2;
background-color: rgba(0, 0, 0, 0.25);
}
.comment-submit.disabled .shortcut-icon {
background-color: rgba(0, 0, 0, 0);
}
</style>

View File

@@ -3,53 +3,12 @@
* 专注于 FFmpeg.wasm 视频压缩,支持 Chrome/Safari
*/
// 声明全局变量以避免 TypeScript 错误
/* global useRuntimeConfig */
// 简化的环境变量读取功能
function getEnvNumber(key, defaultValue) {
if (typeof window !== 'undefined') {
// 客户端:尝试从 Nuxt 环境获取
try {
// 使用 globalThis 避免直接引用未定义的变量
const nuxtApp = globalThis.$nuxt || globalThis.nuxtApp
if (nuxtApp && nuxtApp.$config) {
const value = nuxtApp.$config.public?.[key.replace('NUXT_PUBLIC_', '').toLowerCase()]
return value ? Number(value) : defaultValue
}
return defaultValue
} catch {
return defaultValue
}
}
// 服务端:从 process.env 获取
return process.env[key] ? Number(process.env[key]) : defaultValue
}
function getEnvBoolean(key, defaultValue) {
if (typeof window !== 'undefined') {
try {
// 使用 globalThis 避免直接引用未定义的变量
const nuxtApp = globalThis.$nuxt || globalThis.nuxtApp
if (nuxtApp && nuxtApp.$config) {
const value = nuxtApp.$config.public?.[key.replace('NUXT_PUBLIC_', '').toLowerCase()]
return value === 'true' || value === true
}
return defaultValue
} catch {
return defaultValue
}
}
const envValue = process.env[key]
return envValue ? envValue === 'true' : defaultValue
}
export const UPLOAD_CONFIG = {
// 视频文件配置 - 专为 FFmpeg.wasm 优化
VIDEO: {
// 文件大小限制 (字节)
MAX_SIZE: getEnvNumber('NUXT_PUBLIC_VIDEO_MAX_SIZE', 20 * 1024 * 1024), // 5MB
TARGET_SIZE: getEnvNumber('NUXT_PUBLIC_VIDEO_TARGET_SIZE', 5 * 1024 * 1024), // 5MB
MAX_SIZE: 20 * 1024 * 1024,
TARGET_SIZE: 5 * 1024 * 1024, // 5MB
// 支持的输入格式 (FFmpeg.wasm 支持更多格式)
SUPPORTED_FORMATS: ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'm4v', 'ogv'],

View File

@@ -1,11 +1,4 @@
import { defineNuxtConfig } from 'nuxt/config'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const appPkg = require('./package.json') as {
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
}
export default defineNuxtConfig({
devServer: {
@@ -104,26 +97,9 @@ export default defineNuxtConfig({
},
},
vite: {
build: {
// increase warning limit and split large libraries into separate chunks
// chunkSizeWarningLimit: 1024,
// rollupOptions: {
// output: {
// manualChunks(id) {
// if (id.includes('node_modules')) {
// if (id.includes('vditor')) {
// return 'vditor'
// }
// if (id.includes('echarts')) {
// return 'echarts'
// }
// if (id.includes('highlight.js')) {
// return 'highlight'
// }
// }
// },
// },
// },
optimizeDeps: {
exclude: ['@ffmpeg/ffmpeg', '@ffmpeg/util'],
},
build: {},
},
})

View File

File diff suppressed because it is too large Load Diff

View File

@@ -13,7 +13,7 @@
},
"dependencies": {
"@icon-park/vue-next": "^1.4.2",
"@ffmpeg/ffmpeg": "^0.12.15",
"@ffmpeg/ffmpeg": "^0.12.2",
"@ffmpeg/util": "^0.12.2",
"@nuxt/image": "^1.11.0",
"@stomp/stompjs": "^7.0.0",

View File

@@ -463,7 +463,11 @@ function minimize() {
function handleContentClick(e) {
handleMarkdownClick(e)
if (e.target.tagName === 'IMG') {
if (
e.target.tagName === 'IMG' &&
!e.target.classList.contains('emoji') &&
!e.target.closest('.reactions-container')
) {
const container = e.target.parentNode
const imgs = [...container.querySelectorAll('img')].map((i) => i.src)
lightboxImgs.value = imgs

View File

@@ -434,7 +434,7 @@ const removeCommentFromList = (id, list) => {
const handleContentClick = (e) => {
handleMarkdownClick(e)
if (e.target.tagName === 'IMG') {
if (e.target.tagName === 'IMG' && !e.target.classList.contains('emoji')) {
const container = e.target.parentNode
const imgs = [...container.querySelectorAll('img')].map((i) => i.src)
lightboxImgs.value = imgs

View File

@@ -1,6 +1,6 @@
import { FFmpeg } from '@ffmpeg/ffmpeg'
import { toBlobURL } from '@ffmpeg/util'
import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
import { defineNuxtPlugin } from 'nuxt/app'
let ffmpeg: FFmpeg | null = null
@@ -10,11 +10,12 @@ export default defineNuxtPlugin(() => {
ffmpeg: async () => {
if (ffmpeg) return ffmpeg
ffmpeg = new FFmpeg()
const base = '~/assets/js/ffmpeg/core-mt/dist/umd'
const base = `https://unpkg.com/@ffmpeg/core@0.12.2/dist/esm`
const libBase = `https://unpkg.com/@ffmpeg/ffmpeg@0.12.2/dist/esm`
await ffmpeg.load({
coreURL: await toBlobURL(`${base}/ffmpeg-core.js`, 'text/javascript'),
wasmURL: await toBlobURL(`${base}/ffmpeg-core.wasm`, 'application/wasm'),
workerURL: await toBlobURL(`${base}/ffmpeg-core.worker.js`, 'text/javascript'),
workerURL: await toBlobURL(`${libBase}/worker.js`, 'text/javascript'),
})
return ffmpeg

View File

@@ -0,0 +1,28 @@
export const isClient = typeof window !== 'undefined' && typeof document !== 'undefined'
export const isMac = getIsMac()
function getIsMac() {
if (!isClient) {
return false
}
try {
// 优先使用现代浏览器的 navigator.userAgentData API
if (navigator.userAgentData && navigator.userAgentData.platform) {
return navigator.userAgentData.platform === 'macOS'
}
// 降级到传统的 User-Agent 检测
if (navigator.userAgent) {
return /Mac|iPhone|iPad|iPod/i.test(navigator.userAgent)
}
// 默认返回false
return false
} catch (error) {
// 异常处理,记录错误并返回默认值
console.warn('检测Mac设备时发生错误:', error)
return false
}
}

View File

@@ -118,7 +118,7 @@ export function createVditor(editorId, options = {}) {
// 如果是视频文件且需要压缩
if (isVideo && sizeCheck.needsCompression) {
try {
vditor.tip('视频压缩中...', 0)
vditor.tip('开始部署ffmpeg环境... 请稍等', 0)
vditor.disabled()
// 使用 FFmpeg 压缩视频