lrf 8 months ago
parent
commit
77a5a402d1
2 changed files with 33 additions and 0 deletions
  1. 5 0
      dict.txt
  2. 28 0
      src/controller/dict.controller.ts

+ 5 - 0
dict.txt

@@ -0,0 +1,5 @@
+铅基合金
+合金开发
+合金
+性能
+爱喝紫色汽水

+ 28 - 0
src/controller/dict.controller.ts

@@ -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;
+  }
+}