|
@@ -0,0 +1,25 @@
|
|
|
+import { Config, Controller, Get, Inject } from "@midwayjs/core";
|
|
|
+import { Context } from '@midwayjs/koa';
|
|
|
+import { makeHttpRequest } from '@midwayjs/core';
|
|
|
+import { get } from "lodash";
|
|
|
+import * as mime from 'mime-types';
|
|
|
+@Controller('/u/cms', { ignoreGlobalPrefix: true })
|
|
|
+export class OldFileController {
|
|
|
+ @Inject()
|
|
|
+ ctx: Context;
|
|
|
+ @Config('urlDomain')
|
|
|
+ urlDomain: string
|
|
|
+
|
|
|
+
|
|
|
+ @Get('/**')
|
|
|
+ async getFile() {
|
|
|
+ const req = this.ctx.request
|
|
|
+ const uri = req.url;
|
|
|
+ const newUrl = `${this.urlDomain}${uri}`
|
|
|
+ const result = await makeHttpRequest(newUrl, { rejectUnauthorized: false })
|
|
|
+ const type = mime.lookup(uri);
|
|
|
+ this.ctx.response.set('content-type', type);
|
|
|
+ this.ctx.body = get(result, 'data');
|
|
|
+ }
|
|
|
+
|
|
|
+}
|