MISASI commited on
Commit
e01be37
Β·
verified Β·
1 Parent(s): bf4729c

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +18 -4
server.js CHANGED
@@ -14,10 +14,22 @@ const delayIncrement = 100
14
  const maxDelay = 5000
15
  let currentTranslations = 0
16
 
17
- if (fs.existsSync('delay.txt')) {
18
- delay = parseInt(fs.readFileSync('delay.txt', 'utf8'))
 
 
 
 
 
 
 
 
 
 
19
  }
20
 
 
 
21
  console.log('File system loaded')
22
 
23
  app.post('/translate', async (req, res) => {
@@ -44,7 +56,9 @@ app.post('/translate', async (req, res) => {
44
  console.log(`"${text}" -> "${result.text}"`)
45
 
46
  } catch (error) {
47
- res.status(500).json({ error: 'Translation failed' })
 
 
48
  } finally {
49
  currentTranslations-- // λ²ˆμ—­ μ²˜λ¦¬κ°€ λλ‚˜λ©΄ 1 κ°μ†Œ
50
  }
@@ -52,7 +66,7 @@ app.post('/translate', async (req, res) => {
52
 
53
  app.get('/', (req, res) => {
54
  const delayMessage = fs.existsSync('delay.txt') ? fs.readFileSync('delay.txt', 'utf8') : '0'
55
- const statusMessage = `μ„œλ²„κ°€ κ΅¬λ™λ˜μ—ˆμŠ΅λ‹ˆλ‹€. ν˜„μž¬ λ”œλ ˆμ΄ μ‹œκ°„μ€ ${delayMessage}ms이며, ν˜„μž¬ 처리 쀑인 λ²ˆμ—­ μš”μ²­ μˆ˜λŠ” ${currentTranslations}κ±΄μž…λ‹ˆλ‹€.`
56
  res.send(statusMessage)
57
 
58
  })
 
14
  const maxDelay = 5000
15
  let currentTranslations = 0
16
 
17
+ function delayFileTermination(delay) {
18
+ if (fs.existsSync('delay.txt')) {
19
+ delay = parseInt(fs.readFileSync('delay.txt', 'utf8'))
20
+ }else{
21
+ fs.writeFile('delay.txt', 'delay:{$delay}', function(err){
22
+ if(err = null){
23
+ console.log('success')
24
+ }else{
25
+ console.log('fail')
26
+ }
27
+ })
28
+ }
29
  }
30
 
31
+
32
+
33
  console.log('File system loaded')
34
 
35
  app.post('/translate', async (req, res) => {
 
56
  console.log(`"${text}" -> "${result.text}"`)
57
 
58
  } catch (error) {
59
+ console.log(error: 'Translation failed') }
60
+ delay = delay + 100
61
+ console("ν˜„μž¬ Delay νƒ€μž„:" + delay + "ms")
62
  } finally {
63
  currentTranslations-- // λ²ˆμ—­ μ²˜λ¦¬κ°€ λλ‚˜λ©΄ 1 κ°μ†Œ
64
  }
 
66
 
67
  app.get('/', (req, res) => {
68
  const delayMessage = fs.existsSync('delay.txt') ? fs.readFileSync('delay.txt', 'utf8') : '0'
69
+ const statusMessage = `μ„œλ²„κ°€ κ΅¬λ™λ˜μ—ˆμŠ΅λ‹ˆλ‹€. ν˜„μž¬ λ”œλ ˆμ΄ μ‹œκ°„μ€ ${delay}ms이며, ν˜„μž¬ 처리 쀑인 λ²ˆμ—­ μš”μ²­ μˆ˜λŠ” ${currentTranslations}κ±΄μž…λ‹ˆλ‹€.`
70
  res.send(statusMessage)
71
 
72
  })