mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-07 23:51:17 +08:00
Compare commits
21 Commits
codex/fix-
...
codex/swit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08fe8a30c1 | ||
|
|
6f4b17f96e | ||
|
|
1e284e15df | ||
|
|
9d76926b8a | ||
|
|
d2ce203236 | ||
|
|
b2228296af | ||
|
|
7020ae19d0 | ||
|
|
227fb6f6cc | ||
|
|
0e46a67ea6 | ||
|
|
b20b705e46 | ||
|
|
4b3ffbab99 | ||
|
|
74039c89f9 | ||
|
|
10dca73d2f | ||
|
|
e37ed1b70b | ||
|
|
8500a7a914 | ||
|
|
3adf722b3b | ||
|
|
791e5a4daf | ||
|
|
7d25e87fbc | ||
|
|
d02c316a70 | ||
|
|
c189c80c05 | ||
|
|
07db73c9c7 |
@@ -1,6 +1,7 @@
|
||||
package com.openisle.config;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
@@ -23,6 +24,7 @@ import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class RabbitMQConfig {
|
||||
|
||||
public static final String EXCHANGE_NAME = "openisle-exchange";
|
||||
@@ -38,7 +40,7 @@ public class RabbitMQConfig {
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
System.out.println("RabbitMQ配置初始化: 队列数量=" + queueCount + ", 持久化=" + queueDurable);
|
||||
log.info("RabbitMQ配置初始化: 队列数量={}, 持久化={}", queueCount, queueDurable);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -51,7 +53,7 @@ public class RabbitMQConfig {
|
||||
*/
|
||||
@Bean
|
||||
public List<Queue> shardedQueues() {
|
||||
System.out.println("开始创建分片队列 Bean...");
|
||||
log.info("开始创建分片队列 Bean...");
|
||||
|
||||
List<Queue> queues = new ArrayList<>();
|
||||
for (int i = 0; i < queueCount; i++) {
|
||||
@@ -61,7 +63,7 @@ public class RabbitMQConfig {
|
||||
queues.add(queue);
|
||||
}
|
||||
|
||||
System.out.println("分片队列 Bean 创建完成,总数: " + queues.size());
|
||||
log.info("分片队列 Bean 创建完成,总数: {}", queues.size());
|
||||
return queues;
|
||||
}
|
||||
|
||||
@@ -70,7 +72,7 @@ public class RabbitMQConfig {
|
||||
*/
|
||||
@Bean
|
||||
public List<Binding> shardedBindings(TopicExchange exchange, @Qualifier("shardedQueues") List<Queue> shardedQueues) {
|
||||
System.out.println("开始创建分片绑定 Bean...");
|
||||
log.info("开始创建分片绑定 Bean...");
|
||||
List<Binding> bindings = new ArrayList<>();
|
||||
if (shardedQueues != null) {
|
||||
for (Queue queue : shardedQueues) {
|
||||
@@ -82,7 +84,7 @@ public class RabbitMQConfig {
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("分片绑定 Bean 创建完成,总数: " + bindings.size());
|
||||
log.info("分片绑定 Bean 创建完成,总数: {}", bindings.size());
|
||||
return bindings;
|
||||
}
|
||||
|
||||
@@ -135,14 +137,14 @@ public class RabbitMQConfig {
|
||||
@Qualifier("shardedBindings") List<Binding> shardedBindings,
|
||||
Binding legacyBinding) {
|
||||
return args -> {
|
||||
System.out.println("=== 开始主动声明 RabbitMQ 组件 ===");
|
||||
log.info("=== 开始主动声明 RabbitMQ 组件 ===");
|
||||
|
||||
try {
|
||||
// 声明交换
|
||||
rabbitAdmin.declareExchange(exchange);
|
||||
|
||||
// 声明分片队列 - 检查存在性
|
||||
System.out.println("开始检查并声明 " + shardedQueues.size() + " 个分片队列...");
|
||||
log.info("开始检查并声明 {} 个分片队列...", shardedQueues.size());
|
||||
int successCount = 0;
|
||||
int skippedCount = 0;
|
||||
|
||||
@@ -159,45 +161,44 @@ public class RabbitMQConfig {
|
||||
skippedCount++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("队列声明失败: " + queueName + ", 错误: " + e.getMessage());
|
||||
log.error("队列声明失败: {}, 错误: {}", queueName, e.getMessage());
|
||||
}
|
||||
}
|
||||
System.out.println("分片队列处理完成: 成功 " + successCount + ", 跳过 " + skippedCount + ", 总数 " + shardedQueues.size());
|
||||
log.info("分片队列处理完成: 成功 {}, 跳过 {}, 总数 {}", successCount, skippedCount, shardedQueues.size());
|
||||
|
||||
// 声明分片绑定
|
||||
System.out.println("开始声明 " + shardedBindings.size() + " 个分片绑定...");
|
||||
log.info("开始声明 {} 个分片绑定...", shardedBindings.size());
|
||||
int bindingSuccessCount = 0;
|
||||
for (Binding binding : shardedBindings) {
|
||||
try {
|
||||
rabbitAdmin.declareBinding(binding);
|
||||
bindingSuccessCount++;
|
||||
} catch (Exception e) {
|
||||
System.err.println("绑定声明失败: " + e.getMessage());
|
||||
log.error("绑定声明失败: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
System.out.println("分片绑定声明完成: 成功 " + bindingSuccessCount + "/" + shardedBindings.size());
|
||||
log.info("分片绑定声明完成: 成功 {}/{}", bindingSuccessCount, shardedBindings.size());
|
||||
|
||||
// 声明遗留队列和绑定 - 检查存在性
|
||||
try {
|
||||
rabbitAdmin.declareQueue(legacyQueue);
|
||||
rabbitAdmin.declareBinding(legacyBinding);
|
||||
System.out.println("遗留队列和绑定就绪: " + QUEUE_NAME + " (已存在或新创建)");
|
||||
log.info("遗留队列和绑定就绪: {} (已存在或新创建)", QUEUE_NAME);
|
||||
} catch (org.springframework.amqp.AmqpIOException e) {
|
||||
if (e.getMessage().contains("PRECONDITION_FAILED") && e.getMessage().contains("durable")) {
|
||||
System.out.println("遗留队列已存在但 durable 设置不匹配: " + QUEUE_NAME + ", 保持现有队列");
|
||||
log.warn("遗留队列已存在但 durable 设置不匹配: {}, 保持现有队列", QUEUE_NAME);
|
||||
} else {
|
||||
System.err.println("遗留队列声明失败: " + QUEUE_NAME + ", 错误: " + e.getMessage());
|
||||
log.error("遗留队列声明失败: {}, 错误: {}", QUEUE_NAME, e.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("遗留队列声明失败: " + QUEUE_NAME + ", 错误: " + e.getMessage());
|
||||
log.error("遗留队列声明失败: {}, 错误: {}", QUEUE_NAME, e.getMessage());
|
||||
}
|
||||
|
||||
System.out.println("=== RabbitMQ 组件声明完成 ===");
|
||||
System.out.println("请检查 RabbitMQ 管理界面确认队列已正确创建");
|
||||
log.info("=== RabbitMQ 组件声明完成 ===");
|
||||
log.info("请检查 RabbitMQ 管理界面确认队列已正确创建");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("RabbitMQ 组件声明过程中发生严重错误:");
|
||||
e.printStackTrace();
|
||||
log.error("RabbitMQ 组件声明过程中发生严重错误", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.openisle.schdule;
|
||||
package com.openisle.scheduler;
|
||||
|
||||
import com.openisle.config.CachingConfig;
|
||||
import com.openisle.model.User;
|
||||
@@ -4,7 +4,9 @@ NUXT_PUBLIC_WEBSOCKET_URL=https://127.0.0.1:8082
|
||||
NUXT_PUBLIC_WEBSITE_BASE_URL=http://localhost:3000
|
||||
|
||||
NUXT_PUBLIC_GOOGLE_CLIENT_ID=777830451304-nt8afkkap18gui4f9entcha99unal744.apps.googleusercontent.com
|
||||
NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liVkO1NPAX5JyWxJ
|
||||
# NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liVkO1NPAX5JyWxJ
|
||||
; 本地
|
||||
NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liOlrZnPKRF7s7NN
|
||||
NUXT_PUBLIC_DISCORD_CLIENT_ID=1394985417044000779
|
||||
NUXT_PUBLIC_TWITTER_CLIENT_ID=ZTRTU05KSk9KTTJrTTdrVC1tc1E6MTpjaQ
|
||||
NUXT_PUBLIC_TELEGRAM_BOT_ID=8450237135
|
||||
|
||||
@@ -16,4 +16,4 @@ NUXT_PUBLIC_GOOGLE_CLIENT_ID=777830451304-nt8afkkap18gui4f9entcha99unal744.apps.
|
||||
NUXT_PUBLIC_GITHUB_CLIENT_ID=Ov23liVkO1NPAX5JyWxJ
|
||||
NUXT_PUBLIC_DISCORD_CLIENT_ID=1394985417044000779
|
||||
NUXT_PUBLIC_TWITTER_CLIENT_ID=ZTRTU05KSk9KTTJrTTdrVC1tc1E6MTpjaQ
|
||||
NUXT_PUBLIC_TELEGRAM_BOT_ID=8450237135
|
||||
NUXT_PUBLIC_TELEGRAM_BOT_ID=8450237135
|
||||
@@ -239,7 +239,7 @@ body {
|
||||
}
|
||||
|
||||
.info-content-text img {
|
||||
max-width: 400px;
|
||||
max-width: min(800px, 100%);
|
||||
max-height: 600px;
|
||||
height: auto;
|
||||
cursor: pointer;
|
||||
@@ -354,25 +354,41 @@ body {
|
||||
position: relative;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Adjust diff2html layout on mobile */
|
||||
@media (max-width: 768px) {
|
||||
.content-diff .d2h-wrapper,
|
||||
.content-diff .d2h-code-line,
|
||||
.content-diff .d2h-code-side-line,
|
||||
.content-diff .d2h-code-line-ctn,
|
||||
.content-diff .d2h-code-side-line-ctn,
|
||||
.content-diff .d2h-file-header {
|
||||
font-size: 12px;
|
||||
.d2h-file-name {
|
||||
font-size: 12px !important;
|
||||
}
|
||||
|
||||
.content-diff .d2h-wrapper {
|
||||
overflow-x: auto;
|
||||
.d2h-file-header {
|
||||
height: auto !important;
|
||||
}
|
||||
|
||||
.d2h-code-linenumber {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.d2h-code-line {
|
||||
padding-left: 10px !important;
|
||||
}
|
||||
|
||||
.d2h-diff-table {
|
||||
font-size: 6px !important;
|
||||
}
|
||||
|
||||
.d2h-code-line ins {
|
||||
height: 100%;
|
||||
font-size: 13px !important;
|
||||
}
|
||||
|
||||
/* .d2h-code-line {
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
.d2h-code-line-ctn {
|
||||
font-size: 12px !important;
|
||||
} */
|
||||
}
|
||||
|
||||
/* Transition API */
|
||||
::view-transition-old(root),
|
||||
::view-transition-new(root) {
|
||||
animation: none;
|
||||
|
||||
@@ -6,8 +6,15 @@
|
||||
</div>
|
||||
<div class="comment-bottom-container">
|
||||
<div class="comment-submit" :class="{ disabled: isDisabled }" @click="submit">
|
||||
<template v-if="!loading"> 发布评论 </template>
|
||||
<template v-else> <loading-four /> 发布中... </template>
|
||||
<template v-if="!loading">
|
||||
发布评论
|
||||
<span class="shortcut-icon" v-if="!isMobile">
|
||||
{{ isMac ? '⌘' : 'Ctrl' }} ⏎
|
||||
</span>
|
||||
</template>
|
||||
<template v-else>
|
||||
<loading-four /> 发布中...
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -24,6 +31,7 @@ import {
|
||||
} from '~/utils/vditor'
|
||||
import '~/assets/global.css'
|
||||
import LoginOverlay from '~/components/LoginOverlay.vue'
|
||||
import { useIsMobile } from '~/utils/screen'
|
||||
|
||||
export default {
|
||||
name: 'CommentEditor',
|
||||
@@ -52,12 +60,22 @@ export default {
|
||||
},
|
||||
components: { LoginOverlay },
|
||||
setup(props, { emit }) {
|
||||
const isMobile = useIsMobile()
|
||||
const vditorInstance = ref(null)
|
||||
const text = ref('')
|
||||
const editorId = ref(props.editorId)
|
||||
if (!editorId.value) {
|
||||
editorId.value = 'editor-' + useId()
|
||||
}
|
||||
|
||||
const isMac = ref(false)
|
||||
|
||||
if (navigator.userAgentData) {
|
||||
isMac.value = navigator.userAgentData.platform === 'macOS'
|
||||
} else {
|
||||
isMac.value = /Mac|iPhone|iPad|iPod/.test(navigator.userAgent)
|
||||
}
|
||||
|
||||
const getEditorTheme = getEditorThemeUtil
|
||||
const getPreviewTheme = getPreviewThemeUtil
|
||||
const applyTheme = () => {
|
||||
@@ -96,7 +114,27 @@ export default {
|
||||
applyTheme()
|
||||
},
|
||||
})
|
||||
// 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(() => {
|
||||
@@ -134,7 +172,7 @@ export default {
|
||||
},
|
||||
)
|
||||
|
||||
return { submit, isDisabled, editorId }
|
||||
return { submit, isDisabled, editorId, isMac, isMobile}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -174,10 +212,16 @@ export default {
|
||||
.comment-submit:hover {
|
||||
background-color: var(--primary-color-hover);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.comment-editor-container {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
/** 评论按钮快捷键样式 */
|
||||
.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>
|
||||
|
||||
@@ -314,6 +314,7 @@ const gotoTag = (t) => {
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
transition: background-color 0.5s ease;
|
||||
}
|
||||
|
||||
.menu-item:hover {
|
||||
@@ -408,6 +409,7 @@ const gotoTag = (t) => {
|
||||
gap: 5px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.5s ease;
|
||||
}
|
||||
|
||||
.section-item:hover {
|
||||
|
||||
@@ -110,11 +110,13 @@ const diffHtml = computed(() => {
|
||||
border-bottom: 1px solid var(--normal-border-color);
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.change-log-text {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.change-log-user {
|
||||
font-weight: bold;
|
||||
margin-right: 4px;
|
||||
@@ -132,6 +134,7 @@ const diffHtml = computed(() => {
|
||||
margin-right: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.change-log-time {
|
||||
font-size: 12px;
|
||||
opacity: 0.6;
|
||||
|
||||
97
frontend_nuxt/config/uploadConfig.js
Normal file
97
frontend_nuxt/config/uploadConfig.js
Normal file
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* 文件上传配置 - 简化版
|
||||
* 专注于 WebCodecs + MP4Box.js 视频压缩,支持 Chrome/Safari
|
||||
*/
|
||||
|
||||
// 声明全局变量以避免 TypeScript 错误
|
||||
/* global useRuntimeConfig */
|
||||
|
||||
export const UPLOAD_CONFIG = {
|
||||
VIDEO: {
|
||||
MAX_SIZE: 20 * 1024 * 1024, // 20mb
|
||||
TARGET_SIZE: 5 * 1024 * 1024, // 5mb
|
||||
|
||||
// 支持的输入格式
|
||||
SUPPORTED_FORMATS: ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'm4v', 'ogv'],
|
||||
|
||||
// 输出格式 - MP4 (兼容性最好)
|
||||
OUTPUT_FORMAT: 'mp4',
|
||||
OUTPUT_CODEC: 'h264',
|
||||
},
|
||||
|
||||
// 图片文件配置
|
||||
IMAGE: {
|
||||
MAX_SIZE: 5 * 1024 * 1024, // 5MB
|
||||
TARGET_SIZE: 5 * 1024 * 1024, // 5MB
|
||||
SUPPORTED_FORMATS: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp'],
|
||||
},
|
||||
|
||||
// 音频文件配置
|
||||
AUDIO: {
|
||||
MAX_SIZE: 5 * 1024 * 1024, // 5MB
|
||||
TARGET_SIZE: 5 * 1024 * 1024, // 5MB
|
||||
SUPPORTED_FORMATS: ['mp3', 'wav', 'ogg', 'aac', 'm4a'],
|
||||
},
|
||||
|
||||
// 通用文件配置
|
||||
GENERAL: {
|
||||
MAX_SIZE: 100 * 1024 * 1024, // 100MB
|
||||
CHUNK_SIZE: 5 * 1024 * 1024, // 5MB 分片大小
|
||||
},
|
||||
|
||||
// 用户体验配置
|
||||
UI: {
|
||||
SUCCESS_DURATION: 2000,
|
||||
ERROR_DURATION: 3000,
|
||||
WARNING_DURATION: 3000,
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件类型配置
|
||||
*/
|
||||
export function getFileTypeConfig(filename) {
|
||||
const ext = filename.split('.').pop().toLowerCase()
|
||||
|
||||
if (UPLOAD_CONFIG.VIDEO.SUPPORTED_FORMATS.includes(ext)) {
|
||||
return { type: 'video', config: UPLOAD_CONFIG.VIDEO }
|
||||
}
|
||||
|
||||
if (UPLOAD_CONFIG.IMAGE.SUPPORTED_FORMATS.includes(ext)) {
|
||||
return { type: 'image', config: UPLOAD_CONFIG.IMAGE }
|
||||
}
|
||||
|
||||
if (UPLOAD_CONFIG.AUDIO.SUPPORTED_FORMATS.includes(ext)) {
|
||||
return { type: 'audio', config: UPLOAD_CONFIG.AUDIO }
|
||||
}
|
||||
|
||||
return { type: 'general', config: UPLOAD_CONFIG.GENERAL }
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化文件大小
|
||||
*/
|
||||
export function formatFileSize(bytes) {
|
||||
if (bytes === 0) return '0 B'
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'MB', 'GB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算压缩节省的费用 (示例函数)
|
||||
*/
|
||||
export function calculateSavings(originalSize, compressedSize, costPerMB = 0.01) {
|
||||
const originalMB = originalSize / (1024 * 1024)
|
||||
const compressedMB = compressedSize / (1024 * 1024)
|
||||
const savedMB = originalMB - compressedMB
|
||||
const savedCost = savedMB * costPerMB
|
||||
|
||||
return {
|
||||
savedMB: savedMB.toFixed(2),
|
||||
savedCost: savedCost.toFixed(4),
|
||||
originalCost: (originalMB * costPerMB).toFixed(4),
|
||||
compressedCost: (compressedMB * costPerMB).toFixed(4),
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
import { defineNuxtConfig } from 'nuxt/config'
|
||||
|
||||
export default defineNuxtConfig({
|
||||
devServer: {
|
||||
host: '0.0.0.0',
|
||||
port: 3000
|
||||
port: 3000,
|
||||
},
|
||||
ssr: true,
|
||||
modules: ['@nuxt/image'],
|
||||
|
||||
31
frontend_nuxt/package-lock.json
generated
31
frontend_nuxt/package-lock.json
generated
@@ -19,6 +19,8 @@
|
||||
"ldrs": "^1.0.0",
|
||||
"markdown-it": "^14.1.0",
|
||||
"mermaid": "^10.9.4",
|
||||
"mp4box": "^2.1.1",
|
||||
"nanoid": "^5.1.5",
|
||||
"nprogress": "^0.2.0",
|
||||
"nuxt": "latest",
|
||||
"sanitize-html": "^2.17.0",
|
||||
@@ -998,7 +1000,7 @@
|
||||
},
|
||||
"node_modules/@icon-park/vue-next": {
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@icon-park/vue-next/-/vue-next-1.4.2.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/@icon-park/vue-next/-/vue-next-1.4.2.tgz",
|
||||
"integrity": "sha512-+QklF255wkfBOabY+xw6FAI0Bwln/RhdwCunNy/9sKdKuChtaU67QZqU67KGAvZUTeeBgsL+yaHHxqfQeGZXEQ==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
@@ -7222,7 +7224,7 @@
|
||||
},
|
||||
"node_modules/diff2html": {
|
||||
"version": "3.4.52",
|
||||
"resolved": "https://registry.npmjs.org/diff2html/-/diff2html-3.4.52.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/diff2html/-/diff2html-3.4.52.tgz",
|
||||
"integrity": "sha512-qhMg8/I3sZ4zm/6R/Kh0xd6qG6Vm86w6M+C9W+DuH1V8ACz+1cgEC8/k0ucjv6AGqZWzHm/8G1gh7IlrUqCMhg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -7238,7 +7240,7 @@
|
||||
},
|
||||
"node_modules/diff2html/node_modules/diff": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/diff/-/diff-7.0.0.tgz",
|
||||
"integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==",
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
@@ -7247,7 +7249,7 @@
|
||||
},
|
||||
"node_modules/diff2html/node_modules/highlight.js": {
|
||||
"version": "11.9.0",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.9.0.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/highlight.js/-/highlight.js-11.9.0.tgz",
|
||||
"integrity": "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw==",
|
||||
"license": "BSD-3-Clause",
|
||||
"optional": true,
|
||||
@@ -8330,7 +8332,7 @@
|
||||
},
|
||||
"node_modules/hogan.js": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/hogan.js/-/hogan.js-3.0.2.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/hogan.js/-/hogan.js-3.0.2.tgz",
|
||||
"integrity": "sha512-RqGs4wavGYJWE07t35JQccByczmNUXQT0E12ZYV1VKYu5UiAU9lsos/yBAcf840+zrUQQxgVduCR5/B8nNtibg==",
|
||||
"dependencies": {
|
||||
"mkdirp": "0.3.0",
|
||||
@@ -8342,13 +8344,13 @@
|
||||
},
|
||||
"node_modules/hogan.js/node_modules/abbrev": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/abbrev/-/abbrev-1.1.1.tgz",
|
||||
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/hogan.js/node_modules/mkdirp": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/mkdirp/-/mkdirp-0.3.0.tgz",
|
||||
"integrity": "sha512-OHsdUcVAQ6pOtg5JYWpCBo9W/GySVuwvP9hueRMW7UqshC0tbfzLv8wjySTPm3tfUZ/21CE9E1pJagOA91Pxew==",
|
||||
"deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)",
|
||||
"license": "MIT/X11",
|
||||
@@ -8358,7 +8360,7 @@
|
||||
},
|
||||
"node_modules/hogan.js/node_modules/nopt": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/nopt/-/nopt-1.0.10.tgz",
|
||||
"integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -8614,7 +8616,7 @@
|
||||
},
|
||||
"node_modules/ipx": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ipx/-/ipx-3.1.1.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/ipx/-/ipx-3.1.1.tgz",
|
||||
"integrity": "sha512-7Xnt54Dco7uYkfdAw0r2vCly3z0rSaVhEXMzPvl3FndsTVm5p26j+PO+gyinkYmcsEUvX2Rh7OGK7KzYWRu6BA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -10139,6 +10141,15 @@
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/mp4box": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/mp4box/-/mp4box-2.1.1.tgz",
|
||||
"integrity": "sha512-gttYFNmlCjredsdnxqNC6ho0bx6zEwOqAwSKZNQXtsBqvSN1CjtzlTLY9Kfhvt14Co8Iu+qMuOOpnPIRjvvFtw==",
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
"node": ">=20.8.1"
|
||||
}
|
||||
},
|
||||
"node_modules/mri": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||
@@ -10171,7 +10182,7 @@
|
||||
},
|
||||
"node_modules/nanoid": {
|
||||
"version": "5.1.5",
|
||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.1.5.tgz",
|
||||
"resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-5.1.5.tgz",
|
||||
"integrity": "sha512-Ir/+ZpE9fDsNH0hQ3C68uyThDXzYcim2EqcZ8zn8Chtt1iylPT9xXJB0kPCnqzgcEGikO9RxSrh63MsmVCU7Fw==",
|
||||
"funding": [
|
||||
{
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
"ldrs": "^1.0.0",
|
||||
"markdown-it": "^14.1.0",
|
||||
"mermaid": "^10.9.4",
|
||||
"mp4box": "^2.1.1",
|
||||
"nanoid": "^5.1.5",
|
||||
"nprogress": "^0.2.0",
|
||||
"nuxt": "latest",
|
||||
"sanitize-html": "^2.17.0",
|
||||
|
||||
@@ -424,7 +424,8 @@ const sanitizeDescription = (text) => stripMarkdown(text)
|
||||
|
||||
.topic-container {
|
||||
position: sticky;
|
||||
top: calc(var(--header-height) + 1px);
|
||||
top: var(--header-height);
|
||||
padding-top: 10px;
|
||||
z-index: 10;
|
||||
background-color: var(--background-color-blur);
|
||||
display: flex;
|
||||
@@ -432,12 +433,10 @@ const sanitizeDescription = (text) => stripMarkdown(text)
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
padding: 10px 0;
|
||||
backdrop-filter: var(--blur-10);
|
||||
}
|
||||
|
||||
.topic-item-container {
|
||||
margin-left: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
@@ -478,6 +477,7 @@ const sanitizeDescription = (text) => stripMarkdown(text)
|
||||
width: 100%;
|
||||
color: gray;
|
||||
border-bottom: 1px solid var(--normal-border-color);
|
||||
padding-top: 30px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
@@ -487,6 +487,7 @@ const sanitizeDescription = (text) => stripMarkdown(text)
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
border-bottom: 1px solid var(--normal-border-color);
|
||||
transition: background-color 0.5s ease;
|
||||
}
|
||||
|
||||
.article-item:hover {
|
||||
|
||||
@@ -3,6 +3,8 @@ import { getToken, authState } from './auth'
|
||||
import { searchUsers, fetchFollowings, fetchAdmins } from './user'
|
||||
import { tiebaEmoji } from './tiebaEmoji'
|
||||
import vditorPostCitation from './vditorPostCitation.js'
|
||||
import { checkFileSize, formatFileSize, compressVideo, VIDEO_CONFIG } from './videoCompressor.js'
|
||||
import { UPLOAD_CONFIG } from '../config/uploadConfig.js'
|
||||
|
||||
export function getEditorTheme() {
|
||||
return document.documentElement.dataset.theme === 'dark' ? 'dark' : 'classic'
|
||||
@@ -91,10 +93,81 @@ export function createVditor(editorId, options = {}) {
|
||||
multiple: false,
|
||||
handler: async (files) => {
|
||||
const file = files[0]
|
||||
vditor.tip('图片上传中', 0)
|
||||
const ext = file.name.split('.').pop().toLowerCase()
|
||||
const videoExts = ['mp4', 'webm', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'm4v', 'ogv']
|
||||
const isVideo = videoExts.includes(ext)
|
||||
|
||||
// 检查文件大小
|
||||
const sizeCheck = checkFileSize(file)
|
||||
if (!sizeCheck.isValid) {
|
||||
console.log(
|
||||
'文件大小不能超过',
|
||||
formatFileSize(sizeCheck.maxSize),
|
||||
',当前文件',
|
||||
formatFileSize(sizeCheck.actualSize),
|
||||
)
|
||||
vditor.tip(
|
||||
`文件大小不能超过 ${formatFileSize(sizeCheck.maxSize)},当前文件 ${formatFileSize(sizeCheck.actualSize)}`,
|
||||
3000,
|
||||
)
|
||||
return '文件过大'
|
||||
}
|
||||
|
||||
let processedFile = file
|
||||
|
||||
// 如果是视频文件且需要压缩
|
||||
if (isVideo && sizeCheck.needsCompression) {
|
||||
try {
|
||||
vditor.tip('视频压缩中...', 0)
|
||||
vditor.disabled()
|
||||
|
||||
// 使用 WebCodecs 压缩视频
|
||||
processedFile = await compressVideo(file, (progress) => {
|
||||
const messages = {
|
||||
initializing: '初始化编码器',
|
||||
preparing: '准备压缩',
|
||||
analyzing: '分析视频',
|
||||
compressing: '压缩中',
|
||||
finalizing: '完成压缩',
|
||||
completed: '压缩完成',
|
||||
}
|
||||
const message = messages[progress.stage] || progress.stage
|
||||
vditor.tip(`${message} ${progress.progress}%`, 0)
|
||||
})
|
||||
|
||||
const originalSize = formatFileSize(file.size)
|
||||
const compressedSize = formatFileSize(processedFile.size)
|
||||
const savings = Math.round((1 - processedFile.size / file.size) * 100)
|
||||
|
||||
vditor.tip(`压缩完成!${originalSize} → ${compressedSize} (节省 ${savings}%)`, 2000)
|
||||
// 压缩成功但仍然超过最大限制,则阻止上传
|
||||
if (processedFile.size > VIDEO_CONFIG.MAX_SIZE) {
|
||||
vditor.tip(
|
||||
`压缩后仍超过限制 (${formatFileSize(VIDEO_CONFIG.MAX_SIZE)}). 请降低分辨率或码率后再上传。`,
|
||||
4000,
|
||||
)
|
||||
vditor.enable()
|
||||
return '压缩后仍超过大小限制'
|
||||
}
|
||||
} catch (error) {
|
||||
// 压缩失败时,如果原文件超过最大限制,则阻止上传
|
||||
if (file.size > VIDEO_CONFIG.MAX_SIZE) {
|
||||
vditor.tip(
|
||||
`视频压缩失败,且文件超过限制 (${formatFileSize(VIDEO_CONFIG.MAX_SIZE)}). 请先压缩后再上传。`,
|
||||
4000,
|
||||
)
|
||||
vditor.enable()
|
||||
return '视频压缩失败且文件过大'
|
||||
}
|
||||
vditor.tip('视频压缩失败,将尝试上传原文件', 3000)
|
||||
processedFile = file
|
||||
}
|
||||
}
|
||||
|
||||
vditor.tip('文件上传中', 0)
|
||||
vditor.disabled()
|
||||
const res = await fetch(
|
||||
`${API_BASE_URL}/api/upload/presign?filename=${encodeURIComponent(file.name)}`,
|
||||
`${API_BASE_URL}/api/upload/presign?filename=${encodeURIComponent(processedFile.name)}`,
|
||||
{ headers: { Authorization: `Bearer ${getToken()}` } },
|
||||
)
|
||||
if (!res.ok) {
|
||||
@@ -103,14 +176,13 @@ export function createVditor(editorId, options = {}) {
|
||||
return '获取上传地址失败'
|
||||
}
|
||||
const info = await res.json()
|
||||
const put = await fetch(info.uploadUrl, { method: 'PUT', body: file })
|
||||
const put = await fetch(info.uploadUrl, { method: 'PUT', body: processedFile })
|
||||
if (!put.ok) {
|
||||
vditor.enable()
|
||||
vditor.tip('上传失败')
|
||||
return '上传失败'
|
||||
}
|
||||
|
||||
const ext = file.name.split('.').pop().toLowerCase()
|
||||
const imageExts = [
|
||||
'apng',
|
||||
'bmp',
|
||||
@@ -132,6 +204,8 @@ export function createVditor(editorId, options = {}) {
|
||||
md = ``
|
||||
} else if (audioExts.includes(ext)) {
|
||||
md = `<audio controls="controls" src="${info.fileUrl}"></audio>`
|
||||
} else if (videoExts.includes(ext)) {
|
||||
md = `<video width="600" controls>\n <source src="${info.fileUrl}" type="video/${ext}">\n 你的浏览器不支持 video 标签。\n</video>`
|
||||
} else {
|
||||
md = `[${file.name}](${info.fileUrl})`
|
||||
}
|
||||
|
||||
72
frontend_nuxt/utils/videoCompressor.js
Normal file
72
frontend_nuxt/utils/videoCompressor.js
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* 基于 WebCodecs + MP4Box.js 的视频压缩工具
|
||||
* 专为现代浏览器 (Chrome/Safari) 优化
|
||||
*/
|
||||
|
||||
import { UPLOAD_CONFIG } from '../config/uploadConfig.js'
|
||||
import { compressVideoWithWebCodecs, isWebCodecSupported } from './webcodecVideoCompressor.js'
|
||||
|
||||
// 导出配置供外部使用
|
||||
export const VIDEO_CONFIG = UPLOAD_CONFIG.VIDEO
|
||||
|
||||
/**
|
||||
* 检查文件大小是否超出限制
|
||||
*/
|
||||
export function checkFileSize(file) {
|
||||
return {
|
||||
isValid: file.size <= VIDEO_CONFIG.MAX_SIZE,
|
||||
actualSize: file.size,
|
||||
maxSize: VIDEO_CONFIG.MAX_SIZE,
|
||||
needsCompression: file.size > VIDEO_CONFIG.TARGET_SIZE,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化文件大小显示
|
||||
*/
|
||||
export function formatFileSize(bytes) {
|
||||
if (bytes === 0) return '0 B'
|
||||
const k = 1024
|
||||
const sizes = ['B', 'KB', 'MB', 'GB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]
|
||||
}
|
||||
|
||||
/**
|
||||
* 压缩视频文件 - 使用 WebCodecs
|
||||
*/
|
||||
export async function compressVideo(file, onProgress = () => {}) {
|
||||
// 检查是否需要压缩
|
||||
const sizeCheck = checkFileSize(file)
|
||||
if (!sizeCheck.needsCompression) {
|
||||
onProgress({ stage: 'completed', progress: 100 })
|
||||
return file
|
||||
}
|
||||
|
||||
// 检查 WebCodecs 支持
|
||||
if (!isWebCodecSupported()) {
|
||||
throw new Error('当前浏览器不支持视频压缩功能,请使用支持 WebCodecs 的浏览器')
|
||||
}
|
||||
|
||||
try {
|
||||
return await compressVideoWithWebCodecs(file, { onProgress })
|
||||
} catch (error) {
|
||||
console.error('WebCodecs 压缩失败:', error)
|
||||
throw new Error(`视频压缩失败: ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预加载 WebCodecs(可选的性能优化)
|
||||
*/
|
||||
export async function preloadVideoCompressor() {
|
||||
try {
|
||||
if (!isWebCodecSupported()) {
|
||||
throw new Error('当前浏览器不支持 WebCodecs')
|
||||
}
|
||||
return { success: true, message: 'WebCodecs 已就绪' }
|
||||
} catch (error) {
|
||||
console.warn('WebCodecs 检测失败:', error)
|
||||
return { success: false, error: error.message }
|
||||
}
|
||||
}
|
||||
98
frontend_nuxt/utils/webcodecVideoCompressor.js
Normal file
98
frontend_nuxt/utils/webcodecVideoCompressor.js
Normal file
@@ -0,0 +1,98 @@
|
||||
import MP4Box from 'mp4box'
|
||||
|
||||
// 检查 WebCodecs 支持
|
||||
export function isWebCodecSupported() {
|
||||
return typeof window !== 'undefined' && typeof window.VideoEncoder !== 'undefined'
|
||||
}
|
||||
|
||||
// 使用 WebCodecs + MP4Box.js 压缩视频
|
||||
export async function compressVideoWithWebCodecs(file, opts = {}) {
|
||||
const { onProgress = () => {}, width = 720, bitrate = 1_000_000 } = opts
|
||||
|
||||
if (!isWebCodecSupported()) {
|
||||
throw new Error('当前浏览器不支持 WebCodecs')
|
||||
}
|
||||
|
||||
onProgress({ stage: 'initializing', progress: 0 })
|
||||
|
||||
// 加载原始视频
|
||||
const url = URL.createObjectURL(file)
|
||||
const video = document.createElement('video')
|
||||
video.src = url
|
||||
video.muted = true
|
||||
await video.play().catch(() => {})
|
||||
video.pause()
|
||||
await new Promise((resolve) => {
|
||||
if (video.readyState >= 2) resolve()
|
||||
else video.onloadedmetadata = () => resolve()
|
||||
})
|
||||
|
||||
const targetWidth = width
|
||||
const targetHeight = Math.round((video.videoHeight / video.videoWidth) * width)
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = targetWidth
|
||||
canvas.height = targetHeight
|
||||
const ctx = canvas.getContext('2d')
|
||||
|
||||
const chunks = []
|
||||
const encoder = new VideoEncoder({
|
||||
output: (chunk) => {
|
||||
chunks.push(chunk)
|
||||
},
|
||||
error: (e) => {
|
||||
throw e
|
||||
},
|
||||
})
|
||||
encoder.configure({
|
||||
codec: 'avc1.42001E',
|
||||
width: targetWidth,
|
||||
height: targetHeight,
|
||||
bitrate,
|
||||
framerate: 30,
|
||||
})
|
||||
|
||||
const duration = video.duration
|
||||
const frameCount = Math.floor(duration * 30)
|
||||
for (let i = 0; i < frameCount; i++) {
|
||||
video.currentTime = i / 30
|
||||
await new Promise((res) => (video.onseeked = res))
|
||||
ctx.drawImage(video, 0, 0, targetWidth, targetHeight)
|
||||
const bitmap = await createImageBitmap(canvas)
|
||||
const frame = new VideoFrame(bitmap, { timestamp: (i / 30) * 1000000 })
|
||||
encoder.encode(frame)
|
||||
frame.close()
|
||||
bitmap.close()
|
||||
onProgress({ stage: 'compressing', progress: Math.round(((i + 1) / frameCount) * 80) })
|
||||
}
|
||||
|
||||
await encoder.flush()
|
||||
onProgress({ stage: 'finalizing', progress: 90 })
|
||||
|
||||
const mp4box = MP4Box.createFile()
|
||||
const track = mp4box.addTrack({
|
||||
timescale: 1000,
|
||||
width: targetWidth,
|
||||
height: targetHeight,
|
||||
})
|
||||
|
||||
let dts = 0
|
||||
chunks.forEach((chunk) => {
|
||||
const data = new Uint8Array(chunk.byteLength)
|
||||
chunk.copyTo(data)
|
||||
mp4box.addSample(track, data.buffer, {
|
||||
duration: chunk.duration ? chunk.duration / 1000 : 33,
|
||||
dts,
|
||||
cts: dts,
|
||||
is_sync: chunk.type === 'key',
|
||||
})
|
||||
dts += chunk.duration ? chunk.duration / 1000 : 33
|
||||
})
|
||||
|
||||
const arrayBuffer = mp4box.flush()
|
||||
const outputFile = new File([arrayBuffer], file.name.replace(/\.[^.]+$/, '.mp4'), {
|
||||
type: 'video/mp4',
|
||||
})
|
||||
onProgress({ stage: 'completed', progress: 100 })
|
||||
URL.revokeObjectURL(url)
|
||||
return outputFile
|
||||
}
|
||||
Reference in New Issue
Block a user