@smpx/koa-request 0.2.8 → 0.3.0

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.
Files changed (2) hide show
  1. package/Request.js +20 -3
  2. package/package.json +5 -5
package/Request.js CHANGED
@@ -37,6 +37,7 @@ const COOKIEID_COOKIE = 'id';
37
37
  const COOKIE_PARAM_PREFIX = '_ck_';
38
38
  const USER_TOKEN_COOKIE = 'utok';
39
39
  const FLASH_COOKIE = 'flash';
40
+ const VIEWPORT_WIDTH_COOKIE = 'vw';
40
41
  // these cookies are httpOnly, should not be readable from js
41
42
  const SENSITIVE_COOKIES = [USER_TOKEN_COOKIE, COOKIEID_COOKIE, SESSIONID_COOKIE];
42
43
 
@@ -756,9 +757,21 @@ class Request {
756
757
  return false;
757
758
  }
758
759
 
759
- if (!this._isMobileWeb) {
760
- const ua = this.parseUserAgent();
761
- this._isMobileWeb = (ua && ua.device && ua.device.type === 'mobile') || false;
760
+ if (this._isMobileWeb == null) {
761
+ const secHeader = this.ctx.headers['sec-ch-ua-mobile'];
762
+ if (secHeader) {
763
+ this._isMobileWeb = secHeader === '?1';
764
+ }
765
+ else {
766
+ const vwCookie = this.cookie(VIEWPORT_WIDTH_COOKIE);
767
+ if (vwCookie) {
768
+ this._isMobileWeb = Number(vwCookie) <= 750;
769
+ }
770
+ else {
771
+ const ua = this.parseUserAgent();
772
+ this._isMobileWeb = (ua && ua.device && ua.device.type === 'mobile') || false;
773
+ }
774
+ }
762
775
  }
763
776
  return this._isMobileWeb;
764
777
  }
@@ -767,6 +780,10 @@ class Request {
767
780
  return this.isMobileApp() || this.isMobileWeb();
768
781
  }
769
782
 
783
+ isAPI() {
784
+ return false;
785
+ }
786
+
770
787
  platform() {
771
788
  if (!this._platform) {
772
789
  if (this.isMobileApp()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smpx/koa-request",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "Handle basic tasks for koajs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -30,12 +30,12 @@
30
30
  },
31
31
  "homepage": "https://github.com/smartprix/koa-request#readme",
32
32
  "dependencies": {
33
- "ip": "^1.1.5",
33
+ "ip": "^1.1.8",
34
34
  "koa-basic-auth": "^4.0.0",
35
- "koa-body": "^4.2.0",
35
+ "koa-body": "^5.0.0",
36
36
  "koa-send": "^5.0.1",
37
- "koa2-ratelimit": "^0.9.1",
38
- "maxmind": "^4.3.3",
37
+ "koa2-ratelimit": "^1.1.1",
38
+ "maxmind": "^4.3.6",
39
39
  "tar": "^6.1.11",
40
40
  "ua-parser-js": "^1.0.2"
41
41
  },