1549469775 3 years ago
parent
commit
a95700b8f1
  1. 58380
      log/SQL.log
  2. 1
      route.txt
  3. BIN
      source/db/data.db
  4. 9
      source/route/api/upload/_upload.ts
  5. 1
      source/route/api/user/_doc.md
  6. 43
      source/util/util.ts
  7. 4
      template/views/demo.ejs
  8. 2
      template/views/index.pug
  9. 4
      test/index.js

58380
log/SQL.log

File diff suppressed because it is too large

1
route.txt

@ -1,5 +1,4 @@
所有路由路径:
不需权限: GET /ad
需要权限: GET /api/upload
需要权限: POST /api/upload/upload
不需权限: POST /api/user/register

BIN
source/db/data.db

Binary file not shown.

9
source/route/api/upload/_upload.ts

@ -1,6 +1,6 @@
import path from "path";
import { gSuccess, gFail, uploadDir, uploadPath } from "@/util";
import { dateTimeFormat } from "@/util/util"
const fs = require("fs");
const multiparty = require("multiparty");
const FileType = require("file-type");
@ -10,15 +10,16 @@ function saveFile(file) {
const filename = file.originalFilename;
const uploadedPath = file.path;
const filetype = await FileType.fromFile(uploadedPath);
console.log(filetype);
const _file = path.parse(filename);
if (filetype && (filetype.ext == "jpg" || filetype.ext == "png")) {
const dstPath = path.resolve(uploadDir, filename);
let _name = _file.name + "_" + dateTimeFormat(new Date(), "yyyy_MM_dd") + "_" + new Date().getTime() + _file.ext
const dstPath = path.resolve(uploadDir, _name);
fs.rename(uploadedPath, dstPath, function (err) {
if (err) {
console.log("rename error: " + err);
reject();
} else {
resolve(uploadPath + "/" + filename);
resolve(dstPath);
}
});
} else {

1
source/route/api/user/_doc.md

@ -0,0 +1 @@
### 用户权限模块

43
source/util/util.ts

@ -0,0 +1,43 @@
export function dateTimeFormat(date, fmt = 'yyyy-MM-dd HH:mm:ss') { //日期时间格式化
if (!date) {
return ''
}
if (typeof date === 'string') {
date = date.replace('T', ' ').replace('Z', '');
date = new Date(date.replace(/-/g, '/'))
}
if (typeof date === 'number') {
date = new Date(date)
}
var o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours() % 12 === 0 ? 12 : date.getHours() % 12,
'H+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds(),
'q+': Math.floor((date.getMonth() + 3) / 3),
'S': date.getMilliseconds()
}
var week = {
'0': '\u65e5',
'1': '\u4e00',
'2': '\u4e8c',
'3': '\u4e09',
'4': '\u56db',
'5': '\u4e94',
'6': '\u516d'
}
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
}
if (/(E+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '\u661f\u671f' : '\u5468') : '') + week[date.getDay() + ''])
}
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
}
}
return fmt
}

4
template/views/demo.ejs

@ -1,4 +1,4 @@
<form action="/demo/upload" method="post" enctype="multipart/form-data">
<form action="/api/upload/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" multiple />
<button type="submit" id="upload">上传</button>
</form>
@ -23,7 +23,7 @@
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST", "/demo/upload", true);
xmlhttp.open("POST", "/api/upload/upload", true);
// 这里不需要自己加,会自己处理
// xmlhttp.setRequestHeader("Content-Type", "multipart/form-data");

2
template/views/index.pug

@ -9,6 +9,6 @@ block head
block content
.container
h1.title 终是无缘一别两欢#{ss}
h1.title 终是无缘一别两欢
div.word 昨天看了我初中喜欢的人在空间发的一篇关于怀念初中的短篇小说吧,记录了他对一些记忆深刻的人的评价,而我也看到了我明明一直清楚,却不肯打心底接受的真相,他喜欢另外一个人,过往那么多的蛛丝马迹,那么多明明一件事就能看出他喜欢的人是她的真相,可我却是宁愿找借口自欺欺人,而今他给出坦白答案,他是放下了,才说出来,我是不是也该放下了,直到今日才明白我一个人自以为刻骨铭心的回忆,他也许早就忘怀,他的短篇小说故事中我没有丝言片语,也许若干年后他回想起来的只是我的名字,我只是个戏子,在他的故事中流着自己的泪,一个于他青春年华中不曾使他掀起过一丝波澜的模糊影子,而他不知道也永远不会知道,我的故事里他出现的很多,占了很多篇幅,我把他写进我的故事,因为他路过我心上,他踏着万千星河而来,又乘舟奔赴远方,我与春风皆过客,你携秋水揽星河。如今看来万般故事不过情伤,易水人去,明月如霜。
div.word(href="232") 他是无意穿堂风,却偏偏孤据引山洪。我是垂眉摆渡翁,却独独偏爱哝。

4
test/index.js

@ -0,0 +1,4 @@
const path = require("path")
console.log(path.parse("wallpaper.png"));
console.log(path.format("walll",));
Loading…
Cancel
Save