import { config, method, route, swagger, validate } from "@noderun/hapi-router";
import UploadFunc from "./_upload";
import Joi from "joi";
export default class {
  index(request, h) {
    return h.view("views/demo.ejs");
  }

  @config({
    payload: {
      maxBytes: 20000 * 1024 * 1024,
      output: "stream",
      parse: false,
      // multipart: true,
      allow: "multipart/form-data",
    }
  })
  @method("POST")
  @swagger("文件上传", "文件上传a ", ["sum", "api"])
  async upload(req, h) {
    const startTime = new Date().getTime();
    const res = await UploadFunc(req, h);
    const endTime = new Date().getTime();
    console.log(
      `该请求处理时间为:${Number(endTime - startTime).toFixed(2)}ms`
    );
    return res;
  }

  @route("/{path*}")
  async 404(req, h) {
    // 404页面
    return h.view("404.ejs");
  }
}