mirror of
https://github.com/doocs/md.git
synced 2024-11-24 19:10:34 +08:00
feat: support upload to local directory (#95)
This commit is contained in:
parent
760e2896ee
commit
378acb7ad4
4
.gitignore
vendored
4
.gitignore
vendored
@ -42,4 +42,6 @@ yarn-error.log*
|
|||||||
*.sw?
|
*.sw?
|
||||||
|
|
||||||
# mockm
|
# mockm
|
||||||
httpData
|
httpData
|
||||||
|
public/upload/**
|
||||||
|
!public/upload/*.gitkeep
|
22
mm.config.js
22
mm.config.js
@ -4,12 +4,22 @@
|
|||||||
* @type {import('mockm/@types/config').Config}
|
* @type {import('mockm/@types/config').Config}
|
||||||
*/
|
*/
|
||||||
module.exports = (util) => {
|
module.exports = (util) => {
|
||||||
|
const port = 9000
|
||||||
return {
|
return {
|
||||||
|
port,
|
||||||
api: {
|
api: {
|
||||||
'/upload'(req, res) {
|
async '/upload'(req, res) {
|
||||||
res.json({
|
const multiparty = await util.toolObj.generate.initPackge(`multiparty`)
|
||||||
msg: `上传成功`,
|
const form = new multiparty.Form({
|
||||||
url: util.libObj.mockjs.mock(`@image`),
|
uploadDir: `./public/upload/`,
|
||||||
|
})
|
||||||
|
form.parse(req, (err, fields = [], files) => {
|
||||||
|
const path = files.file[0].path.replace(/\\/g, `/`)
|
||||||
|
const url = `http://127.0.0.1:${port}/${path}`
|
||||||
|
res.json({
|
||||||
|
msg: `上传成功`,
|
||||||
|
url,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -21,6 +31,10 @@ module.exports = (util) => {
|
|||||||
{ // 测试 gitee/github 部署
|
{ // 测试 gitee/github 部署
|
||||||
fileDir: `./dist`,
|
fileDir: `./dist`,
|
||||||
path: `/md`,
|
path: `/md`,
|
||||||
|
},,
|
||||||
|
{ // 访问公共目录
|
||||||
|
fileDir: `./public`,
|
||||||
|
path: `/public`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
0
public/upload/.gitkeep
Normal file
0
public/upload/.gitkeep
Normal file
Loading…
Reference in New Issue
Block a user