-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ 耶耶!现在你可以使用 npx 来快速启动 sql2 网页版! 💄 现在消息有进入动画了 🐛 修正在 webkit 下图片预览起出界的问题 <- #134 🐛 修正消息选择在触屏设备下消息背景的异常 🐛 修正一个消息列表元素 key 错误导致元素卡斯的问题
- Loading branch information
Showing
14 changed files
with
224 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.gitignore | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env node | ||
|
||
import * as http from 'http' | ||
import * as fs from 'fs' | ||
import Logger from 'log4js' | ||
|
||
import { checkUpdate } from './update' | ||
|
||
// 日志配置 | ||
const logger = Logger.getLogger('index') | ||
logger.level = 'info' | ||
|
||
let hostname | ||
let port | ||
|
||
// 获取输入参数 | ||
// 参数包括 hostname、port 和 help | ||
const argv = process.argv.slice(2).reduce((acc, cur) => { | ||
const [key, value] = cur.split('=') | ||
acc[key] = value || true | ||
return acc | ||
}, {}) | ||
if(argv['hostname']) { | ||
hostname = argv['hostname'] | ||
} | ||
if(argv['port']) { | ||
port = argv['port'] | ||
} | ||
if(argv['help'] || !hostname || !port) { | ||
// eslint-disable-next-line no-console | ||
console.log(` | ||
Stapxs QQ Lite 网页服务工具: | ||
--hostname 指定服务运行的主机名 | ||
--port 指定服务运行的端口 | ||
--help 查看帮助 | ||
主仓库:https://github.com/Stapxs/Stapxs-QQ-Lite-2.0 | ||
网页服务工具:https://www.npmjs.com/package/ssqq-web | ||
** 欢迎 star 项目,如果有问题请在主仓库提 issue ** | ||
`) | ||
process.exit(0) | ||
} | ||
|
||
logger.info('正在初始化...') | ||
let localVersion = '0.0.1' | ||
// 检查是否存在 dist 文件夹 | ||
if (fs.existsSync('./dist')) { | ||
try { | ||
// 获取文件夹中的 package.json | ||
const packageJson = fs.readFileSync('./dist/package.json', 'utf-8') | ||
localVersion = JSON.parse(packageJson).version | ||
logger.info(`本地版本号为: ${localVersion}`) | ||
} catch (err) { | ||
logger.error(`读取 package.json 失败: ${err}`) | ||
} | ||
} | ||
|
||
// 检查更新 | ||
checkUpdate(localVersion) | ||
|
||
// 创建服务 | ||
const server = http.createServer((req, res) => { | ||
const url = req.url | ||
if (url === '/') { | ||
// 根路径下的请求映射到 dist 文件夹下的 index.html | ||
fs.readFile('./dist/index.html', (err, data) => { | ||
if (err) { | ||
logger.error(`读取 index.html 失败: ${err}`) | ||
res.statusCode = 404 | ||
res.end() | ||
} else { | ||
res.statusCode = 200 | ||
res.setHeader('Content-Type', 'text/html') | ||
res.end(data) | ||
} | ||
}) | ||
} else { | ||
// 其他路径直接映射到 dist 文件夹下 | ||
fs.readFile(`./dist${url}`, (err, data) => { | ||
if (err) { | ||
logger.error(`读取 ${url} 失败: ${err}`) | ||
res.statusCode = 404 | ||
res.end() | ||
} else { | ||
res.statusCode = 200 | ||
res.end(data) | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
server.listen(port, hostname, () => { | ||
logger.info(`服务于 http://${hostname}:${port} 运行`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "ssqq-web", | ||
"version": "1.0.3", | ||
"description": "一个兼容 OneBot 的非官方网页版 QQ 客户端,Web 端快速启动包。", | ||
"main": "index.ts", | ||
"bin": { | ||
"ssqq-web": "bin/index.js" | ||
}, | ||
"scripts": { | ||
"start": "tsc && node index.js", | ||
"build": "tsc", | ||
"test": "tsc && node index.js help" | ||
}, | ||
"repository": "https://github.com/Stapxs/Stapxs-QQ-Lite-2.0", | ||
"author": "Stapx Steve [林槐]", | ||
"license": "Apache-2.0", | ||
"private": false, | ||
"dependencies": { | ||
"log4js": "^6.9.1", | ||
"request": "^2.88.2", | ||
"semver-compare": "^1.0.0", | ||
"typescript": "^5.6.3", | ||
"unzipper": "^0.12.3" | ||
}, | ||
"devDependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"outDir": "bin" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env node | ||
|
||
import cmp from 'semver-compare' | ||
import Logger from 'log4js' | ||
import request from 'request' | ||
import unzipper from 'unzipper' | ||
import fs from 'fs' | ||
|
||
// 日志配置 | ||
const logger = Logger.getLogger('update') | ||
logger.level = 'info' | ||
|
||
|
||
export function checkUpdate(nowVersion: string) { | ||
// 检查本体版本 | ||
fetch('https://api.github.com/repos/Stapxs/Stapxs-QQ-Lite-2.0/releases/latest') | ||
.then(res => res.json()) | ||
.then(json => { | ||
const version = json.tag_name.slice(1) | ||
logger.info(`Stapxs QQ Lite 当前版本: ${version}, 本地版本: ${nowVersion}`) | ||
if (cmp(nowVersion, version) === -1) { | ||
// 本地版本小于线上版本, 需要更新 | ||
logger.info('发现新版本, 正在更新...') | ||
logger.info(`运行路径: ${process.cwd()}`) | ||
// 下载新版本 | ||
const assetList = json.assets | ||
assetList.forEach(asset => { | ||
const name = asset.name | ||
// 寻找结尾为 -web.zip 的文件 | ||
if (name.endsWith('-web.zip')) { | ||
// 删除 dist 文件夹 | ||
if(fs.existsSync('./dist')) { | ||
fs.rm('./dist', { recursive: true }, err => { | ||
if (err) { | ||
logger.error(`删除 dist 文件夹失败: ${err}`) | ||
} | ||
} | ||
) | ||
} | ||
const downloadUrl = asset.browser_download_url | ||
logger.info(`下载地址: ${downloadUrl}`) | ||
// 下载文件并解压 | ||
request(downloadUrl).pipe(unzipper.Extract({ path: './' })) | ||
.on('close', () => { | ||
logger.info('更新完成') | ||
// 保存版本缓存 | ||
fs.writeFile('./dist/package.json', JSON.stringify({ | ||
version: version | ||
}), err => { | ||
if (err) { | ||
logger.error(`保存版本缓存失败: ${err}`) | ||
} | ||
}) | ||
}) | ||
} | ||
}) | ||
} else { | ||
logger.info('当前已是最新版本') | ||
} | ||
}) | ||
.catch(err => { | ||
logger.error(`检查更新失败: ${err}`) | ||
}) | ||
} |