fishpi 0.0.3 → 0.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/lib/src/utils.js CHANGED
@@ -27,61 +27,106 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
27
27
  step((generator = generator.apply(thisArg, _arguments || [])).next());
28
28
  });
29
29
  };
30
+ var __generator = (this && this.__generator) || function (thisArg, body) {
31
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
+ function verb(n) { return function (v) { return step([n, v]); }; }
34
+ function step(op) {
35
+ if (f) throw new TypeError("Generator is already executing.");
36
+ while (_) try {
37
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
38
+ if (y = 0, t) op = [op[0] & 2, t.value];
39
+ switch (op[0]) {
40
+ case 0: case 1: t = op; break;
41
+ case 4: _.label++; return { value: op[1], done: false };
42
+ case 5: _.label++; y = op[1]; op = [0]; continue;
43
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
+ default:
45
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
+ if (t[2]) _.ops.pop();
50
+ _.trys.pop(); continue;
51
+ }
52
+ op = body.call(thisArg, _);
53
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
+ }
56
+ };
30
57
  var __importDefault = (this && this.__importDefault) || function (mod) {
31
58
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
59
  };
33
60
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.isBrowse = exports.toMetal = exports.domain = exports.request = void 0;
35
- const axios_1 = __importDefault(require("axios"));
36
- const https = __importStar(require("https"));
37
- const domain = 'fishpi.cn/';
61
+ exports.isBrowse = exports.analyzeMetalAttr = exports.toMetal = exports.domain = exports.request = void 0;
62
+ var axios_1 = __importDefault(require("axios"));
63
+ var https = __importStar(require("https"));
64
+ var domain = 'fishpi.cn/';
38
65
  exports.domain = domain;
39
66
  function request(opt) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- let { url, method = 'get', headers = {}, data } = opt;
42
- if (!isBrowse) {
43
- headers['User-Agent'] = `Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36`;
44
- headers['Referer'] = `https://${domain}`;
45
- }
46
- let options = {
47
- method, headers,
48
- httpsAgent: new https.Agent({
49
- keepAlive: true,
50
- rejectUnauthorized: false,
51
- }),
52
- data
53
- };
54
- let rsp;
55
- try {
56
- rsp = yield (0, axios_1.default)(`https://${domain}${url}`, options);
57
- return rsp;
58
- }
59
- catch (err) {
60
- if (err.response.status === 401) {
61
- return err.response;
67
+ return __awaiter(this, void 0, void 0, function () {
68
+ var url, _a, method, _b, headers, data, options, rsp, err_1;
69
+ return __generator(this, function (_c) {
70
+ switch (_c.label) {
71
+ case 0:
72
+ url = opt.url, _a = opt.method, method = _a === void 0 ? 'get' : _a, _b = opt.headers, headers = _b === void 0 ? {} : _b, data = opt.data;
73
+ if (!isBrowse) {
74
+ headers['User-Agent'] = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36";
75
+ headers['Referer'] = "https://".concat(domain);
76
+ }
77
+ options = {
78
+ method: method,
79
+ headers: headers,
80
+ httpsAgent: new https.Agent({
81
+ keepAlive: true,
82
+ rejectUnauthorized: false,
83
+ }),
84
+ data: data
85
+ };
86
+ _c.label = 1;
87
+ case 1:
88
+ _c.trys.push([1, 3, , 4]);
89
+ return [4 /*yield*/, (0, axios_1.default)("https://".concat(domain).concat(url), options)];
90
+ case 2:
91
+ rsp = _c.sent();
92
+ return [2 /*return*/, rsp];
93
+ case 3:
94
+ err_1 = _c.sent();
95
+ if (err_1.response.status === 401) {
96
+ return [2 /*return*/, err_1.response];
97
+ }
98
+ throw (err_1);
99
+ case 4: return [2 /*return*/];
62
100
  }
63
- throw (err);
64
- }
101
+ });
65
102
  });
66
103
  }
67
104
  exports.request = request;
105
+ function analyzeMetalAttr(m) {
106
+ if (!m)
107
+ return m;
108
+ if (typeof m.attr != 'string')
109
+ return m;
110
+ var attr = m.attr.split('&');
111
+ m.attr = {};
112
+ attr.forEach(function (a) { return m.attr[a.split('=')[0]] = a.split('=')[1]; });
113
+ m.url = "https://fishpi.cn/gen?txt=".concat(m.description, "&").concat(m.attr.url);
114
+ m.icon = "https://fishpi.cn/gen?txt=&".concat(m.attr.url);
115
+ return m;
116
+ }
117
+ exports.analyzeMetalAttr = analyzeMetalAttr;
68
118
  function toMetal(sysMetal) {
69
119
  try {
70
- let metal = JSON.parse(sysMetal);
71
- metal.list.forEach((m, i, list) => {
72
- let attr = m.attr.split('&');
73
- m.attr = {};
74
- attr.forEach((a) => m.attr[a.split('=')[0]] = a.split('=')[1]);
75
- list[i] = m;
120
+ var metal = JSON.parse(sysMetal);
121
+ metal.list.forEach(function (m, i, list) {
122
+ list[i] = analyzeMetalAttr(m);
76
123
  });
77
- return metal;
124
+ return metal.list;
78
125
  }
79
126
  catch (error) {
80
- return {
81
- list: []
82
- };
127
+ return [];
83
128
  }
84
129
  }
85
130
  exports.toMetal = toMetal;
86
- const isBrowse = typeof window !== 'undefined';
131
+ var isBrowse = typeof window !== 'undefined';
87
132
  exports.isBrowse = isBrowse;
package/package.json CHANGED
@@ -1,48 +1,48 @@
1
- {
2
- "name": "fishpi",
3
- "version": "0.0.3",
4
- "description": "A Package to use API of fishpi.",
5
- "main": "./lib/src/index.js",
6
- "files": [
7
- "lib/**/*"
8
- ],
9
- "scripts": {
10
- "prebuild": "rm -rf lib",
11
- "build": "tsc"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/imlinhanchao/fishpi-api-package.git"
16
- },
17
- "license": "MIT",
18
- "author": {
19
- "name": "Hancel.Lin",
20
- "email": "imlinhanchao@foxmail.com",
21
- "url": "https://github.com/imlinhanchao"
22
- },
23
- "engines": {
24
- "node": ">=12.0"
25
- },
26
- "keywords": [],
27
- "bugs": {
28
- "url": "https://github.com/imlinhanchao/fishpi-api-package/issues"
29
- },
30
- "homepage": "https://github.com/imlinhanchao/fishpi-api-package#readme",
31
- "dependencies": {
32
- "axios": "^0.25.0",
33
- "form-data": "^4.0.0",
34
- "reconnecting-websocket": "^4.4.0",
35
- "ws": "^8.4.2"
36
- },
37
- "devDependencies": {
38
- "@types/node": "^12.20.11",
39
- "@types/ws": "^8.2.2",
40
- "ts-node": "^10.2.1",
41
- "typescript": "^4.2.4"
42
- },
43
- "release": {
44
- "branches": [
45
- "master"
46
- ]
47
- }
48
- }
1
+ {
2
+ "name": "fishpi",
3
+ "version": "0.0.7",
4
+ "description": "A Package to use API of fishpi.",
5
+ "main": "./lib/src/index.js",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "scripts": {
10
+ "prebuild": "rm -rf lib",
11
+ "build": "tsc"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/imlinhanchao/fishpi-api-package.git"
16
+ },
17
+ "license": "MIT",
18
+ "author": {
19
+ "name": "Hancel.Lin",
20
+ "email": "imlinhanchao@foxmail.com",
21
+ "url": "https://github.com/imlinhanchao"
22
+ },
23
+ "engines": {
24
+ "node": ">=12.0"
25
+ },
26
+ "keywords": [],
27
+ "bugs": {
28
+ "url": "https://github.com/imlinhanchao/fishpi-api-package/issues"
29
+ },
30
+ "homepage": "https://github.com/imlinhanchao/fishpi-api-package#readme",
31
+ "dependencies": {
32
+ "axios": "^0.25.0",
33
+ "form-data": "^4.0.0",
34
+ "reconnecting-websocket": "^4.4.0",
35
+ "ws": "^8.4.2"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^12.20.11",
39
+ "@types/ws": "^8.2.2",
40
+ "ts-node": "^10.2.1",
41
+ "typescript": "^4.2.4"
42
+ },
43
+ "release": {
44
+ "branches": [
45
+ "master"
46
+ ]
47
+ }
48
+ }
@@ -1 +0,0 @@
1
- export {};
package/lib/test/index.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const src_1 = __importDefault(require("../src"));
16
- function test(account) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- let fish = new src_1.default();
19
- console.dir(yield fish.login(account));
20
- console.dir(yield fish.info());
21
- fish.chatroom.addListener((ev) => console.dir(ev));
22
- });
23
- }
24
- test({
25
- username: '',
26
- passwd: ''
27
- });