app.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const express = require('express');
  2. const app = express();
  3. const PORT = 2345;
  4. app.use(express.json());
  5. class Log {
  6. static debug(message, additionalInfo = '') {
  7. this.log('D', message, additionalInfo, '\x1b[34m');
  8. }
  9. static info(message, additionalInfo = '') {
  10. this.log('I', message, additionalInfo, '\x1b[32m');
  11. }
  12. static success(message, additionalInfo = '') {
  13. this.log('S', message, additionalInfo, '\x1b[36m');
  14. }
  15. static warning(message, additionalInfo = '') {
  16. this.log('W', message, additionalInfo, '\x1b[33m');
  17. }
  18. static error(message, additionalInfo = '') {
  19. this.log('E', message, additionalInfo, '\x1b[31m');
  20. }
  21. static log(level, message, additionalInfo, color) {
  22. const timestamp = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
  23. const logMessage = `${timestamp} [${level}] ${additionalInfo} ${message}`;
  24. console.log(`${color}${logMessage}\x1b[0m`);
  25. }
  26. }
  27. // 访问根路径返回
  28. app.get("/", (res, req) => {
  29. });
  30. // 根据取件码获取文件
  31. // 返回文件的二进制流或者返回文件下载的直接链接
  32. app.post("/fetch", (res, req) => {
  33. });
  34. // 上传文件获取取件码
  35. // 返回内容包括:取件码 文件名 文件大小
  36. app.post("/upload", (res, req) => {
  37. });
  38. // 用于相应直接链接的下载请求
  39. app.get("/download", (res, req) => {
  40. });
  41. // 获取统计信息
  42. app.get("/statistic", (res, req) => {
  43. });
  44. app.listen(PORT, () => {
  45. Log.info("Server running on port: " + PORT + ";")
  46. });