wangzhibo
6 天以前 3f249e399659dcd09d3fe58071b146e50e45c17f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Provide, Inject, Get, Post, Query, Config } from '@midwayjs/core';
import {
  CoolController,
  BaseController,
  CoolEps,
  TagTypes,
  CoolUrlTag,
  CoolTag,
} from '@cool-midway/core';
import { Context } from '@midwayjs/koa';
import { BaseSysParamService } from '../../service/sys/param';
import { PluginService } from '../../../plugin/service/info';
 
/**
 * 不需要登录的后台接口
 */
@CoolUrlTag()
@Provide()
@CoolController()
export class BaseAppCommController extends BaseController {
  @Inject()
  pluginService: PluginService;
 
  @Inject()
  ctx: Context;
 
  @Config('module.base.allowKeys')
  allowKeys: string[];
 
  @Inject()
  eps: CoolEps;
 
  @Inject()
  baseSysParamService: BaseSysParamService;
 
  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Get('/param', { summary: '参数配置' })
  async param(@Query('key') key: string) {
    if (!this.allowKeys.includes(key)) {
      return this.fail('非法操作');
    }
    return this.ok(await this.baseSysParamService.dataByKey(key));
  }
 
  /**
   * 实体信息与路径
   * @returns
   */
  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Get('/eps', { summary: '实体信息与路径' })
  public async getEps() {
    return this.ok(this.eps.app);
  }
 
  /**
   * 文件上传
   */
  @Post('/upload', { summary: '文件上传' })
  async upload() {
    const file = await this.pluginService.getInstance('upload');
    return this.ok(await file.upload(this.ctx));
  }
 
  /**
   * 文件上传模式,本地或者云存储
   */
  @Get('/uploadMode', { summary: '文件上传模式' })
  async uploadMode() {
    const file = await this.pluginService.getInstance('upload');
    return this.ok(await file.getMode());
  }
}