topbit 3.0.6 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/demo/upserv.js ADDED
@@ -0,0 +1,35 @@
1
+ 'use strict'
2
+
3
+ process.chdir(__dirname)
4
+
5
+ const fs = require('node:fs')
6
+ const Topbit = require('../src/topbit.js')
7
+
8
+ let app = new Topbit({
9
+ debug: true,
10
+ globalLog: true
11
+ })
12
+
13
+ let {ToFile,Timing} = Topbit.extensions
14
+
15
+ app.pre(new Timing({test: true}))
16
+
17
+ app.use(new ToFile, {group: 'upload'})
18
+
19
+ let fsp = fs.promises
20
+
21
+ fsp.access('./tmp').catch(err => {
22
+ fsp.mkdir('tmp')
23
+ })
24
+
25
+ app.post('/file', async ctx => {
26
+
27
+ let f = ctx.getFile('file')
28
+
29
+ if (!f) return ctx.status(400).oo('file not found')
30
+
31
+ ctx.to( await f.toFile('tmp') )
32
+
33
+ }, {group: 'upload'})
34
+
35
+ app.run(1234)
package/docs/README.md CHANGED
@@ -11,6 +11,6 @@
11
11
 
12
12
  ## English Document
13
13
 
14
- [TopbitLoader](./topbit-loader.md)
14
+ [TopbitLoader](./en/topbit-loader.md)
15
15
 
16
- [TopbitToken](./topbit-token.md)
16
+ [TopbitToken](./en/topbit-token.md)
@@ -1,4 +1,4 @@
1
- # TopbitLoader Complete User Manual
1
+ # 🤖 TopbitLoader Complete User Manual
2
2
 
3
3
  ---
4
4
 
@@ -1,4 +1,6 @@
1
- # TopbitToken – Ultra-Fast & Secure Token System for Topbit
1
+ # 🔐 TopbitToken
2
+
3
+ **Ultra-Fast & Secure Token System for Topbit🪙**
2
4
 
3
5
 
4
6
  ### 1. What is TopbitToken?
@@ -1,4 +1,4 @@
1
- # TopbitLoader 完全使用手册
1
+ # 🤖 TopbitLoader 完全使用手册
2
2
 
3
3
  ### 一、TopbitLoader 是什么?
4
4
 
@@ -1,4 +1,6 @@
1
- # TopbitToken – 极简、高性能、可刷新的加密 Token 解决方案
1
+ # 🔐 TopbitToken
2
+
3
+ **极简、高性能、可刷新的加密 Token 解决方案🪙**
2
4
 
3
5
  ---
4
6
 
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topbit",
3
- "version": "3.0.6",
3
+ "version": "3.0.7",
4
4
  "description": "A Server-side web framework support http/1.1 and http/2",
5
5
  "main": "src/topbit.js",
6
6
  "directories": {
package/src/bodyparser.js CHANGED
@@ -197,7 +197,7 @@ class Bodyparser {
197
197
  if (cdpobj.filename !== undefined) {
198
198
  let file_post = {
199
199
  filename: cdpobj.filename,
200
- 'content-type': headers['content-type'] || 'application/octet-stream',
200
+ type: headers['content-type'] || 'application/octet-stream',
201
201
  start: data_start,
202
202
  end: end_ind,
203
203
  length: data_length,
@@ -210,8 +210,6 @@ class Bodyparser {
210
210
  file_post.filename = file_post.filename.substring(slash_index+1);
211
211
  }
212
212
 
213
- //content-type
214
- file_post.type = file_post['content-type'];
215
213
  let upload_name = cdpobj.name || 'file';
216
214
 
217
215
  if (ctx.files[upload_name] === undefined) {
@@ -6,9 +6,8 @@ class Cookie {
6
6
  }
7
7
 
8
8
  mid() {
9
-
10
9
  return async (rr, next) => {
11
- rr.cookie = {}
10
+ rr.box.cookie = {}
12
11
 
13
12
  if (rr.headers['cookie']) {
14
13
  let cookies = rr.headers['cookie'].split(';').filter(c => c.length > 0)
@@ -25,16 +24,16 @@ class Cookie {
25
24
  }
26
25
 
27
26
  if (tmpList.length < 2) {
28
- rr.cookie[name] = ''
27
+ rr.box.cookie[name] = ''
29
28
  } else {
30
- rr.cookie[name] = tmpList[1]
29
+ rr.box.cookie[name] = tmpList[1]
31
30
  }
32
31
  }
33
32
  }
34
33
 
35
34
  await next(rr)
36
35
 
37
- rr.cookie = null
36
+ rr.box.cookie = null
38
37
  }
39
38
 
40
39
  }
@@ -196,16 +196,15 @@ class JWT {
196
196
  return async (ctx, next) => {
197
197
  let token = ctx.headers.authorization || ctx.query.token
198
198
  if (!token) {
199
- return ctx.status(401).send('unauthorized')
199
+ return ctx.status(401).to('unauthorized')
200
200
  }
201
201
 
202
202
  let r = self.verify(token)
203
203
 
204
204
  if (!r.ok) {
205
- return ctx.status(401).send(r.errcode)
205
+ return ctx.status(401).to(r.errcode)
206
206
  }
207
207
 
208
- ctx.box.user = r.data
209
208
  ctx.user = r.data
210
209
 
211
210
  await next(ctx)
@@ -155,7 +155,7 @@ class Session {
155
155
 
156
156
  }
157
157
 
158
- await next()
158
+ await next(c)
159
159
 
160
160
  if (c._sessionState) {
161
161
  let tmpText = JSON.stringify(c._session)
@@ -20,7 +20,7 @@ class Timing {
20
20
  PATCH : new Map()
21
21
  }
22
22
 
23
- this.maxLimit = 100
23
+ this.maxLimit = 1000
24
24
 
25
25
  this.test = false
26
26
 
@@ -51,7 +51,7 @@ class Timing {
51
51
 
52
52
  let start_time = Date.now()
53
53
 
54
- await next()
54
+ await next(c)
55
55
 
56
56
  let end_time = Date.now()
57
57
 
@@ -109,11 +109,11 @@ class ToFile {
109
109
  let self = this
110
110
  return async (c, next) => {
111
111
  if (!c.isUpload) {
112
- return await next()
112
+ return await next(c)
113
113
  }
114
114
 
115
115
  c.getFile = getFile
116
- await next()
116
+ await next(c)
117
117
  }
118
118
 
119
119
  }
package/src/topbit.js CHANGED
@@ -387,6 +387,9 @@ class Topbit {
387
387
  case 'fastParseQuery':
388
388
  case 'allowHTTP1':
389
389
  this.config[k] = !!options[k]; break;
390
+
391
+ case 'log':
392
+ this.config.globalLog = !!options[k]; break;
390
393
 
391
394
  case 'notFound':
392
395
  case 'badRequest':
@@ -878,7 +881,7 @@ class Topbit {
878
881
  //如果没有添加路由则添加默认路由
879
882
  if (this.router.count === 0) {
880
883
  this.router.get('/*', async c => {
881
- c.setHeader('content-type', 'text/html; charset=utf-8').send(_topbit_home_page)
884
+ c.setHeader('content-type', 'text/html; charset=utf-8').to(_topbit_home_page)
882
885
  })
883
886
  }
884
887