From 7c6ac5d13bea994da2a3f516391e8aa8573f0740 Mon Sep 17 00:00:00 2001 From: "qwen.ai[bot]" Date: Fri, 27 Mar 2026 12:39:56 +0000 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=8C=96=E5=B9=B6=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=96=87=E4=BB=B6=E5=8F=8A=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=AD=98=E5=82=A8=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Key features implemented: - 新增 REFACTORING.md 文档详细说明代码重构方案和模块划分 - 创建 app_legacy.js 保留原始864行单体代码作为备份 - 实现 src/config/index.js 配置管理模块,支持同目录配置文件加载保存 - 实现 src/database/index.js 数据库服务模块,采用单例模式封装SQLite操作 - 实现 src/middleware/auth.js 认证中间件模块 - 实现 src/routes/clipboard.js 剪贴板路由模块,分离首页和创建路由 - 实现 src/routes/files.js 文件路由模块,包含文件信息预览和下载功能 - 实现 src/routes/admin.js 管理路由模块,集成Vditor上传和同步功能 - 实现 src/utils/helpers.js 工具函数模块,提供日期格式化和MIME类型判断 - 更新 app.js 主应用入口,整合各模块并调整默认存储路径为同目录 - 修改 .gitignore 文件以适配新目录结构和文件类型 整体重构将单体应用拆分为职责单一的模块,提高代码可维护性,并统一配置和数据库文件至应用根目录。 --- .gitignore | 79 +- REFACTORING.md | 99 ++ app.js | 798 +--------------- app_legacy.js | 864 ++++++++++++++++++ package-lock.json | 1931 +++++++++++++++++++++++++++++++++++++++ src/config/index.js | 77 ++ src/database/index.js | 129 +++ src/middleware/auth.js | 21 + src/routes/admin.js | 294 ++++++ src/routes/clipboard.js | 136 +++ src/routes/files.js | 160 ++++ src/utils/helpers.js | 93 ++ 12 files changed, 3890 insertions(+), 791 deletions(-) create mode 100644 REFACTORING.md create mode 100644 app_legacy.js create mode 100644 package-lock.json create mode 100644 src/config/index.js create mode 100644 src/database/index.js create mode 100644 src/middleware/auth.js create mode 100644 src/routes/admin.js create mode 100644 src/routes/clipboard.js create mode 100644 src/routes/files.js create mode 100644 src/utils/helpers.js diff --git a/.gitignore b/.gitignore index 80d14a9..952cf6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,46 +1,55 @@ -# 依赖目录 +``` +# Dependencies node_modules/ -package-lock.json -# 上传目录 -uploads/ -vditoruploads/ +# Database +clipboard.db -# 数据库文件 -*.db -*.sqlite -*.sqlite3 - -# 日志文件 -logs/ +# Logs and temp files *.log +*.tmp -# 环境变量文件 +# Environment .env .env.local -.env.development.local -.env.test.local -.env.production.local +*.env.* -# 编辑器和IDE配置 +# Editors .vscode/ .idea/ -*.swp -*.swo -*~ - -# 操作系统生成的文件 -.DS_Store -.DS_Store? -._* -.Spotlight-V100 -.Trashes -ehthumbs.db -Thumbs.db - -# 临时文件 -*.tmp -*.temp -# 配置文件(可选,如果不想提交配置可以取消下面这行的注释) -# config.json \ No newline at end of file +# Python +__pycache__/ +*.pyc +*.pyo +*.pyd + +# Build outputs +dist/ +build/ +target/ + +# Compression files +*.zip +*.gz +*.tar +*.tgz +*.bz2 +*.xz +*.7z +*.rar +*.zst +*.lz4 +*.lzh +*.cab +*.arj +*.rpm +*.deb +*.Z +*.lz +*.lzo +*.tar.gz +*.tar.bz2 +*.tar.xz +*.tar.zst +``` \ No newline at end of file diff --git a/REFACTORING.md b/REFACTORING.md new file mode 100644 index 0000000..872171f --- /dev/null +++ b/REFACTORING.md @@ -0,0 +1,99 @@ +# 代码重构说明 + +## 概述 + +本次重构将原本集中在 `app.js`(864 行)中的代码模块化,提高了代码的可维护性、可读性和可测试性。 + +## 目录结构 + +``` +/workspace +├── app.js # 主应用入口(重构后) +├── app_legacy.js # 原始应用代码(备份) +├── src/ +│ ├── config/ # 配置管理 +│ │ └── index.js # 配置加载、保存和路径解析 +│ ├── database/ # 数据库服务 +│ │ └── index.js # SQLite 数据库操作封装 +│ ├── middleware/ # 中间件 +│ │ └── auth.js # 认证中间件 +│ ├── routes/ # 路由处理 +│ │ ├── clipboard.js # 剪贴板相关路由 +│ │ ├── files.js # 文件相关路由 +│ │ └── admin.js # 管理和 Vditor 上传路由 +│ ├── services/ # 业务服务(预留) +│ └── utils/ # 工具函数 +│ └── helpers.js # 日期格式化、文件类型判断等 +├── public/ # 静态资源 +├── views/ # EJS 模板 +└── config.json # 应用配置 +``` + +## 模块说明 + +### 1. 配置管理 (`src/config/index.js`) +- `loadConfig()`: 加载配置文件 +- `saveConfig(config)`: 保存配置文件 +- `resolvePath(dirPath)`: 解析路径(支持相对和绝对路径) +- `ensureDirectoryExists(dirPath)`: 确保目录存在 + +### 2. 数据库服务 (`src/database/index.js`) +采用单例模式,提供以下方法: +- `connect()`: 初始化数据库连接 +- `getAllItems()`: 获取所有剪贴板项目 +- `getItemById(id)`: 根据 ID 获取项目 +- `createItem(type, title, content, filePath, createdAt)`: 创建项目 +- `updateItem(id, title, content)`: 更新项目 +- `deleteItem(id)`: 删除项目 +- `getAllFileItems()`: 获取所有文件项目 +- `getAllFilePaths()`: 获取所有文件路径 + +### 3. 认证中间件 (`src/middleware/auth.js`) +- `createAuthMiddleware()`: 创建认证中间件工厂函数 + +### 4. 路由模块 + +#### 剪贴板路由 (`src/routes/clipboard.js`) +- `setupIndexRoute(app)`: 首页路由 +- `setupCreateRoutes(router, upload)`: 创建项目路由(markdown/text/link/file) +- `setupItemRoutes(router)`: 获取项目和分享页面路由 + +#### 文件路由 (`src/routes/files.js`) +- `router.get('/file-info/:id')`: 获取文件信息 +- `router.get('/text-preview/:id')`: 文本文件预览 +- `setupFileDownloadRoute(app)`: 文件下载(支持断点续传) + +#### 管理路由 (`src/routes/admin.js`) +- `createVditorUpload()`: 创建 Vditor 上传中间件 +- `setupVditorRoutes(vditorUpload)`: Vditor 图片/音频上传 +- `setupAdminRoutes()`: 管理页面、密码更新、目录更新、文件同步 + +### 5. 工具函数 (`src/utils/helpers.js`) +- `formatDateTime(date)`: 日期格式化(UTC+8) +- `getFileType(filePath)`: 获取文件 MIME 类型 + +## 主要改进 + +1. **模块化**: 将 864 行的单体文件拆分为多个职责单一的模块 +2. **可测试性**: 每个模块可以独立测试 +3. **可维护性**: 代码结构清晰,易于定位和修改 +4. **复用性**: 通用功能(如配置管理、数据库操作)可被多处复用 +5. **类型安全**: 添加了 JSDoc 注释,提供更好的 IDE 支持 + +## 运行方式 + +```bash +# 开发模式 +npm run dev + +# 生产模式 +npm start +``` + +## 兼容性 + +重构后的代码完全保持原有功能,包括: +- 所有 API 端点保持不变 +- 配置文件格式保持不变 +- 数据库结构保持不变 +- 前端页面无需修改 diff --git a/app.js b/app.js index a5fc314..f0f3999 100644 --- a/app.js +++ b/app.js @@ -1,98 +1,32 @@ const express = require('express'); -const bodyParser = require('body-parser'); const path = require('path'); +const bodyParser = require('body-parser'); +const session = require('express-session'); const multer = require('multer'); const fs = require('fs'); -const Database = require('better-sqlite3'); -const session = require('express-session'); - -/** - * 将 UTC 日期格式化为 UTC+8 的 YYYY/MM/DD hh:mm:ss 格式 - * @param {Date|string} date - 日期对象或日期字符串(应为 UTC 时间) - * @returns {string} 格式化后的 UTC+8 日期字符串 - */ -function formatDateTime(date) { - if (!date) return ''; - - const d = new Date(date); - if (isNaN(d.getTime())) return ''; - // 将时间转为 UTC 时间戳,再加 8 小时(28800000 毫秒) - const utcTime = d.getTime(); - const utcPlus8Time = utcTime + 8 * 60 * 60 * 1000; - const d8 = new Date(utcPlus8Time); - - const year = d8.getFullYear(); - const month = String(d8.getMonth() + 1).padStart(2, '0'); - const day = String(d8.getDate()).padStart(2, '0'); - const hours = String(d8.getHours()).padStart(2, '0'); - const minutes = String(d8.getMinutes()).padStart(2, '0'); - const seconds = String(d8.getSeconds()).padStart(2, '0'); - - return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`; -} - -// 读取配置文件 -let config; -try { - const configPath = path.join('/mnt/data', 'config.json'); - if (fs.existsSync(configPath)) { - config = JSON.parse(fs.readFileSync(configPath, 'utf8')); - } else { - // 默认配置 - config = { - auth: { password: 'PasePad' }, - upload: { - uploadDir: '/mnt/data/uploads', - vditoruploadsDir: '/mnt/data/vditoruploads' - }, - fileSync: { - dbMissingFile: 'keep', - fileMissingDb: 'keep' - } - }; - // 创建默认配置文件 - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - } -} catch (err) { - console.error('读取配置文件失败:', err); - // 默认配置 - config = { - auth: { password: 'Abc@123' }, - upload: { - uploadDir: './uploads', - vditoruploadsDir: './vditoruploads' - }, - fileSync: { - dbMissingFile: 'keep', - fileMissingDb: 'keep' - } - }; -} +const configService = require('./src/config'); +const db = require('./src/database'); +const { createAuthMiddleware } = require('./src/middleware/auth'); +const { formatDateTime } = require('./src/utils/helpers'); +const { setupIndexRoute, setupCreateRoutes, setupItemRoutes } = require('./src/routes/clipboard'); +const fileRoutes = require('./src/routes/files'); +const { createVditorUpload, setupVditorRoutes, setupAdminRoutes } = require('./src/routes/admin'); // 初始化应用 const app = express(); const port = process.env.PORT || 3000; -// 解析上传目录路径(支持相对路径和绝对路径) -function resolvePath(dirPath) { - if (path.isAbsolute(dirPath)) { - return dirPath; - } - return path.join(__dirname, dirPath.replace(/^\.\//, '')); -} +// 加载配置 +const config = configService.loadConfig(); // 确保上传目录存在 -const uploadDir = resolvePath(config.upload.uploadDir); -if (!fs.existsSync(uploadDir)) { - fs.mkdirSync(uploadDir, { recursive: true }); -} +const uploadDir = configService.resolvePath(config.upload.uploadDir); +configService.ensureDirectoryExists(config.upload.uploadDir); -// 确保vditor上传目录存在 -const vditoruploadsDir = resolvePath(config.upload.vditoruploadsDir); -if (!fs.existsSync(vditoruploadsDir)) { - fs.mkdirSync(vditoruploadsDir, { recursive: true }); -} +// 确保 vditor 上传目录存在 +const vditoruploadsDir = configService.resolvePath(config.upload.vditoruploadsDir); +configService.ensureDirectoryExists(config.upload.vditoruploadsDir); // 配置文件上传 const storage = multer.diskStorage({ @@ -100,22 +34,18 @@ const storage = multer.diskStorage({ cb(null, uploadDir); }, filename: function (req, file, cb) { - // 使用Buffer处理文件名,确保中文字符正确编码 const originalName = Buffer.from(file.originalname, 'latin1').toString('utf8'); - // 检查文件是否已存在,如果存在则添加序号 let fileName = originalName; let fileNameWithoutExt = originalName; let extension = ''; - // 提取文件扩展名 const lastDotIndex = originalName.lastIndexOf('.'); if (lastDotIndex !== -1) { fileNameWithoutExt = originalName.substring(0, lastDotIndex); extension = originalName.substring(lastDotIndex); } - // 检查文件是否存在,如果存在则添加序号 let counter = 1; while (fs.existsSync(path.join(uploadDir, fileName))) { fileName = `${fileNameWithoutExt} (${counter})${extension}`; @@ -127,326 +57,68 @@ const storage = multer.diskStorage({ }); const upload = multer({ storage: storage }); -// 配置Vditor图片上传 -const vditorStorage = multer.diskStorage({ - destination: function (req, file, cb) { - cb(null, vditoruploadsDir); - }, - filename: function (req, file, cb) { - // 生成唯一文件名 - const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9); - const extension = path.extname(file.originalname); - cb(null, uniqueSuffix + extension); - } -}); - -// 限制Vditor只能上传图片和音频文件 -const vditorFileFilter = function(req, file, cb) { - // 检查文件MIME类型 - const allowedMimeTypes = [ - // 图片类型 - 'image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/webp', 'image/svg+xml', - // 音频类型 - 'audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/mp3', 'audio/aac', 'audio/flac' - ]; - - if (allowedMimeTypes.includes(file.mimetype)) { - // 接受文件 - cb(null, true); - } else { - // 拒绝文件 - cb(new Error('只允许上传图片和音频文件'), false); - } -}; - -const vditorUpload = multer({ - storage: vditorStorage, - fileFilter: vditorFileFilter -}); - // 配置视图引擎和静态文件 app.set('view engine', 'ejs'); app.set('views', path.join(__dirname, 'views')); app.use(express.static(path.join(__dirname, 'public'))); app.use('/node_modules', express.static(path.join(__dirname, 'node_modules'))); -app.use('/vditor', express.static(resolvePath(config.upload.vditoruploadsDir))); +app.use('/vditor', express.static(vditoruploadsDir)); // 配置会话 app.use(session({ secret: 'nd-clipboard-secret-key', resave: false, saveUninitialized: true, - cookie: { maxAge: 3600000 } // 会话有效期1小时 + cookie: { maxAge: 3600000 } })); -// 认证中间件 -const authMiddleware = (req, res, next) => { - if (req.session.authenticated) { - return next(); - } - return res.status(403).json({ error: '未授权访问' }); -}; - // 解析请求体 app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); // 初始化数据库 -const dbPath = path.join('/mnt/data', 'clipboard.db'); -let db; +db.connect(); -try { - db = new Database(dbPath); - console.log('已连接到SQLite数据库'); - - // 创建剪贴板表 - db.exec(`CREATE TABLE IF NOT EXISTS clipboard ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - type TEXT NOT NULL, - title TEXT NOT NULL, - content TEXT, - file_path TEXT, - created_at DATETIME DEFAULT CURRENT_TIMESTAMP - )`); - console.log('剪贴板表已创建或已存在'); -} catch (err) { - console.error('数据库连接错误:', err.message); -} +// 设置路由 +setupIndexRoute(app); -// 路由 +// 创建项目路由 +const clipboardRouter = express.Router(); +setupCreateRoutes(clipboardRouter, upload); +setupItemRoutes(clipboardRouter); +app.use(clipboardRouter); -// 首页 - 显示所有剪贴板项目 -app.get('/', (req, res) => { - // 检查URL中是否有密码参数 - const { password } = req.query; - if (password === config.auth.password) { - req.session.authenticated = true; - } - - try { - // 按照创建时间降序排序,确保最新的项目显示在最前面 - const rows = db.prepare(`SELECT * FROM clipboard ORDER BY created_at DESC`).all(); - res.render('index', { - items: rows, - authenticated: req.session.authenticated || false, - formatDateTime: formatDateTime - }); - } catch (err) { - return res.status(500).send('数据库错误: ' + err.message); - } -}); +// 文件相关路由 +app.use(fileRoutes.router); +fileRoutes.setupFileDownloadRoute(app); -// 创建新的剪贴板项目 - 富文本(Markdown) -app.post('/create/markdown', (req, res) => { - const { title, content } = req.body; - try { - db.prepare(`INSERT INTO clipboard (type, title, content) VALUES (?, ?, ?)`) - .run('markdown', title, content); - res.redirect('/'); - } catch (err) { - return res.status(500).json({ error: err.message }); - } -}); +// Vditor 上传 +const vditorUpload = createVditorUpload(); +app.use('/upload', setupVditorRoutes(vditorUpload)); -// 创建新的剪贴板项目 - 纯文本 -app.post('/create/text', (req, res) => { - const { title, content } = req.body; - try { - db.prepare(`INSERT INTO clipboard (type, title, content) VALUES (?, ?, ?)`) - .run('text', title, content); - res.redirect('/'); - } catch (err) { - return res.status(500).json({ error: err.message }); - } -}); - -// 创建新的剪贴板项目 - 链接 -app.post('/create/link', (req, res) => { - const { title, content } = req.body; - try { - db.prepare(`INSERT INTO clipboard (type, title, content) VALUES (?, ?, ?)`) - .run('link', title, content); - res.redirect('/'); - } catch (err) { - return res.status(500).json({ error: err.message }); - } -}); - -// 创建新的剪贴板项目 - 文件 -app.post('/create/file', upload.single('file'), (req, res) => { - // 使用文件原始名称作为标题(如果没有提供标题) - let { title, original_filename } = req.body; - - // 确保文件名编码正确 - if (req.file) { - // 处理可能的编码问题 - const originalName = Buffer.from(req.file.originalname, 'latin1').toString('utf8'); - if (!title) { - title = originalName; - } - // 使用处理后的原始文件名 - original_filename = original_filename || originalName; - } - - // 只存储相对路径格式,保持一致性 - // 无论上传目录如何配置,数据库中始终使用'uploads/filename'格式 - const filePath = req.file ? 'uploads/' + path.basename(req.file.path) : null; - - try { - db.prepare(`INSERT INTO clipboard (type, title, file_path) VALUES (?, ?, ?)`) - .run('file', title, filePath); - res.redirect('/'); - } catch (err) { - return res.status(500).json({ error: err.message }); - } -}); - -// 获取单个剪贴板项目 -app.get('/item/:id', (req, res) => { - const id = req.params.id; - try { - const row = db.prepare(`SELECT * FROM clipboard WHERE id = ?`).get(id); - if (!row) { - return res.status(404).json({ error: '项目未找到' }); - } - res.json(row); - } catch (err) { - return res.status(500).json({ error: err.message }); - } -}); - -// 分享页面 - 显示单个剪贴板项目 -app.get('/share/:id', (req, res) => { - const id = req.params.id; - try { - const row = db.prepare(`SELECT * FROM clipboard WHERE id = ?`).get(id); - if (!row) { - return res.render('share', { item: null, formatDateTime: formatDateTime }); - } - res.render('share', { item: row, formatDateTime: formatDateTime }); - } catch (err) { - console.error('分享页面错误:', err.message); - return res.render('share', { item: null, formatDateTime: formatDateTime }); - } -}); - -// 获取文件信息 -app.get('/file-info/:id', (req, res) => { - try { - const id = req.params.id; - const stmt = db.prepare('SELECT * FROM clipboard WHERE id = ? AND type = \'file\''); - const item = stmt.get(id); - - if (!item || !item.file_path) { - return res.status(404).json({ error: '文件不存在' }); - } - - // 获取文件的完整路径,处理相对路径 - // 从数据库中获取的file_path格式为'uploads/filename',需要提取实际文件名 - const filename = path.basename(item.file_path); - const filePath = path.join(resolvePath(config.upload.uploadDir), filename); - - // 检查文件是否存在 - if (!fs.existsSync(filePath)) { - return res.status(404).json({ error: '文件不存在' }); - } - - // 获取文件信息 - const stats = fs.statSync(filePath); - const fileInfo = { - name: path.basename(filePath), - size: stats.size, - created: stats.birthtime, - modified: stats.mtime, - type: getFileType(filePath) - }; - - res.json(fileInfo); - } catch (err) { - console.error('获取文件信息失败:', err.message); - res.status(500).json({ error: '服务器错误' }); - } -}); +// 管理页面路由 +app.use('/admin', setupAdminRoutes()); -// 获取文件类型 -function getFileType(filePath) { - const extension = path.extname(filePath).toLowerCase(); - const mimeTypes = { - // 图片类型 - '.jpg': 'image/jpeg', - '.jpeg': 'image/jpeg', - '.png': 'image/png', - '.gif': 'image/gif', - '.bmp': 'image/bmp', - '.webp': 'image/webp', - '.svg': 'image/svg+xml', - // 视频类型 - '.mp4': 'video/mp4', - '.webm': 'video/webm', - '.ogg': 'video/ogg', - // 音频类型 - '.mp3': 'audio/mpeg', - '.wav': 'audio/wav', - // 文档类型 - '.pdf': 'application/pdf', - '.doc': 'application/msword', - '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - '.xls': 'application/vnd.ms-excel', - '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - '.ppt': 'application/vnd.ms-powerpoint', - '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - // 纯文本类型 - '.txt': 'text/plain', - '.xml': 'text/xml', - '.json': 'application/json', - '.js': 'text/javascript', - '.py': 'text/x-python', - '.java': 'text/x-java', - '.c': 'text/x-c', - '.cpp': 'text/x-c++', - '.cs': 'text/x-csharp', - '.html': 'text/html', - '.css': 'text/css', - '.md': 'text/markdown', - '.sh': 'text/x-sh', - '.bat': 'text/plain', - '.ps1': 'text/plain', - '.ini': 'text/plain', - '.cfg': 'text/plain', - '.log': 'text/plain', - '.sql': 'text/x-sql', - '.yaml': 'text/yaml', - '.yml': 'text/yaml', - // 压缩文件类型 - '.zip': 'application/zip', - '.rar': 'application/x-rar-compressed', - '.7z': 'application/x-7z-compressed' - }; - - return mimeTypes[extension] || 'application/octet-stream'; -} +// 更新和删除路由(需要认证) +const authMiddleware = createAuthMiddleware(); -// 更新剪贴板项目 app.post('/update/:id', authMiddleware, (req, res) => { const id = req.params.id; const { title, content } = req.body; try { - // 确保只使用title和content两个参数 - const stmt = db.prepare(`UPDATE clipboard SET title = ?, content = ? WHERE id = ?`); - stmt.run(title, content, id); + db.updateItem(id, title, content); res.redirect('/'); } catch (err) { return res.status(500).json({ error: err.message }); } }); -// 删除剪贴板项目 app.post('/delete/:id', authMiddleware, (req, res) => { const id = req.params.id; try { - const row = db.prepare(`SELECT * FROM clipboard WHERE id = ?`).get(id); + const row = db.getItemById(id); if (!row) { return res.status(404).json({ error: '项目未找到' }); @@ -455,410 +127,24 @@ app.post('/delete/:id', authMiddleware, (req, res) => { // 如果是文件类型,删除文件 if (row.type === 'file' && row.file_path) { try { - // 从数据库中获取的file_path格式为'uploads/filename',需要提取实际文件名 const filename = path.basename(row.file_path); - const fullPath = path.join(resolvePath(config.upload.uploadDir), filename); + const fullPath = path.join(uploadDir, filename); fs.unlinkSync(fullPath); } catch (err) { console.error('删除文件失败:', err); } } - // 从数据库中删除记录 - db.prepare(`DELETE FROM clipboard WHERE id = ?`).run(id); + db.deleteItem(id); res.redirect('/'); } catch (err) { return res.status(500).json({ error: err.message }); } }); -// 提供文件下载 -app.get('/uploads/:filename', (req, res) => { - const filename = req.params.filename; - // 使用配置中的上传目录 - const filePath = path.join(resolvePath(config.upload.uploadDir), filename); - - // 检查文件是否存在 - if (!fs.existsSync(filePath)) { - return res.status(404).send('文件未找到'); - } - - // 获取文件信息 - const stat = fs.statSync(filePath); - const fileSize = stat.size; - - // 设置文件名和类型 - res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(filename)}"`); - // 获取文件MIME类型(可选:使用mime-types等库获取更精确的MIME类型) - res.setHeader('Content-Type', 'application/octet-stream'); - // 设置文件大小 - res.setHeader('Content-Length', fileSize); - // 支持断点续传 - res.setHeader('Accept-Ranges', 'bytes'); - - // 处理断点续传请求 - const range = req.headers.range; - if (range) { - // 解析Range头 - const parts = range.replace(/bytes=/, '').split('-'); - const start = parseInt(parts[0], 10); - const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1; - - // 验证范围 - if (start >= fileSize || end >= fileSize || start > end) { - return res.status(416).send('请求范围不满足'); - } - - // 设置部分内容响应头 - const chunkSize = (end - start) + 1; - res.status(206); - res.setHeader('Content-Range', `bytes ${start}-${end}/${fileSize}`); - res.setHeader('Content-Length', chunkSize); - - // 创建范围流 - const stream = fs.createReadStream(filePath, { start, end }); - return stream.pipe(res); - } else { - // 发送完整文件 - return fs.createReadStream(filePath).pipe(res); - } -}); - -// 获取文本文件内容(用于预览) -app.get('/text-preview/:id', (req, res) => { - try { - const id = req.params.id; - const stmt = db.prepare('SELECT * FROM clipboard WHERE id = ? AND type = \'file\''); - const item = stmt.get(id); - - if (!item || !item.file_path) { - return res.status(404).json({ error: '文件不存在' }); - } - - // 获取文件的完整路径,处理相对路径 - // 从数据库中获取的file_path格式为'uploads/filename',需要提取实际文件名 - const filename = path.basename(item.file_path); - const filePath = path.join(resolvePath(config.upload.uploadDir), filename); - - // 检查文件是否存在 - if (!fs.existsSync(filePath)) { - return res.status(404).json({ error: '文件不存在' }); - } - - // 获取文件信息 - const stats = fs.statSync(filePath); - const fileType = getFileType(filePath); - - // 检查文件类型和大小 - const isTextFile = [ - 'text/plain', 'text/xml', 'application/json', 'text/javascript', - 'text/x-python', 'text/x-java', 'text/x-c', 'text/x-c++', 'text/x-csharp', - 'text/html', 'text/css', 'text/markdown', 'text/x-sh', 'text/x-sql', - 'text/yaml' - ].includes(fileType); - - // 文件大小限制为1MB - const sizeLimit = 10 * 1024 * 1024; // 10MB - - if (!isTextFile) { - return res.status(400).json({ error: '不是文本文件' }); - } - - if (stats.size > sizeLimit) { - return res.status(400).json({ error: '文件太大,无法预览' }); - } - - // 读取文件内容 - fs.readFile(filePath, 'utf8', (err, data) => { - if (err) { - console.error('读取文件失败:', err); - return res.status(500).json({ error: '读取文件失败' }); - } - - res.json({ content: data, type: fileType }); - }); - } catch (err) { - console.error('获取文本预览失败:', err.message); - res.status(500).json({ error: '服务器错误' }); - } -}); - -// Vditor上传处理 -app.post('/upload/vditor', (req, res) => { - vditorUpload.single('file')(req, res, function(err) { - // 处理文件过滤器中的错误 - if (err) { - return res.status(400).json({ - msg: err.message || '文件上传失败', - code: 1, - data: {} - }); - } - - try { - if (!req.file) { - return res.status(400).json({ - msg: '未找到上传的文件', - code: 1, - data: {} - }); - } - - // 返回URL - const vditorFileUrl = `/vditor/${req.file.filename}`; - - // 返回符合Vditor要求的数据格式 - res.json({ - msg: '', - code: 0, - data: { - errFiles: [], - succMap: { - [req.file.originalname]: vditorFileUrl - } - } - }); - } catch (err) { - return res.status(500).json({ - msg: err.message, - code: 1, - data: {} - }); - } - }); -}); - -// 管理页面路由 -app.get('/admin', authMiddleware, (req, res) => { - res.render('admin', { config, formatDateTime: formatDateTime }); -}); - -// 更新密码 -app.post('/admin/update-password', authMiddleware, (req, res) => { - try { - const { password } = req.body; - if (!password) { - return res.status(400).json({ success: false, error: '密码不能为空' }); - } - - // 更新配置 - config.auth.password = password; - - // 保存到配置文件 - fs.writeFileSync(path.join('/mnt/data', 'config.json'), JSON.stringify(config, null, 2)); - - res.json({ success: true }); - } catch (err) { - console.error('更新密码失败:', err); - res.status(500).json({ success: false, error: err.message }); - } -}); - -// 更新上传目录 -app.post('/admin/update-upload-dirs', authMiddleware, (req, res) => { - try { - const { uploadDir: newUploadDir, vditoruploadsDir: newVditorDir } = req.body; - - if (!newUploadDir || !newVditorDir) { - return res.status(400).json({ success: false, error: '上传目录不能为空' }); - } - - // 验证并创建目录 - try { - const resolvedUploadDir = resolvePath(newUploadDir); - const resolvedVditorDir = resolvePath(newVditorDir); - - if (!fs.existsSync(resolvedUploadDir)) { - fs.mkdirSync(resolvedUploadDir, { recursive: true }); - } - - if (!fs.existsSync(resolvedVditorDir)) { - fs.mkdirSync(resolvedVditorDir, { recursive: true }); - } - - // 更新配置 - config.upload.uploadDir = newUploadDir; - config.upload.vditoruploadsDir = newVditorDir; - - // 保存到配置文件 - fs.writeFileSync(path.join('/mnt/data', 'config.json'), JSON.stringify(config, null, 2)); - - res.json({ success: true }); - } catch (err) { - throw new Error(`目录创建失败: ${err.message}`); - } - } catch (err) { - console.error('更新上传目录失败:', err); - res.status(500).json({ success: false, error: err.message }); - } -}); - -app.post('/admin/sync-files', authMiddleware, async (req, res) => { - try { - const { - dbMissingFile, - fileMissingDb, - convertTxtToText, - txtMaxSize, - convertMdToMarkdown, - mdMaxSize - } = req.body; - - // 记录传入的参数,用于调试 - console.log('文件同步参数:', { - dbMissingFile, - fileMissingDb, - convertTxtToText, - txtMaxSize, - convertMdToMarkdown, - mdMaxSize, - convertTxtToTextType: typeof convertTxtToText, - convertMdToMarkdownType: typeof convertMdToMarkdown - }); - - // 更新配置 - config.fileSync.dbMissingFile = dbMissingFile; - config.fileSync.fileMissingDb = fileMissingDb; - config.fileSync.convertTxtToText = convertTxtToText === 'on' || convertTxtToText === true; - config.fileSync.txtMaxSize = parseInt(txtMaxSize) || 1024; - config.fileSync.convertMdToMarkdown = convertMdToMarkdown === 'on' || convertMdToMarkdown === true; - config.fileSync.mdMaxSize = parseInt(mdMaxSize) || 1024; - - // 保存到配置文件 - fs.writeFileSync(path.join('/mnt/data', 'config.json'), JSON.stringify(config, null, 2)); - - // 同步结果统计 - const result = { - deletedRecords: 0, - addedRecords: 0, - deletedFiles: 0, - convertedTxtFiles: 0, - convertedMdFiles: 0 - }; - - // 1. 处理数据库中存在但文件不存在的情况 - if (dbMissingFile === 'delete') { - const fileItems = db.prepare(`SELECT * FROM clipboard WHERE type = 'file'`).all(); - - for (const item of fileItems) { - if (item.file_path) { - const filename = path.basename(item.file_path); - const filePath = path.join(resolvePath(config.upload.uploadDir), filename); - if (!fs.existsSync(filePath)) { - // 文件不存在,删除数据库记录 - db.prepare(`DELETE FROM clipboard WHERE id = ?`).run(item.id); - result.deletedRecords++; - } - } - } - } - - // 2. 处理文件存在但数据库中不存在的情况 - if (fileMissingDb === 'add') { - // 获取数据库中所有文件路径 - const dbFilePaths = db.prepare(`SELECT file_path FROM clipboard WHERE type = 'file'`) - .all() - .map(item => item.file_path) - .filter(Boolean); - - // 获取上传目录中所有文件 - const resolvedUploadDir = resolvePath(config.upload.uploadDir); - const files = fs.readdirSync(resolvedUploadDir); - - for (const file of files) { - const relativePath = `uploads/${file}`; - const fullPath = path.join(resolvedUploadDir, file); - - if (fs.statSync(fullPath).isFile() && !dbFilePaths.includes(relativePath)) { - const stats = fs.statSync(fullPath); - const fileExt = path.extname(file).toLowerCase(); - const fileSize = stats.size / 1024; // 转换为KB - const fileName = path.basename(file, fileExt); - - // 检查是否为.txt文件且需要转换为文本剪贴板 - if (fileExt === '.txt' && config.fileSync.convertTxtToText && fileSize <= config.fileSync.txtMaxSize) { - try { - const content = fs.readFileSync(fullPath, 'utf8'); - db.prepare(`INSERT INTO clipboard (type, title, content, created_at) VALUES (?, ?, ?, ?)`) - .run('text', fileName, content, formatDateTime(stats.birthtime)); - result.convertedTxtFiles++; - // 将文件移动到 /deleted 目录 - const deletedFilePath = path.join(resolvedUploadDir, 'deleted', file); - fs.mkdirSync(path.join(resolvedUploadDir, 'deleted'), { recursive: true }); - fs.renameSync(fullPath, deletedFilePath); - result.deletedFiles++; - } catch (err) { - console.error(`转换文本文件失败 ${file}:`, err); - console.error(`文件信息: 路径=${fullPath}, 大小=${fileSize}KB, 限制=${config.fileSync.txtMaxSize}KB`); - } - } - // 检查是否为.md文件且需要转换为Markdown剪贴板 - else if (fileExt === '.md' && config.fileSync.convertMdToMarkdown && fileSize <= config.fileSync.mdMaxSize) { - try { - const content = fs.readFileSync(fullPath, 'utf8'); - db.prepare(`INSERT INTO clipboard (type, title, content, created_at) VALUES (?, ?, ?, ?)`) - .run('markdown', fileName, content, formatDateTime(stats.birthtime)); - result.convertedMdFiles++; - // 将文件移动到 /deleted 目录 - const deletedFilePath = path.join(resolvedUploadDir, 'deleted', file); - fs.mkdirSync(path.join(resolvedUploadDir, 'deleted'), { recursive: true }); - fs.renameSync(fullPath, deletedFilePath); - result.deletedFiles++; - } catch (err) { - console.error(`转换Markdown文件失败 ${file}:`, err); - console.error(`文件信息: 路径=${fullPath}, 大小=${fileSize}KB, 限制=${config.fileSync.mdMaxSize}KB`); - } - } - // 其他文件类型直接添加到数据库 - else { - db.prepare(`INSERT INTO clipboard (type, title, file_path, created_at) VALUES (?, ?, ?, ?)`) - .run('file', fileName, relativePath, formatDateTime(stats.birthtime)); - result.addedRecords++; - } - } - } - } - // 处理文件存在但数据库中不存在的情况,并移动多余的文件到 /deleted 目录 - else if (fileMissingDb === 'delete') { - // 获取数据库中所有文件路径 - const dbFilePaths = db.prepare(`SELECT file_path FROM clipboard WHERE type = 'file'`) - .all() - .map(item => item.file_path) - .filter(Boolean); - - // 获取上传目录中所有文件 - const resolvedUploadDir = resolvePath(config.upload.uploadDir); - const files = fs.readdirSync(resolvedUploadDir); - - for (const file of files) { - const relativePath = `uploads/${file}`; - const fullPath = path.join(resolvedUploadDir, file); - - if (fs.statSync(fullPath).isFile() && !dbFilePaths.includes(relativePath)) { - // 文件存在但数据库中不存在,移动文件到 /deleted 目录 - const deletedFilePath = path.join(resolvedUploadDir, 'deleted', file); - fs.mkdirSync(path.join(resolvedUploadDir, 'deleted'), { recursive: true }); - fs.renameSync(fullPath, deletedFilePath); - result.deletedFiles++; - } - } - } - - res.json({ - success: true, - deletedRecords: result.deletedRecords, - addedRecords: result.addedRecords, - deletedFiles: result.deletedFiles, - convertedTxtFiles: result.convertedTxtFiles, - convertedMdFiles: result.convertedMdFiles - }); - } catch (err) { - console.error('文件同步失败:', err); - res.status(500).json({ success: false, error: err.message }); - } -}); - // 启动服务器 app.listen(port, () => { console.log(`服务器运行在 http://localhost:${port}`); }); + +module.exports = app; diff --git a/app_legacy.js b/app_legacy.js new file mode 100644 index 0000000..a5fc314 --- /dev/null +++ b/app_legacy.js @@ -0,0 +1,864 @@ +const express = require('express'); +const bodyParser = require('body-parser'); +const path = require('path'); +const multer = require('multer'); +const fs = require('fs'); +const Database = require('better-sqlite3'); +const session = require('express-session'); + +/** + * 将 UTC 日期格式化为 UTC+8 的 YYYY/MM/DD hh:mm:ss 格式 + * @param {Date|string} date - 日期对象或日期字符串(应为 UTC 时间) + * @returns {string} 格式化后的 UTC+8 日期字符串 + */ +function formatDateTime(date) { + if (!date) return ''; + + const d = new Date(date); + if (isNaN(d.getTime())) return ''; + + // 将时间转为 UTC 时间戳,再加 8 小时(28800000 毫秒) + const utcTime = d.getTime(); + const utcPlus8Time = utcTime + 8 * 60 * 60 * 1000; + const d8 = new Date(utcPlus8Time); + + const year = d8.getFullYear(); + const month = String(d8.getMonth() + 1).padStart(2, '0'); + const day = String(d8.getDate()).padStart(2, '0'); + const hours = String(d8.getHours()).padStart(2, '0'); + const minutes = String(d8.getMinutes()).padStart(2, '0'); + const seconds = String(d8.getSeconds()).padStart(2, '0'); + + return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`; +} + +// 读取配置文件 +let config; +try { + const configPath = path.join('/mnt/data', 'config.json'); + if (fs.existsSync(configPath)) { + config = JSON.parse(fs.readFileSync(configPath, 'utf8')); + } else { + // 默认配置 + config = { + auth: { password: 'PasePad' }, + upload: { + uploadDir: '/mnt/data/uploads', + vditoruploadsDir: '/mnt/data/vditoruploads' + }, + fileSync: { + dbMissingFile: 'keep', + fileMissingDb: 'keep' + } + }; + // 创建默认配置文件 + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); + } +} catch (err) { + console.error('读取配置文件失败:', err); + // 默认配置 + config = { + auth: { password: 'Abc@123' }, + upload: { + uploadDir: './uploads', + vditoruploadsDir: './vditoruploads' + }, + fileSync: { + dbMissingFile: 'keep', + fileMissingDb: 'keep' + } + }; +} + +// 初始化应用 +const app = express(); +const port = process.env.PORT || 3000; + +// 解析上传目录路径(支持相对路径和绝对路径) +function resolvePath(dirPath) { + if (path.isAbsolute(dirPath)) { + return dirPath; + } + return path.join(__dirname, dirPath.replace(/^\.\//, '')); +} + +// 确保上传目录存在 +const uploadDir = resolvePath(config.upload.uploadDir); +if (!fs.existsSync(uploadDir)) { + fs.mkdirSync(uploadDir, { recursive: true }); +} + +// 确保vditor上传目录存在 +const vditoruploadsDir = resolvePath(config.upload.vditoruploadsDir); +if (!fs.existsSync(vditoruploadsDir)) { + fs.mkdirSync(vditoruploadsDir, { recursive: true }); +} + +// 配置文件上传 +const storage = multer.diskStorage({ + destination: function (req, file, cb) { + cb(null, uploadDir); + }, + filename: function (req, file, cb) { + // 使用Buffer处理文件名,确保中文字符正确编码 + const originalName = Buffer.from(file.originalname, 'latin1').toString('utf8'); + + // 检查文件是否已存在,如果存在则添加序号 + let fileName = originalName; + let fileNameWithoutExt = originalName; + let extension = ''; + + // 提取文件扩展名 + const lastDotIndex = originalName.lastIndexOf('.'); + if (lastDotIndex !== -1) { + fileNameWithoutExt = originalName.substring(0, lastDotIndex); + extension = originalName.substring(lastDotIndex); + } + + // 检查文件是否存在,如果存在则添加序号 + let counter = 1; + while (fs.existsSync(path.join(uploadDir, fileName))) { + fileName = `${fileNameWithoutExt} (${counter})${extension}`; + counter++; + } + + cb(null, fileName); + } +}); +const upload = multer({ storage: storage }); + +// 配置Vditor图片上传 +const vditorStorage = multer.diskStorage({ + destination: function (req, file, cb) { + cb(null, vditoruploadsDir); + }, + filename: function (req, file, cb) { + // 生成唯一文件名 + const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9); + const extension = path.extname(file.originalname); + cb(null, uniqueSuffix + extension); + } +}); + +// 限制Vditor只能上传图片和音频文件 +const vditorFileFilter = function(req, file, cb) { + // 检查文件MIME类型 + const allowedMimeTypes = [ + // 图片类型 + 'image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/webp', 'image/svg+xml', + // 音频类型 + 'audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/mp3', 'audio/aac', 'audio/flac' + ]; + + if (allowedMimeTypes.includes(file.mimetype)) { + // 接受文件 + cb(null, true); + } else { + // 拒绝文件 + cb(new Error('只允许上传图片和音频文件'), false); + } +}; + +const vditorUpload = multer({ + storage: vditorStorage, + fileFilter: vditorFileFilter +}); + +// 配置视图引擎和静态文件 +app.set('view engine', 'ejs'); +app.set('views', path.join(__dirname, 'views')); +app.use(express.static(path.join(__dirname, 'public'))); +app.use('/node_modules', express.static(path.join(__dirname, 'node_modules'))); +app.use('/vditor', express.static(resolvePath(config.upload.vditoruploadsDir))); + +// 配置会话 +app.use(session({ + secret: 'nd-clipboard-secret-key', + resave: false, + saveUninitialized: true, + cookie: { maxAge: 3600000 } // 会话有效期1小时 +})); + +// 认证中间件 +const authMiddleware = (req, res, next) => { + if (req.session.authenticated) { + return next(); + } + return res.status(403).json({ error: '未授权访问' }); +}; + +// 解析请求体 +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: true })); + +// 初始化数据库 +const dbPath = path.join('/mnt/data', 'clipboard.db'); +let db; + +try { + db = new Database(dbPath); + console.log('已连接到SQLite数据库'); + + // 创建剪贴板表 + db.exec(`CREATE TABLE IF NOT EXISTS clipboard ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + type TEXT NOT NULL, + title TEXT NOT NULL, + content TEXT, + file_path TEXT, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP + )`); + console.log('剪贴板表已创建或已存在'); +} catch (err) { + console.error('数据库连接错误:', err.message); +} + +// 路由 + +// 首页 - 显示所有剪贴板项目 +app.get('/', (req, res) => { + // 检查URL中是否有密码参数 + const { password } = req.query; + if (password === config.auth.password) { + req.session.authenticated = true; + } + + try { + // 按照创建时间降序排序,确保最新的项目显示在最前面 + const rows = db.prepare(`SELECT * FROM clipboard ORDER BY created_at DESC`).all(); + res.render('index', { + items: rows, + authenticated: req.session.authenticated || false, + formatDateTime: formatDateTime + }); + } catch (err) { + return res.status(500).send('数据库错误: ' + err.message); + } +}); + +// 创建新的剪贴板项目 - 富文本(Markdown) +app.post('/create/markdown', (req, res) => { + const { title, content } = req.body; + try { + db.prepare(`INSERT INTO clipboard (type, title, content) VALUES (?, ?, ?)`) + .run('markdown', title, content); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } +}); + +// 创建新的剪贴板项目 - 纯文本 +app.post('/create/text', (req, res) => { + const { title, content } = req.body; + try { + db.prepare(`INSERT INTO clipboard (type, title, content) VALUES (?, ?, ?)`) + .run('text', title, content); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } +}); + +// 创建新的剪贴板项目 - 链接 +app.post('/create/link', (req, res) => { + const { title, content } = req.body; + try { + db.prepare(`INSERT INTO clipboard (type, title, content) VALUES (?, ?, ?)`) + .run('link', title, content); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } +}); + +// 创建新的剪贴板项目 - 文件 +app.post('/create/file', upload.single('file'), (req, res) => { + // 使用文件原始名称作为标题(如果没有提供标题) + let { title, original_filename } = req.body; + + // 确保文件名编码正确 + if (req.file) { + // 处理可能的编码问题 + const originalName = Buffer.from(req.file.originalname, 'latin1').toString('utf8'); + if (!title) { + title = originalName; + } + // 使用处理后的原始文件名 + original_filename = original_filename || originalName; + } + + // 只存储相对路径格式,保持一致性 + // 无论上传目录如何配置,数据库中始终使用'uploads/filename'格式 + const filePath = req.file ? 'uploads/' + path.basename(req.file.path) : null; + + try { + db.prepare(`INSERT INTO clipboard (type, title, file_path) VALUES (?, ?, ?)`) + .run('file', title, filePath); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } +}); + +// 获取单个剪贴板项目 +app.get('/item/:id', (req, res) => { + const id = req.params.id; + try { + const row = db.prepare(`SELECT * FROM clipboard WHERE id = ?`).get(id); + if (!row) { + return res.status(404).json({ error: '项目未找到' }); + } + res.json(row); + } catch (err) { + return res.status(500).json({ error: err.message }); + } +}); + +// 分享页面 - 显示单个剪贴板项目 +app.get('/share/:id', (req, res) => { + const id = req.params.id; + try { + const row = db.prepare(`SELECT * FROM clipboard WHERE id = ?`).get(id); + if (!row) { + return res.render('share', { item: null, formatDateTime: formatDateTime }); + } + res.render('share', { item: row, formatDateTime: formatDateTime }); + } catch (err) { + console.error('分享页面错误:', err.message); + return res.render('share', { item: null, formatDateTime: formatDateTime }); + } +}); + +// 获取文件信息 +app.get('/file-info/:id', (req, res) => { + try { + const id = req.params.id; + const stmt = db.prepare('SELECT * FROM clipboard WHERE id = ? AND type = \'file\''); + const item = stmt.get(id); + + if (!item || !item.file_path) { + return res.status(404).json({ error: '文件不存在' }); + } + + // 获取文件的完整路径,处理相对路径 + // 从数据库中获取的file_path格式为'uploads/filename',需要提取实际文件名 + const filename = path.basename(item.file_path); + const filePath = path.join(resolvePath(config.upload.uploadDir), filename); + + // 检查文件是否存在 + if (!fs.existsSync(filePath)) { + return res.status(404).json({ error: '文件不存在' }); + } + + // 获取文件信息 + const stats = fs.statSync(filePath); + const fileInfo = { + name: path.basename(filePath), + size: stats.size, + created: stats.birthtime, + modified: stats.mtime, + type: getFileType(filePath) + }; + + res.json(fileInfo); + } catch (err) { + console.error('获取文件信息失败:', err.message); + res.status(500).json({ error: '服务器错误' }); + } +}); + +// 获取文件类型 +function getFileType(filePath) { + const extension = path.extname(filePath).toLowerCase(); + const mimeTypes = { + // 图片类型 + '.jpg': 'image/jpeg', + '.jpeg': 'image/jpeg', + '.png': 'image/png', + '.gif': 'image/gif', + '.bmp': 'image/bmp', + '.webp': 'image/webp', + '.svg': 'image/svg+xml', + // 视频类型 + '.mp4': 'video/mp4', + '.webm': 'video/webm', + '.ogg': 'video/ogg', + // 音频类型 + '.mp3': 'audio/mpeg', + '.wav': 'audio/wav', + // 文档类型 + '.pdf': 'application/pdf', + '.doc': 'application/msword', + '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + '.xls': 'application/vnd.ms-excel', + '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + '.ppt': 'application/vnd.ms-powerpoint', + '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + // 纯文本类型 + '.txt': 'text/plain', + '.xml': 'text/xml', + '.json': 'application/json', + '.js': 'text/javascript', + '.py': 'text/x-python', + '.java': 'text/x-java', + '.c': 'text/x-c', + '.cpp': 'text/x-c++', + '.cs': 'text/x-csharp', + '.html': 'text/html', + '.css': 'text/css', + '.md': 'text/markdown', + '.sh': 'text/x-sh', + '.bat': 'text/plain', + '.ps1': 'text/plain', + '.ini': 'text/plain', + '.cfg': 'text/plain', + '.log': 'text/plain', + '.sql': 'text/x-sql', + '.yaml': 'text/yaml', + '.yml': 'text/yaml', + // 压缩文件类型 + '.zip': 'application/zip', + '.rar': 'application/x-rar-compressed', + '.7z': 'application/x-7z-compressed' + }; + + return mimeTypes[extension] || 'application/octet-stream'; +} + +// 更新剪贴板项目 +app.post('/update/:id', authMiddleware, (req, res) => { + const id = req.params.id; + const { title, content } = req.body; + + try { + // 确保只使用title和content两个参数 + const stmt = db.prepare(`UPDATE clipboard SET title = ?, content = ? WHERE id = ?`); + stmt.run(title, content, id); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } +}); + +// 删除剪贴板项目 +app.post('/delete/:id', authMiddleware, (req, res) => { + const id = req.params.id; + + try { + const row = db.prepare(`SELECT * FROM clipboard WHERE id = ?`).get(id); + + if (!row) { + return res.status(404).json({ error: '项目未找到' }); + } + + // 如果是文件类型,删除文件 + if (row.type === 'file' && row.file_path) { + try { + // 从数据库中获取的file_path格式为'uploads/filename',需要提取实际文件名 + const filename = path.basename(row.file_path); + const fullPath = path.join(resolvePath(config.upload.uploadDir), filename); + fs.unlinkSync(fullPath); + } catch (err) { + console.error('删除文件失败:', err); + } + } + + // 从数据库中删除记录 + db.prepare(`DELETE FROM clipboard WHERE id = ?`).run(id); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } +}); + +// 提供文件下载 +app.get('/uploads/:filename', (req, res) => { + const filename = req.params.filename; + // 使用配置中的上传目录 + const filePath = path.join(resolvePath(config.upload.uploadDir), filename); + + // 检查文件是否存在 + if (!fs.existsSync(filePath)) { + return res.status(404).send('文件未找到'); + } + + // 获取文件信息 + const stat = fs.statSync(filePath); + const fileSize = stat.size; + + // 设置文件名和类型 + res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(filename)}"`); + // 获取文件MIME类型(可选:使用mime-types等库获取更精确的MIME类型) + res.setHeader('Content-Type', 'application/octet-stream'); + // 设置文件大小 + res.setHeader('Content-Length', fileSize); + // 支持断点续传 + res.setHeader('Accept-Ranges', 'bytes'); + + // 处理断点续传请求 + const range = req.headers.range; + if (range) { + // 解析Range头 + const parts = range.replace(/bytes=/, '').split('-'); + const start = parseInt(parts[0], 10); + const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1; + + // 验证范围 + if (start >= fileSize || end >= fileSize || start > end) { + return res.status(416).send('请求范围不满足'); + } + + // 设置部分内容响应头 + const chunkSize = (end - start) + 1; + res.status(206); + res.setHeader('Content-Range', `bytes ${start}-${end}/${fileSize}`); + res.setHeader('Content-Length', chunkSize); + + // 创建范围流 + const stream = fs.createReadStream(filePath, { start, end }); + return stream.pipe(res); + } else { + // 发送完整文件 + return fs.createReadStream(filePath).pipe(res); + } +}); + +// 获取文本文件内容(用于预览) +app.get('/text-preview/:id', (req, res) => { + try { + const id = req.params.id; + const stmt = db.prepare('SELECT * FROM clipboard WHERE id = ? AND type = \'file\''); + const item = stmt.get(id); + + if (!item || !item.file_path) { + return res.status(404).json({ error: '文件不存在' }); + } + + // 获取文件的完整路径,处理相对路径 + // 从数据库中获取的file_path格式为'uploads/filename',需要提取实际文件名 + const filename = path.basename(item.file_path); + const filePath = path.join(resolvePath(config.upload.uploadDir), filename); + + // 检查文件是否存在 + if (!fs.existsSync(filePath)) { + return res.status(404).json({ error: '文件不存在' }); + } + + // 获取文件信息 + const stats = fs.statSync(filePath); + const fileType = getFileType(filePath); + + // 检查文件类型和大小 + const isTextFile = [ + 'text/plain', 'text/xml', 'application/json', 'text/javascript', + 'text/x-python', 'text/x-java', 'text/x-c', 'text/x-c++', 'text/x-csharp', + 'text/html', 'text/css', 'text/markdown', 'text/x-sh', 'text/x-sql', + 'text/yaml' + ].includes(fileType); + + // 文件大小限制为1MB + const sizeLimit = 10 * 1024 * 1024; // 10MB + + if (!isTextFile) { + return res.status(400).json({ error: '不是文本文件' }); + } + + if (stats.size > sizeLimit) { + return res.status(400).json({ error: '文件太大,无法预览' }); + } + + // 读取文件内容 + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + console.error('读取文件失败:', err); + return res.status(500).json({ error: '读取文件失败' }); + } + + res.json({ content: data, type: fileType }); + }); + } catch (err) { + console.error('获取文本预览失败:', err.message); + res.status(500).json({ error: '服务器错误' }); + } +}); + +// Vditor上传处理 +app.post('/upload/vditor', (req, res) => { + vditorUpload.single('file')(req, res, function(err) { + // 处理文件过滤器中的错误 + if (err) { + return res.status(400).json({ + msg: err.message || '文件上传失败', + code: 1, + data: {} + }); + } + + try { + if (!req.file) { + return res.status(400).json({ + msg: '未找到上传的文件', + code: 1, + data: {} + }); + } + + // 返回URL + const vditorFileUrl = `/vditor/${req.file.filename}`; + + // 返回符合Vditor要求的数据格式 + res.json({ + msg: '', + code: 0, + data: { + errFiles: [], + succMap: { + [req.file.originalname]: vditorFileUrl + } + } + }); + } catch (err) { + return res.status(500).json({ + msg: err.message, + code: 1, + data: {} + }); + } + }); +}); + +// 管理页面路由 +app.get('/admin', authMiddleware, (req, res) => { + res.render('admin', { config, formatDateTime: formatDateTime }); +}); + +// 更新密码 +app.post('/admin/update-password', authMiddleware, (req, res) => { + try { + const { password } = req.body; + if (!password) { + return res.status(400).json({ success: false, error: '密码不能为空' }); + } + + // 更新配置 + config.auth.password = password; + + // 保存到配置文件 + fs.writeFileSync(path.join('/mnt/data', 'config.json'), JSON.stringify(config, null, 2)); + + res.json({ success: true }); + } catch (err) { + console.error('更新密码失败:', err); + res.status(500).json({ success: false, error: err.message }); + } +}); + +// 更新上传目录 +app.post('/admin/update-upload-dirs', authMiddleware, (req, res) => { + try { + const { uploadDir: newUploadDir, vditoruploadsDir: newVditorDir } = req.body; + + if (!newUploadDir || !newVditorDir) { + return res.status(400).json({ success: false, error: '上传目录不能为空' }); + } + + // 验证并创建目录 + try { + const resolvedUploadDir = resolvePath(newUploadDir); + const resolvedVditorDir = resolvePath(newVditorDir); + + if (!fs.existsSync(resolvedUploadDir)) { + fs.mkdirSync(resolvedUploadDir, { recursive: true }); + } + + if (!fs.existsSync(resolvedVditorDir)) { + fs.mkdirSync(resolvedVditorDir, { recursive: true }); + } + + // 更新配置 + config.upload.uploadDir = newUploadDir; + config.upload.vditoruploadsDir = newVditorDir; + + // 保存到配置文件 + fs.writeFileSync(path.join('/mnt/data', 'config.json'), JSON.stringify(config, null, 2)); + + res.json({ success: true }); + } catch (err) { + throw new Error(`目录创建失败: ${err.message}`); + } + } catch (err) { + console.error('更新上传目录失败:', err); + res.status(500).json({ success: false, error: err.message }); + } +}); + +app.post('/admin/sync-files', authMiddleware, async (req, res) => { + try { + const { + dbMissingFile, + fileMissingDb, + convertTxtToText, + txtMaxSize, + convertMdToMarkdown, + mdMaxSize + } = req.body; + + // 记录传入的参数,用于调试 + console.log('文件同步参数:', { + dbMissingFile, + fileMissingDb, + convertTxtToText, + txtMaxSize, + convertMdToMarkdown, + mdMaxSize, + convertTxtToTextType: typeof convertTxtToText, + convertMdToMarkdownType: typeof convertMdToMarkdown + }); + + // 更新配置 + config.fileSync.dbMissingFile = dbMissingFile; + config.fileSync.fileMissingDb = fileMissingDb; + config.fileSync.convertTxtToText = convertTxtToText === 'on' || convertTxtToText === true; + config.fileSync.txtMaxSize = parseInt(txtMaxSize) || 1024; + config.fileSync.convertMdToMarkdown = convertMdToMarkdown === 'on' || convertMdToMarkdown === true; + config.fileSync.mdMaxSize = parseInt(mdMaxSize) || 1024; + + // 保存到配置文件 + fs.writeFileSync(path.join('/mnt/data', 'config.json'), JSON.stringify(config, null, 2)); + + // 同步结果统计 + const result = { + deletedRecords: 0, + addedRecords: 0, + deletedFiles: 0, + convertedTxtFiles: 0, + convertedMdFiles: 0 + }; + + // 1. 处理数据库中存在但文件不存在的情况 + if (dbMissingFile === 'delete') { + const fileItems = db.prepare(`SELECT * FROM clipboard WHERE type = 'file'`).all(); + + for (const item of fileItems) { + if (item.file_path) { + const filename = path.basename(item.file_path); + const filePath = path.join(resolvePath(config.upload.uploadDir), filename); + if (!fs.existsSync(filePath)) { + // 文件不存在,删除数据库记录 + db.prepare(`DELETE FROM clipboard WHERE id = ?`).run(item.id); + result.deletedRecords++; + } + } + } + } + + // 2. 处理文件存在但数据库中不存在的情况 + if (fileMissingDb === 'add') { + // 获取数据库中所有文件路径 + const dbFilePaths = db.prepare(`SELECT file_path FROM clipboard WHERE type = 'file'`) + .all() + .map(item => item.file_path) + .filter(Boolean); + + // 获取上传目录中所有文件 + const resolvedUploadDir = resolvePath(config.upload.uploadDir); + const files = fs.readdirSync(resolvedUploadDir); + + for (const file of files) { + const relativePath = `uploads/${file}`; + const fullPath = path.join(resolvedUploadDir, file); + + if (fs.statSync(fullPath).isFile() && !dbFilePaths.includes(relativePath)) { + const stats = fs.statSync(fullPath); + const fileExt = path.extname(file).toLowerCase(); + const fileSize = stats.size / 1024; // 转换为KB + const fileName = path.basename(file, fileExt); + + // 检查是否为.txt文件且需要转换为文本剪贴板 + if (fileExt === '.txt' && config.fileSync.convertTxtToText && fileSize <= config.fileSync.txtMaxSize) { + try { + const content = fs.readFileSync(fullPath, 'utf8'); + db.prepare(`INSERT INTO clipboard (type, title, content, created_at) VALUES (?, ?, ?, ?)`) + .run('text', fileName, content, formatDateTime(stats.birthtime)); + result.convertedTxtFiles++; + // 将文件移动到 /deleted 目录 + const deletedFilePath = path.join(resolvedUploadDir, 'deleted', file); + fs.mkdirSync(path.join(resolvedUploadDir, 'deleted'), { recursive: true }); + fs.renameSync(fullPath, deletedFilePath); + result.deletedFiles++; + } catch (err) { + console.error(`转换文本文件失败 ${file}:`, err); + console.error(`文件信息: 路径=${fullPath}, 大小=${fileSize}KB, 限制=${config.fileSync.txtMaxSize}KB`); + } + } + // 检查是否为.md文件且需要转换为Markdown剪贴板 + else if (fileExt === '.md' && config.fileSync.convertMdToMarkdown && fileSize <= config.fileSync.mdMaxSize) { + try { + const content = fs.readFileSync(fullPath, 'utf8'); + db.prepare(`INSERT INTO clipboard (type, title, content, created_at) VALUES (?, ?, ?, ?)`) + .run('markdown', fileName, content, formatDateTime(stats.birthtime)); + result.convertedMdFiles++; + // 将文件移动到 /deleted 目录 + const deletedFilePath = path.join(resolvedUploadDir, 'deleted', file); + fs.mkdirSync(path.join(resolvedUploadDir, 'deleted'), { recursive: true }); + fs.renameSync(fullPath, deletedFilePath); + result.deletedFiles++; + } catch (err) { + console.error(`转换Markdown文件失败 ${file}:`, err); + console.error(`文件信息: 路径=${fullPath}, 大小=${fileSize}KB, 限制=${config.fileSync.mdMaxSize}KB`); + } + } + // 其他文件类型直接添加到数据库 + else { + db.prepare(`INSERT INTO clipboard (type, title, file_path, created_at) VALUES (?, ?, ?, ?)`) + .run('file', fileName, relativePath, formatDateTime(stats.birthtime)); + result.addedRecords++; + } + } + } + } + // 处理文件存在但数据库中不存在的情况,并移动多余的文件到 /deleted 目录 + else if (fileMissingDb === 'delete') { + // 获取数据库中所有文件路径 + const dbFilePaths = db.prepare(`SELECT file_path FROM clipboard WHERE type = 'file'`) + .all() + .map(item => item.file_path) + .filter(Boolean); + + // 获取上传目录中所有文件 + const resolvedUploadDir = resolvePath(config.upload.uploadDir); + const files = fs.readdirSync(resolvedUploadDir); + + for (const file of files) { + const relativePath = `uploads/${file}`; + const fullPath = path.join(resolvedUploadDir, file); + + if (fs.statSync(fullPath).isFile() && !dbFilePaths.includes(relativePath)) { + // 文件存在但数据库中不存在,移动文件到 /deleted 目录 + const deletedFilePath = path.join(resolvedUploadDir, 'deleted', file); + fs.mkdirSync(path.join(resolvedUploadDir, 'deleted'), { recursive: true }); + fs.renameSync(fullPath, deletedFilePath); + result.deletedFiles++; + } + } + } + + res.json({ + success: true, + deletedRecords: result.deletedRecords, + addedRecords: result.addedRecords, + deletedFiles: result.deletedFiles, + convertedTxtFiles: result.convertedTxtFiles, + convertedMdFiles: result.convertedMdFiles + }); + } catch (err) { + console.error('文件同步失败:', err); + res.status(500).json({ success: false, error: err.message }); + } +}); + +// 启动服务器 +app.listen(port, () => { + console.log(`服务器运行在 http://localhost:${port}`); +}); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..6ee4826 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1931 @@ +{ + "name": "pasepad-cloud-clipboard", + "version": "1.2.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "pasepad-cloud-clipboard", + "version": "1.2.0", + "dependencies": { + "better-sqlite3": "^11.9.1", + "body-parser": "^1.20.2", + "ejs": "^3.1.9", + "express": "^4.18.2", + "express-session": "^1.18.1", + "multer": "^1.4.5-lts.1", + "vditor": "^3.9.6" + }, + "devDependencies": { + "nodemon": "^3.0.1" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "license": "ISC", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/append-field": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", + "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==", + "license": "MIT" + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "license": "MIT" + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "license": "MIT" + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/better-sqlite3": { + "version": "11.10.0", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-11.10.0.tgz", + "integrity": "sha512-EwhOpyXiOEL/lKzHz9AW1msWFNzGc/z+LzeB3/jnFJpxu+th2yqvzsSWas1v9jgs9+xiXJcD5A8CJxAG2TaghQ==", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "bindings": "^1.5.0", + "prebuild-install": "^7.1.1" + } + }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "license": "MIT", + "dependencies": { + "file-uri-to-path": "1.0.0" + } + }, + "node_modules/bl": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", + "license": "MIT", + "dependencies": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "node_modules/bl/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/body-parser": { + "version": "1.20.4", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.4.tgz", + "integrity": "sha512-ZTgYYLMOXY9qKU/57FAo8F+HA2dGX7bqGc71txDRC1rS4frdFI5R7NhluHxH6M0YItAP0sHB4uqAOcYKxO6uGA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "~1.2.0", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "on-finished": "~2.4.1", + "qs": "~6.14.0", + "raw-body": "~2.5.3", + "type-is": "~1.6.18", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/brace-expansion": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.3.tgz", + "integrity": "sha512-MCV/fYJEbqx68aE58kv2cA/kiky1G8vux3OR6/jbS+jIMe/6fJWa0DTzJU7dqijOWYwHi1t29FlfYI9uytqlpA==", + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "license": "MIT" + }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "license": "MIT", + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chownr": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", + "license": "ISC" + }, + "node_modules/concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "engines": [ + "node >= 0.8" + ], + "license": "MIT", + "dependencies": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==", + "license": "MIT" + }, + "node_modules/core-util-is": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "license": "MIT" + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "license": "MIT", + "dependencies": { + "mimic-response": "^3.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/deep-extend": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", + "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/diff-match-patch": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/diff-match-patch/-/diff-match-patch-1.0.5.tgz", + "integrity": "sha512-IayShXAgj/QMXgB0IWmKx+rOPuGMhqm5w6jvFxmVenXKIzRqTAAsbBPT3kWQeGANj3jGgvcvv4yK6SxqYmikgw==", + "license": "Apache-2.0" + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/ejs": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", + "license": "Apache-2.0", + "dependencies": { + "jake": "^10.8.5" + }, + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/end-of-stream": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", + "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", + "license": "MIT", + "dependencies": { + "once": "^1.4.0" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/expand-template": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", + "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==", + "license": "(MIT OR WTFPL)", + "engines": { + "node": ">=6" + } + }, + "node_modules/express": { + "version": "4.22.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.1.tgz", + "integrity": "sha512-F2X8g9P1X7uCPZMA3MVf9wcTqlyNp7IhH5qPCI0izhaOIYXaW9L535tGA3qmjRzpH+bZczqq7hVKxTR4NWnu+g==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "~1.20.3", + "content-disposition": "~0.5.4", + "content-type": "~1.0.4", + "cookie": "~0.7.1", + "cookie-signature": "~1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.3.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "~0.1.12", + "proxy-addr": "~2.0.7", + "qs": "~6.14.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "~0.19.0", + "serve-static": "~1.16.2", + "setprototypeof": "1.2.0", + "statuses": "~2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express-session": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.19.0.tgz", + "integrity": "sha512-0csaMkGq+vaiZTmSMMGkfdCOabYv192VbytFypcvI0MANrp+4i/7yEkJ0sbAEhycQjntaKGzYfjfXQyVb7BHMA==", + "license": "MIT", + "dependencies": { + "cookie": "~0.7.2", + "cookie-signature": "~1.0.7", + "debug": "~2.6.9", + "depd": "~2.0.0", + "on-headers": "~1.1.0", + "parseurl": "~1.3.3", + "safe-buffer": "~5.2.1", + "uid-safe": "~2.1.5" + }, + "engines": { + "node": ">= 0.8.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "license": "MIT" + }, + "node_modules/filelist": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.6.tgz", + "integrity": "sha512-5giy2PkLYY1cP39p17Ech+2xlpTRL9HLspOfEgm0L6CwBXBTgsK5ou0JtzYuepxkaQ/tvhCFIJ5uXo0OrM2DxA==", + "license": "Apache-2.0", + "dependencies": { + "minimatch": "^5.0.1" + } + }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/finalhandler": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", + "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "statuses": "~2.0.2", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", + "license": "MIT" + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/github-from-package": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", + "integrity": "sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==", + "license": "MIT" + }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", + "dev": true, + "license": "ISC" + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ini": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "license": "MIT", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "license": "MIT" + }, + "node_modules/jake": { + "version": "10.9.4", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.4.tgz", + "integrity": "sha512-wpHYzhxiVQL+IV05BLE2Xn34zW1S223hvjtqk0+gsPrwd/8JNLXJgZZM/iPFsYc1xyphF+6M6EvdE5E9MBGkDA==", + "license": "Apache-2.0", + "dependencies": { + "async": "^3.2.6", + "filelist": "^1.0.4", + "picocolors": "^1.1.1" + }, + "bin": { + "jake": "bin/cli.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/minimatch": { + "version": "5.1.9", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.9.tgz", + "integrity": "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw==", + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/mkdirp-classic": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", + "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", + "license": "MIT" + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/multer": { + "version": "1.4.5-lts.2", + "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.5-lts.2.tgz", + "integrity": "sha512-VzGiVigcG9zUAoCNU+xShztrlr1auZOlurXynNvO9GiWD1/mTBbUljOKY+qMeazBqXgRnjzeEgJI/wyjJUHg9A==", + "deprecated": "Multer 1.x is impacted by a number of vulnerabilities, which have been patched in 2.x. You should upgrade to the latest 2.x version.", + "license": "MIT", + "dependencies": { + "append-field": "^1.0.0", + "busboy": "^1.0.0", + "concat-stream": "^1.5.2", + "mkdirp": "^0.5.4", + "object-assign": "^4.1.1", + "type-is": "^1.6.4", + "xtend": "^4.0.0" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/napi-build-utils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-2.0.0.tgz", + "integrity": "sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-abi": { + "version": "3.89.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.89.0.tgz", + "integrity": "sha512-6u9UwL0HlAl21+agMN3YAMXcKByMqwGx+pq+P76vii5f7hTPtKDp08/H9py6DY+cfDw7kQNTGEj/rly3IgbNQA==", + "license": "MIT", + "dependencies": { + "semver": "^7.3.5" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/nodemon": { + "version": "3.1.14", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.14.tgz", + "integrity": "sha512-jakjZi93UtB3jHMWsXL68FXSAosbLfY0In5gtKq3niLSkrWznrVBzXFNOEMJUfc9+Ke7SHWoAZsiMkNP3vq6Jw==", + "dev": true, + "license": "MIT", + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^4", + "ignore-by-default": "^1.0.1", + "minimatch": "^10.2.1", + "pstree.remy": "^1.1.8", + "semver": "^7.5.3", + "simple-update-notifier": "^2.0.0", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/nodemon/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/nodemon/node_modules/brace-expansion": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.5.tgz", + "integrity": "sha512-VZznLgtwhn+Mact9tfiwx64fA9erHH/MCXEUfB/0bX/6Fz6ny5EGTXYltMocqg4xFAQZtnO3DHWWXi8RiuN7cQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" + } + }, + "node_modules/nodemon/node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/nodemon/node_modules/minimatch": { + "version": "10.2.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.4.tgz", + "integrity": "sha512-oRjTw/97aTBN0RHbYCdtF1MQfvusSIBQM0IZEgzl6426+8jSC0nF1a/GmnVLpfB9yyr6g6FTqWqiZVbxrtaCIg==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "brace-expansion": "^5.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/nodemon/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/on-headers": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.1.0.tgz", + "integrity": "sha512-737ZY3yNnXy37FHkQxPzt4UZ2UWPWiCZWLvFZ4fu5cueciegX0zGPnrlY6bwRg4FdQOe9YU8MkmJwGhoMybl8A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz", + "integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==", + "license": "MIT" + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/prebuild-install": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz", + "integrity": "sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==", + "deprecated": "No longer maintained. Please contact the author of the relevant native addon; alternatives are available.", + "license": "MIT", + "dependencies": { + "detect-libc": "^2.0.0", + "expand-template": "^2.0.3", + "github-from-package": "0.0.0", + "minimist": "^1.2.3", + "mkdirp-classic": "^0.5.3", + "napi-build-utils": "^2.0.0", + "node-abi": "^3.3.0", + "pump": "^3.0.0", + "rc": "^1.2.7", + "simple-get": "^4.0.0", + "tar-fs": "^2.0.0", + "tunnel-agent": "^0.6.0" + }, + "bin": { + "prebuild-install": "bin.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", + "dev": true, + "license": "MIT" + }, + "node_modules/pump": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz", + "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==", + "license": "MIT", + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "node_modules/qs": { + "version": "6.14.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.2.tgz", + "integrity": "sha512-V/yCWTTF7VJ9hIh18Ugr2zhJMP01MY7c5kh4J870L7imm6/DIzBsNLTXzMwUA3yZ5b/KBqLx8Kp3uRvd7xSe3Q==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/random-bytes": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz", + "integrity": "sha512-iv7LhNVO047HzYR3InF6pUcUsPQiHTM1Qal51DcGSuZFBil1aBBWG5eHPNek7bvILMaYJ/8RU1e8w1AMdHmLQQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", + "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/rc": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", + "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", + "license": "(BSD-2-Clause OR MIT OR Apache-2.0)", + "dependencies": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + }, + "bin": { + "rc": "cli.js" + } + }, + "node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "license": "MIT", + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/readable-stream/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "license": "MIT", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/semver": { + "version": "7.7.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", + "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/send": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", + "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.4.1", + "range-parser": "~1.2.1", + "statuses": "~2.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/serve-static": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", + "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", + "license": "MIT", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "~0.19.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/simple-concat": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", + "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/simple-get": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-4.0.1.tgz", + "integrity": "sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "decompress-response": "^6.0.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, + "node_modules/simple-update-notifier": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", + "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^7.5.3" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, + "node_modules/string_decoder/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT" + }, + "node_modules/strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/tar-fs": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz", + "integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==", + "license": "MIT", + "dependencies": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.1.4" + } + }, + "node_modules/tar-stream": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", + "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", + "license": "MIT", + "dependencies": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/tar-stream/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/touch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", + "integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==", + "dev": true, + "license": "ISC", + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, + "node_modules/tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + }, + "engines": { + "node": "*" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", + "license": "MIT" + }, + "node_modules/uid-safe": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", + "integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==", + "license": "MIT", + "dependencies": { + "random-bytes": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", + "dev": true, + "license": "MIT" + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "license": "MIT" + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vditor": { + "version": "3.11.2", + "resolved": "https://registry.npmjs.org/vditor/-/vditor-3.11.2.tgz", + "integrity": "sha512-8QguQQUPWbBFocnfQmWjz4jiykQnvsmCuhOomGIVVK7vc+dQq2h8w9qQQuEjUTZpnZT5fEdYbj4aLr1NGdAZaA==", + "license": "MIT", + "dependencies": { + "diff-match-patch": "^1.0.5" + }, + "funding": { + "url": "https://ld246.com/sponsor" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "license": "MIT", + "engines": { + "node": ">=0.4" + } + } + } +} diff --git a/src/config/index.js b/src/config/index.js new file mode 100644 index 0000000..6716269 --- /dev/null +++ b/src/config/index.js @@ -0,0 +1,77 @@ +const path = require('path'); +const fs = require('fs'); + +// 获取应用根目录(项目所在目录) +const APP_ROOT = path.join(__dirname, '..', '..'); + +/** + * 加载配置文件 + * @returns {Object} 配置对象 + */ +function loadConfig() { + const configPath = path.join(APP_ROOT, 'config.json'); + + try { + if (fs.existsSync(configPath)) { + return JSON.parse(fs.readFileSync(configPath, 'utf8')); + } + } catch (err) { + console.error('读取配置文件失败:', err); + } + + // 默认配置 + return { + auth: { password: 'PasePad' }, + upload: { + uploadDir: './uploads', + vditoruploadsDir: './vditoruploads' + }, + fileSync: { + dbMissingFile: 'keep', + fileMissingDb: 'keep', + convertTxtToText: true, + txtMaxSize: 1000, + convertMdToMarkdown: true, + mdMaxSize: 1000 + } + }; +} + +/** + * 保存配置文件 + * @param {Object} config - 配置对象 + */ +function saveConfig(config) { + const configPath = path.join(APP_ROOT, 'config.json'); + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); +} + +/** + * 解析路径(支持相对路径和绝对路径) + * @param {string} dirPath - 目录路径 + * @returns {string} 绝对路径 + */ +function resolvePath(dirPath) { + if (path.isAbsolute(dirPath)) { + return dirPath; + } + return path.join(__dirname, '..', dirPath.replace(/^\.\//, '')); +} + +/** + * 确保目录存在 + * @param {string} dirPath - 目录路径 + */ +function ensureDirectoryExists(dirPath) { + const resolvedPath = resolvePath(dirPath); + if (!fs.existsSync(resolvedPath)) { + fs.mkdirSync(resolvedPath, { recursive: true }); + } +} + +module.exports = { + loadConfig, + saveConfig, + resolvePath, + ensureDirectoryExists +}; diff --git a/src/database/index.js b/src/database/index.js new file mode 100644 index 0000000..0f56b56 --- /dev/null +++ b/src/database/index.js @@ -0,0 +1,129 @@ +const Database = require('better-sqlite3'); +const path = require('path'); + +// 获取应用根目录(项目所在目录) +const APP_ROOT = path.join(__dirname, '..', '..'); + +class DatabaseService { + constructor() { + this.db = null; + } + + /** + * 初始化数据库连接 + */ + connect() { + const dbPath = path.join(APP_ROOT, 'clipboard.db'); + + try { + this.db = new Database(dbPath); + console.log('已连接到 SQLite 数据库'); + + // 创建剪贴板表 + this.db.exec(`CREATE TABLE IF NOT EXISTS clipboard ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + type TEXT NOT NULL, + title TEXT NOT NULL, + content TEXT, + file_path TEXT, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP + )`); + console.log('剪贴板表已创建或已存在'); + + return true; + } catch (err) { + console.error('数据库连接错误:', err.message); + return false; + } + } + + /** + * 获取所有剪贴板项目 + * @returns {Array} 剪贴板项目数组 + */ + getAllItems() { + return this.db.prepare(`SELECT * FROM clipboard ORDER BY created_at DESC`).all(); + } + + /** + * 根据 ID 获取剪贴板项目 + * @param {number} id - 项目 ID + * @returns {Object|null} 剪贴板项目 + */ + getItemById(id) { + return this.db.prepare(`SELECT * FROM clipboard WHERE id = ?`).get(id); + } + + /** + * 创建剪贴板项目 + * @param {string} type - 类型 (markdown|text|link|file) + * @param {string} title - 标题 + * @param {string} content - 内容 + * @param {string} filePath - 文件路径(可选) + * @param {string} createdAt - 创建时间(可选) + * @returns {Object} 插入结果 + */ + createItem(type, title, content = null, filePath = null, createdAt = null) { + if (createdAt) { + return this.db.prepare( + `INSERT INTO clipboard (type, title, content, file_path, created_at) VALUES (?, ?, ?, ?, ?)` + ).run(type, title, content, filePath, createdAt); + } + + return this.db.prepare( + `INSERT INTO clipboard (type, title, content, file_path) VALUES (?, ?, ?, ?)` + ).run(type, title, content, filePath); + } + + /** + * 更新剪贴板项目 + * @param {number} id - 项目 ID + * @param {string} title - 标题 + * @param {string} content - 内容 + * @returns {Object} 更新结果 + */ + updateItem(id, title, content) { + return this.db.prepare( + `UPDATE clipboard SET title = ?, content = ? WHERE id = ?` + ).run(title, content, id); + } + + /** + * 删除剪贴板项目 + * @param {number} id - 项目 ID + * @returns {Object} 删除结果 + */ + deleteItem(id) { + return this.db.prepare(`DELETE FROM clipboard WHERE id = ?`).run(id); + } + + /** + * 获取所有文件类型的项目 + * @returns {Array} 文件项目数组 + */ + getAllFileItems() { + return this.db.prepare(`SELECT * FROM clipboard WHERE type = 'file'`).all(); + } + + /** + * 获取数据库中所有文件路径 + * @returns {Array} 文件路径数组 + */ + getAllFilePaths() { + return this.db.prepare(`SELECT file_path FROM clipboard WHERE type = 'file'`) + .all() + .map(item => item.file_path) + .filter(Boolean); + } + + /** + * 关闭数据库连接 + */ + close() { + if (this.db) { + this.db.close(); + } + } +} + +module.exports = new DatabaseService(); diff --git a/src/middleware/auth.js b/src/middleware/auth.js new file mode 100644 index 0000000..cbe05ef --- /dev/null +++ b/src/middleware/auth.js @@ -0,0 +1,21 @@ +/** + * 认证中间件 + */ + +/** + * 创建认证中间件 + * @param {Object} config - 配置对象 + * @returns {Function} Express 中间件函数 + */ +function createAuthMiddleware() { + return (req, res, next) => { + if (req.session && req.session.authenticated) { + return next(); + } + return res.status(403).json({ error: '未授权访问' }); + }; +} + +module.exports = { + createAuthMiddleware +}; diff --git a/src/routes/admin.js b/src/routes/admin.js new file mode 100644 index 0000000..535d263 --- /dev/null +++ b/src/routes/admin.js @@ -0,0 +1,294 @@ +const express = require('express'); +const router = express.Router(); +const path = require('path'); +const fs = require('fs'); +const multer = require('multer'); +const db = require('../database'); +const configService = require('../config'); +const { createAuthMiddleware } = require('../middleware/auth'); +const { formatDateTime } = require('../utils/helpers'); + +/** + * 创建 Vditor 上传中间件 + */ +function createVditorUpload() { + const config = configService.loadConfig(); + const vditoruploadsDir = configService.resolvePath(config.upload.vditoruploadsDir); + + const vditorStorage = multer.diskStorage({ + destination: function (req, file, cb) { + cb(null, vditoruploadsDir); + }, + filename: function (req, file, cb) { + const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9); + const extension = path.extname(file.originalname); + cb(null, uniqueSuffix + extension); + } + }); + + const vditorFileFilter = function(req, file, cb) { + const allowedMimeTypes = [ + 'image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/webp', 'image/svg+xml', + 'audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/mp3', 'audio/aac', 'audio/flac' + ]; + + if (allowedMimeTypes.includes(file.mimetype)) { + cb(null, true); + } else { + cb(new Error('只允许上传图片和音频文件'), false); + } + }; + + return multer({ + storage: vditorStorage, + fileFilter: vditorFileFilter + }); +} + +/** + * 设置 Vditor 上传路由 + */ +function setupVditorRoutes(vditorUpload) { + const router = express.Router(); + + router.post('/vditor', (req, res) => { + vditorUpload.single('file')(req, res, function(err) { + if (err) { + return res.status(400).json({ + msg: err.message || '文件上传失败', + code: 1, + data: {} + }); + } + + try { + if (!req.file) { + return res.status(400).json({ + msg: '未找到上传的文件', + code: 1, + data: {} + }); + } + + const vditorFileUrl = `/vditor/${req.file.filename}`; + + res.json({ + msg: '', + code: 0, + data: { + errFiles: [], + succMap: { + [req.file.originalname]: vditorFileUrl + } + } + }); + } catch (err) { + return res.status(500).json({ + msg: err.message, + code: 1, + data: {} + }); + } + }); + }); + + return router; +} + +/** + * 设置管理页面路由 + */ +function setupAdminRoutes() { + const authMiddleware = createAuthMiddleware(); + + // 管理页面 + router.get('/', authMiddleware, (req, res) => { + const config = configService.loadConfig(); + res.render('admin', { config, formatDateTime: formatDateTime }); + }); + + // 更新密码 + router.post('/update-password', authMiddleware, (req, res) => { + try { + const { password } = req.body; + if (!password) { + return res.status(400).json({ success: false, error: '密码不能为空' }); + } + + const config = configService.loadConfig(); + config.auth.password = password; + configService.saveConfig(config); + + res.json({ success: true }); + } catch (err) { + console.error('更新密码失败:', err); + res.status(500).json({ success: false, error: err.message }); + } + }); + + // 更新上传目录 + router.post('/update-upload-dirs', authMiddleware, (req, res) => { + try { + const { uploadDir: newUploadDir, vditoruploadsDir: newVditorDir } = req.body; + + if (!newUploadDir || !newVditorDir) { + return res.status(400).json({ success: false, error: '上传目录不能为空' }); + } + + const config = configService.loadConfig(); + + try { + const resolvedUploadDir = configService.resolvePath(newUploadDir); + const resolvedVditorDir = configService.resolvePath(newVditorDir); + + configService.ensureDirectoryExists(resolvedUploadDir); + configService.ensureDirectoryExists(resolvedVditorDir); + + config.upload.uploadDir = newUploadDir; + config.upload.vditoruploadsDir = newVditorDir; + configService.saveConfig(config); + + res.json({ success: true }); + } catch (err) { + throw new Error(`目录创建失败:${err.message}`); + } + } catch (err) { + console.error('更新上传目录失败:', err); + res.status(500).json({ success: false, error: err.message }); + } + }); + + // 文件同步 + router.post('/sync-files', authMiddleware, async (req, res) => { + try { + const { + dbMissingFile, + fileMissingDb, + convertTxtToText, + txtMaxSize, + convertMdToMarkdown, + mdMaxSize + } = req.body; + + const config = configService.loadConfig(); + + // 更新配置 + config.fileSync.dbMissingFile = dbMissingFile; + config.fileSync.fileMissingDb = fileMissingDb; + config.fileSync.convertTxtToText = convertTxtToText === 'on' || convertTxtToText === true; + config.fileSync.txtMaxSize = parseInt(txtMaxSize) || 1024; + config.fileSync.convertMdToMarkdown = convertMdToMarkdown === 'on' || convertMdToMarkdown === true; + config.fileSync.mdMaxSize = parseInt(mdMaxSize) || 1024; + configService.saveConfig(config); + + const result = { + deletedRecords: 0, + addedRecords: 0, + deletedFiles: 0, + convertedTxtFiles: 0, + convertedMdFiles: 0 + }; + + const uploadDir = configService.resolvePath(config.upload.uploadDir); + + // 1. 处理数据库中存在但文件不存在的情况 + if (dbMissingFile === 'delete') { + const fileItems = db.getAllFileItems(); + + for (const item of fileItems) { + if (item.file_path) { + const filename = path.basename(item.file_path); + const filePath = path.join(uploadDir, filename); + if (!fs.existsSync(filePath)) { + db.deleteItem(item.id); + result.deletedRecords++; + } + } + } + } + + // 2. 处理文件存在但数据库中不存在的情况 + if (fileMissingDb === 'add') { + const dbFilePaths = db.getAllFilePaths(); + const files = fs.readdirSync(uploadDir); + + for (const file of files) { + const relativePath = `uploads/${file}`; + const fullPath = path.join(uploadDir, file); + + if (fs.statSync(fullPath).isFile() && !dbFilePaths.includes(relativePath)) { + const stats = fs.statSync(fullPath); + const fileExt = path.extname(file).toLowerCase(); + const fileSize = stats.size / 1024; + const fileName = path.basename(file, fileExt); + + if (fileExt === '.txt' && config.fileSync.convertTxtToText && fileSize <= config.fileSync.txtMaxSize) { + try { + const content = fs.readFileSync(fullPath, 'utf8'); + db.createItem('text', fileName, content, null, formatDateTime(stats.birthtime)); + result.convertedTxtFiles++; + + const deletedFilePath = path.join(uploadDir, 'deleted', file); + fs.mkdirSync(path.join(uploadDir, 'deleted'), { recursive: true }); + fs.renameSync(fullPath, deletedFilePath); + result.deletedFiles++; + } catch (err) { + console.error(`转换文本文件失败 ${file}:`, err); + } + } + else if (fileExt === '.md' && config.fileSync.convertMdToMarkdown && fileSize <= config.fileSync.mdMaxSize) { + try { + const content = fs.readFileSync(fullPath, 'utf8'); + db.createItem('markdown', fileName, content, null, formatDateTime(stats.birthtime)); + result.convertedMdFiles++; + + const deletedFilePath = path.join(uploadDir, 'deleted', file); + fs.mkdirSync(path.join(uploadDir, 'deleted'), { recursive: true }); + fs.renameSync(fullPath, deletedFilePath); + result.deletedFiles++; + } catch (err) { + console.error(`转换 Markdown 文件失败 ${file}:`, err); + } + } + else { + db.createItem('file', fileName, null, relativePath, formatDateTime(stats.birthtime)); + result.addedRecords++; + } + } + } + } + else if (fileMissingDb === 'delete') { + const dbFilePaths = db.getAllFilePaths(); + const files = fs.readdirSync(uploadDir); + + for (const file of files) { + const relativePath = `uploads/${file}`; + const fullPath = path.join(uploadDir, file); + + if (fs.statSync(fullPath).isFile() && !dbFilePaths.includes(relativePath)) { + const deletedFilePath = path.join(uploadDir, 'deleted', file); + fs.mkdirSync(path.join(uploadDir, 'deleted'), { recursive: true }); + fs.renameSync(fullPath, deletedFilePath); + result.deletedFiles++; + } + } + } + + res.json({ + success: true, + ...result + }); + } catch (err) { + console.error('文件同步失败:', err); + res.status(500).json({ success: false, error: err.message }); + } + }); + + return router; +} + +module.exports = { + createVditorUpload, + setupVditorRoutes, + setupAdminRoutes +}; diff --git a/src/routes/clipboard.js b/src/routes/clipboard.js new file mode 100644 index 0000000..934329c --- /dev/null +++ b/src/routes/clipboard.js @@ -0,0 +1,136 @@ +const express = require('express'); +const router = express.Router(); +const db = require('../database'); +const { formatDateTime } = require('../utils/helpers'); +const configService = require('../config'); + +/** + * 设置首页路由 + * @param {Object} app - Express 应用实例 + */ +function setupIndexRoute(app) { + // 首页 - 显示所有剪贴板项目 + app.get('/', (req, res) => { + // 检查 URL 中是否有密码参数 + const { password } = req.query; + if (password === configService.loadConfig().auth.password) { + req.session.authenticated = true; + } + + try { + const rows = db.getAllItems(); + res.render('index', { + items: rows, + authenticated: req.session.authenticated || false, + formatDateTime: formatDateTime + }); + } catch (err) { + return res.status(500).send('数据库错误:' + err.message); + } + }); +} + +/** + * 设置创建项目路由 + * @param {Object} router - Express 路由器实例 + * @param {Object} upload - Multer 上传中间件 + */ +function setupCreateRoutes(router, upload) { + // 创建新的剪贴板项目 - 富文本 (Markdown) + router.post('/create/markdown', (req, res) => { + const { title, content } = req.body; + try { + db.createItem('markdown', title, content); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } + }); + + // 创建新的剪贴板项目 - 纯文本 + router.post('/create/text', (req, res) => { + const { title, content } = req.body; + try { + db.createItem('text', title, content); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } + }); + + // 创建新的剪贴板项目 - 链接 + router.post('/create/link', (req, res) => { + const { title, content } = req.body; + try { + db.createItem('link', title, content); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } + }); + + // 创建新的剪贴板项目 - 文件 + router.post('/create/file', upload.single('file'), (req, res) => { + let { title, original_filename } = req.body; + + // 确保文件名编码正确 + if (req.file) { + const originalName = Buffer.from(req.file.originalname, 'latin1').toString('utf8'); + if (!title) { + title = originalName; + } + original_filename = original_filename || originalName; + } + + // 只存储相对路径格式 + const filePath = req.file ? 'uploads/' + require('path').basename(req.file.path) : null; + + try { + db.createItem('file', title, null, filePath); + res.redirect('/'); + } catch (err) { + return res.status(500).json({ error: err.message }); + } + }); +} + +/** + * 设置获取项目路由 + * @param {Object} router - Express 路由器实例 + */ +function setupItemRoutes(router) { + // 获取单个剪贴板项目 + router.get('/item/:id', (req, res) => { + const id = req.params.id; + try { + const row = db.getItemById(id); + if (!row) { + return res.status(404).json({ error: '项目未找到' }); + } + res.json(row); + } catch (err) { + return res.status(500).json({ error: err.message }); + } + }); + + // 分享页面 - 显示单个剪贴板项目 + router.get('/share/:id', (req, res) => { + const id = req.params.id; + try { + const row = db.getItemById(id); + if (!row) { + return res.render('share', { item: null, formatDateTime: formatDateTime }); + } + res.render('share', { item: row, formatDateTime: formatDateTime }); + } catch (err) { + console.error('分享页面错误:', err.message); + return res.render('share', { item: null, formatDateTime: formatDateTime }); + } + }); +} + +module.exports = { + setupIndexRoute, + setupCreateRoutes, + setupItemRoutes +}; diff --git a/src/routes/files.js b/src/routes/files.js new file mode 100644 index 0000000..2e8952d --- /dev/null +++ b/src/routes/files.js @@ -0,0 +1,160 @@ +const express = require('express'); +const router = express.Router(); +const path = require('path'); +const fs = require('fs'); +const db = require('../database'); +const configService = require('../config'); +const { getFileType } = require('../utils/helpers'); + +/** + * 设置文件信息路由 + */ +router.get('/file-info/:id', (req, res) => { + try { + const id = req.params.id; + const item = db.getItemById(id); + + if (!item || !item.file_path || item.type !== 'file') { + return res.status(404).json({ error: '文件不存在' }); + } + + // 获取文件的完整路径 + const filename = path.basename(item.file_path); + const uploadDir = configService.resolvePath(configService.loadConfig().upload.uploadDir); + const filePath = path.join(uploadDir, filename); + + // 检查文件是否存在 + if (!fs.existsSync(filePath)) { + return res.status(404).json({ error: '文件不存在' }); + } + + // 获取文件信息 + const stats = fs.statSync(filePath); + const fileInfo = { + name: path.basename(filePath), + size: stats.size, + created: stats.birthtime, + modified: stats.mtime, + type: getFileType(filePath) + }; + + res.json(fileInfo); + } catch (err) { + console.error('获取文件信息失败:', err.message); + res.status(500).json({ error: '服务器错误' }); + } +}); + +/** + * 设置文本预览路由 + */ +router.get('/text-preview/:id', (req, res) => { + try { + const id = req.params.id; + const item = db.getItemById(id); + + if (!item || !item.file_path || item.type !== 'file') { + return res.status(404).json({ error: '文件不存在' }); + } + + // 获取文件的完整路径 + const filename = path.basename(item.file_path); + const uploadDir = configService.resolvePath(configService.loadConfig().upload.uploadDir); + const filePath = path.join(uploadDir, filename); + + // 检查文件是否存在 + if (!fs.existsSync(filePath)) { + return res.status(404).json({ error: '文件不存在' }); + } + + // 获取文件信息 + const stats = fs.statSync(filePath); + const fileType = getFileType(filePath); + + // 检查文件类型和大小 + const isTextFile = [ + 'text/plain', 'text/xml', 'application/json', 'text/javascript', + 'text/x-python', 'text/x-java', 'text/x-c', 'text/x-c++', 'text/x-csharp', + 'text/html', 'text/css', 'text/markdown', 'text/x-sh', 'text/x-sql', + 'text/yaml' + ].includes(fileType); + + // 文件大小限制为 10MB + const sizeLimit = 10 * 1024 * 1024; + + if (!isTextFile) { + return res.status(400).json({ error: '不是文本文件' }); + } + + if (stats.size > sizeLimit) { + return res.status(400).json({ error: '文件太大,无法预览' }); + } + + // 读取文件内容 + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + console.error('读取文件失败:', err); + return res.status(500).json({ error: '读取文件失败' }); + } + + res.json({ content: data, type: fileType }); + }); + } catch (err) { + console.error('获取文本预览失败:', err.message); + res.status(500).json({ error: '服务器错误' }); + } +}); + +/** + * 设置文件下载路由 + * @param {Object} app - Express 应用实例 + */ +function setupFileDownloadRoute(app) { + app.get('/uploads/:filename', (req, res) => { + const filename = req.params.filename; + const uploadDir = configService.resolvePath(configService.loadConfig().upload.uploadDir); + const filePath = path.join(uploadDir, filename); + + // 检查文件是否存在 + if (!fs.existsSync(filePath)) { + return res.status(404).send('文件未找到'); + } + + // 获取文件信息 + const stat = fs.statSync(filePath); + const fileSize = stat.size; + + // 设置文件名和类型 + res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(filename)}"`); + res.setHeader('Content-Type', 'application/octet-stream'); + res.setHeader('Content-Length', fileSize); + res.setHeader('Accept-Ranges', 'bytes'); + + // 处理断点续传请求 + const range = req.headers.range; + if (range) { + const parts = range.replace(/bytes=/, '').split('-'); + const start = parseInt(parts[0], 10); + const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1; + + if (start >= fileSize || end >= fileSize || start > end) { + return res.status(416).send('请求范围不满足'); + } + + const chunkSize = (end - start) + 1; + res.status(206); + res.setHeader('Content-Range', `bytes ${start}-${end}/${fileSize}`); + res.setHeader('Content-Length', chunkSize); + + const stream = fs.createReadStream(filePath, { start, end }); + return stream.pipe(res); + } else { + return fs.createReadStream(filePath).pipe(res); + } + }); +} + +module.exports = { + router, + setupFileDownloadRoute +}; diff --git a/src/utils/helpers.js b/src/utils/helpers.js new file mode 100644 index 0000000..7b55011 --- /dev/null +++ b/src/utils/helpers.js @@ -0,0 +1,93 @@ +/** + * 将 UTC 日期格式化为 UTC+8 的 YYYY/MM/DD hh:mm:ss 格式 + * @param {Date|string} date - 日期对象或日期字符串(应为 UTC 时间) + * @returns {string} 格式化后的 UTC+8 日期字符串 + */ +function formatDateTime(date) { + if (!date) return ''; + + const d = new Date(date); + if (isNaN(d.getTime())) return ''; + + // 将时间转为 UTC 时间戳,再加 8 小时(28800000 毫秒) + const utcTime = d.getTime(); + const utcPlus8Time = utcTime + 8 * 60 * 60 * 1000; + const d8 = new Date(utcPlus8Time); + + const year = d8.getFullYear(); + const month = String(d8.getMonth() + 1).padStart(2, '0'); + const day = String(d8.getDate()).padStart(2, '0'); + const hours = String(d8.getHours()).padStart(2, '0'); + const minutes = String(d8.getMinutes()).padStart(2, '0'); + const seconds = String(d8.getSeconds()).padStart(2, '0'); + + return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`; +} + +/** + * 获取文件 MIME 类型 + * @param {string} filePath - 文件路径 + * @returns {string} MIME 类型 + */ +function getFileType(filePath) { + const path = require('path'); + const extension = path.extname(filePath).toLowerCase(); + const mimeTypes = { + // 图片类型 + '.jpg': 'image/jpeg', + '.jpeg': 'image/jpeg', + '.png': 'image/png', + '.gif': 'image/gif', + '.bmp': 'image/bmp', + '.webp': 'image/webp', + '.svg': 'image/svg+xml', + // 视频类型 + '.mp4': 'video/mp4', + '.webm': 'video/webm', + '.ogg': 'video/ogg', + // 音频类型 + '.mp3': 'audio/mpeg', + '.wav': 'audio/wav', + // 文档类型 + '.pdf': 'application/pdf', + '.doc': 'application/msword', + '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + '.xls': 'application/vnd.ms-excel', + '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + '.ppt': 'application/vnd.ms-powerpoint', + '.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + // 纯文本类型 + '.txt': 'text/plain', + '.xml': 'text/xml', + '.json': 'application/json', + '.js': 'text/javascript', + '.py': 'text/x-python', + '.java': 'text/x-java', + '.c': 'text/x-c', + '.cpp': 'text/x-c++', + '.cs': 'text/x-csharp', + '.html': 'text/html', + '.css': 'text/css', + '.md': 'text/markdown', + '.sh': 'text/x-sh', + '.bat': 'text/plain', + '.ps1': 'text/plain', + '.ini': 'text/plain', + '.cfg': 'text/plain', + '.log': 'text/plain', + '.sql': 'text/x-sql', + '.yaml': 'text/yaml', + '.yml': 'text/yaml', + // 压缩文件类型 + '.zip': 'application/zip', + '.rar': 'application/x-rar-compressed', + '.7z': 'application/x-7z-compressed' + }; + + return mimeTypes[extension] || 'application/octet-stream'; +} + +module.exports = { + formatDateTime, + getFileType +};