拆分部分文件
This commit is contained in:
1 parent
d5cb96d713
commit
08e7820f37
12 files changed
+448
-210
No files matched your search
@@ -2,13 +2,15 @@ import express from 'express'
|
||||
import cors from 'cors'
|
||||
import Database from 'better-sqlite3';
|
||||
import fs from "fs"
|
||||
|
||||
// import Config from "./miaoShareConfig.json"
|
||||
|
||||
|
||||
const HOST = '0.0.0.0'
|
||||
const PORT = '17058'
|
||||
// const PORT = Config.PORT
|
||||
const PORT = 17057
|
||||
const fileDir = "./temp";
|
||||
const dbPath = './miaoShare.db'
|
||||
const PATH = "./dist";
|
||||
// 上传文件最大大小:200MB
|
||||
const uploadMaxSize=200*1024*1024
|
||||
// 一天的毫秒数
|
||||
@@ -72,7 +74,7 @@ const db_getTimestamp = (id)=>{
|
||||
}
|
||||
|
||||
// 更新存储的文件,删除已经被冻结的文件以及相关记录,然后冻结过期文件
|
||||
const updateFiles = ()=>{
|
||||
const updateDBAndFiles = ()=>{
|
||||
try{
|
||||
let rows = stmt_getFreezenIDs.all()
|
||||
stmt_deleteExpireData.run()
|
||||
@@ -92,13 +94,14 @@ const updateFiles = ()=>{
|
||||
return
|
||||
}
|
||||
}
|
||||
updateFiles()
|
||||
updateDBAndFiles()
|
||||
// 3小时更新一次
|
||||
setInterval(updateFiles,1000*3600*3)
|
||||
setInterval(updateDBAndFiles,1000*3600*3)
|
||||
|
||||
|
||||
var app = express();
|
||||
app.use(cors());
|
||||
app.options('*', cors());
|
||||
var tempMap = {}
|
||||
|
||||
if (!fs.existsSync(fileDir)) {
|
||||
@@ -166,10 +169,8 @@ function downloadFile(req, res, fileId){
|
||||
}
|
||||
}
|
||||
|
||||
// 设置一些通用的中间件
|
||||
// app.use(bodyParser.json());
|
||||
// app.use(bodyParser.urlencoded({extended: true}));
|
||||
|
||||
app.use(express.static(PATH));
|
||||
// app.all()
|
||||
app.post('/file/upload', function(req, res){
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
@@ -208,6 +209,5 @@ app.get('/file/download', function(req, res){
|
||||
|
||||
// 启动服务器
|
||||
app.listen(PORT, HOST, function(){
|
||||
// console.log('Example app listening on port ' + PORT + '.');
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user