You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
var express = require ( 'express' ) ;
var router = express . Router ( ) ;
const path = require ( "path" ) ;
const userfileService = require ( "../services/userfile.service" ) ;
/* GET users listing. */
router . get ( '/admin' , async function ( req , res , next ) {
if ( ! req . session . admin ) {
req . session . message = "您没有管理员权限!"
res . redirect ( '/' )
} else {
// 这里我们要拿到所有用户以及他们的文件,然后交给 ejs去渲染, 渲染的时候
// 为每个文件 (a标签) 添加一个链接,这个链接我们会在后端去处理,就在下面
const title = 'Dynamic EJS Page' ;
const message = myVariable1 ;
res . render ( 'admin' , { title : title , message : message } ) ;
}
} ) ;
// 处理下载文件请求
// 获取前端传来的username 和 filename, 根据这两个参数拼接文件路径
router . get ( '/admin/download' , ( req , res ) => {
var username = req . query . username ;
var filename = req . query . filename ;
if ( ! req . session . admin ) {
return res . send ( "没有权限!" ) ;
}
console . log ( username , filename )
if ( ! username || ! filename ) {
return res . send ( "没有该文件!" ) ;
}
// 查找文件
// res.sendFile 必须使用绝对路径,它的作用是响应出去一个任意类型文件给前端
res . sendFile ( path . resolve ( _ _dirname , '../users/' + username + "/" + filename ) ) ;
} ) ;
module . exports = router ;