|
@@ -0,0 +1,28 @@
|
|
|
+import { Body, Controller, Get, Post } from '@midwayjs/core';
|
|
|
+import * as fs from 'fs';
|
|
|
+import * as path from 'path';
|
|
|
+@Controller('/dict')
|
|
|
+export class DictController {
|
|
|
+ fileName = 'dict.txt';
|
|
|
+ @Get('/')
|
|
|
+ async getDict() {
|
|
|
+ const filePath = path.resolve(process.cwd(), this.fileName);
|
|
|
+ const fileData = fs.readFileSync(filePath, 'utf-8');
|
|
|
+ const list = fileData.split('\n');
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Post('/')
|
|
|
+ async updateDict(@Body('data') data: Array<string>) {
|
|
|
+ const filePath = path.resolve(process.cwd(), this.fileName);
|
|
|
+ const fileData = data.join('\n');
|
|
|
+ fs.writeFileSync(filePath, fileData, 'utf-8');
|
|
|
+ }
|
|
|
+
|
|
|
+ @Get('/remote')
|
|
|
+ async remote() {
|
|
|
+ const filePath = path.resolve(process.cwd(), this.fileName);
|
|
|
+ const fileData = fs.readFileSync(filePath, 'utf-8');
|
|
|
+ return fileData;
|
|
|
+ }
|
|
|
+}
|