fishpi 0.0.1

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.
@@ -0,0 +1,33 @@
1
+ import { ApiResponse, NoticeCount, NoticeList } from '..';
2
+ declare class Notice {
3
+ private _apiKey;
4
+ constructor(token?: string);
5
+ /**
6
+ * 重新设置请求 Token
7
+ * @param apiKey 接口 API Key
8
+ */
9
+ setToken(token: string): void;
10
+ /**
11
+ * 获取未读消息数
12
+ */
13
+ count(): Promise<NoticeCount>;
14
+ /**
15
+ * 获取消息列表
16
+ * @param type 消息类型
17
+ */
18
+ list(type: string): Promise<ApiResponse<NoticeList>>;
19
+ /**
20
+ * 已读指定类型消息
21
+ * @param type 消息类型
22
+ */
23
+ makeRead(type: string): Promise<{
24
+ code: number;
25
+ }>;
26
+ /**
27
+ * 已读所有消息
28
+ */
29
+ readAll(): Promise<{
30
+ code: number;
31
+ }>;
32
+ }
33
+ export default Notice;
@@ -0,0 +1,100 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const utils_1 = require("./utils");
13
+ class Notice {
14
+ constructor(token = '') {
15
+ this._apiKey = '';
16
+ if (!token) {
17
+ return;
18
+ }
19
+ this._apiKey = token;
20
+ }
21
+ /**
22
+ * 重新设置请求 Token
23
+ * @param apiKey 接口 API Key
24
+ */
25
+ setToken(token) {
26
+ this._apiKey = token;
27
+ }
28
+ /**
29
+ * 获取未读消息数
30
+ */
31
+ count() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ let rsp;
34
+ try {
35
+ rsp = yield (0, utils_1.request)({
36
+ url: `notifications/unread/count?apiKey=${this._apiKey}`,
37
+ });
38
+ rsp.data.userNotifyStatus = rsp.data.userNotifyStatus != 0;
39
+ return rsp.data;
40
+ }
41
+ catch (e) {
42
+ throw e;
43
+ }
44
+ });
45
+ }
46
+ /**
47
+ * 获取消息列表
48
+ * @param type 消息类型
49
+ */
50
+ list(type) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ let rsp;
53
+ try {
54
+ rsp = yield (0, utils_1.request)({
55
+ url: `api/getNotifications?apiKey=${this._apiKey}&type=${type}`,
56
+ });
57
+ return rsp.data;
58
+ }
59
+ catch (e) {
60
+ throw e;
61
+ }
62
+ });
63
+ }
64
+ /**
65
+ * 已读指定类型消息
66
+ * @param type 消息类型
67
+ */
68
+ makeRead(type) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ let rsp;
71
+ try {
72
+ rsp = yield (0, utils_1.request)({
73
+ url: `notifications/make-read/${type}?apiKey=${this._apiKey}`,
74
+ });
75
+ return rsp.data;
76
+ }
77
+ catch (e) {
78
+ throw e;
79
+ }
80
+ });
81
+ }
82
+ /**
83
+ * 已读所有消息
84
+ */
85
+ readAll() {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ let rsp;
88
+ try {
89
+ rsp = yield (0, utils_1.request)({
90
+ url: `notifications/all-read?apiKey=${this._apiKey}`,
91
+ });
92
+ return rsp.data;
93
+ }
94
+ catch (e) {
95
+ throw e;
96
+ }
97
+ });
98
+ }
99
+ }
100
+ exports.default = Notice;
@@ -0,0 +1,5 @@
1
+ import { Metal } from '..';
2
+ declare const domain = "fishpi.cn/";
3
+ declare function request(opt: any): Promise<any>;
4
+ declare function toMetal(sysMetal: string): Metal;
5
+ export { request, domain, toMetal, };
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ 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/';
38
+ exports.domain = domain;
39
+ function request(opt) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ let { url, method = 'get', headers = {}, data } = opt;
42
+ 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`;
43
+ headers['Referer'] = `https://${domain}`;
44
+ let options = {
45
+ method, headers,
46
+ httpsAgent: new https.Agent({
47
+ keepAlive: true,
48
+ rejectUnauthorized: false,
49
+ }),
50
+ data
51
+ };
52
+ let rsp;
53
+ try {
54
+ rsp = yield (0, axios_1.default)(`https://${domain}${url}`, options);
55
+ return rsp;
56
+ }
57
+ catch (err) {
58
+ if (err.response.status === 401) {
59
+ return err.response;
60
+ }
61
+ throw (err);
62
+ }
63
+ });
64
+ }
65
+ exports.request = request;
66
+ function toMetal(sysMetal) {
67
+ try {
68
+ let metal = JSON.parse(sysMetal);
69
+ metal.list.forEach((m, i, list) => {
70
+ let attr = m.attr.split('&');
71
+ m.attr = {};
72
+ attr.forEach((a) => m.attr[a.split('=')[0]] = a.split('=')[1]);
73
+ list[i] = m;
74
+ });
75
+ return metal;
76
+ }
77
+ catch (error) {
78
+ return {
79
+ list: []
80
+ };
81
+ }
82
+ }
83
+ exports.toMetal = toMetal;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
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
+ });
package/lib/utils.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const domain = "fishpi.cn/";
2
+ declare function request(opt: any): Promise<any>;
3
+ export { request, domain };
package/lib/utils.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
+ return new (P || (P = Promise))(function (resolve, reject) {
24
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
28
+ });
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.domain = exports.request = void 0;
35
+ const axios_1 = __importDefault(require("axios"));
36
+ const https = __importStar(require("https"));
37
+ const domain = 'fishpi.cn/';
38
+ exports.domain = domain;
39
+ function request(opt) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ let { url, method = 'get', headers = {}, data } = opt;
42
+ 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`;
43
+ headers['Referer'] = `https://${domain}`;
44
+ let options = {
45
+ method, headers,
46
+ httpsAgent: new https.Agent({
47
+ keepAlive: true,
48
+ rejectUnauthorized: false,
49
+ }),
50
+ data
51
+ };
52
+ let rsp;
53
+ try {
54
+ rsp = yield (0, axios_1.default)(`https://${domain}${url}`, options);
55
+ return rsp;
56
+ }
57
+ catch (err) {
58
+ if (err.response.status === 401) {
59
+ return err.response;
60
+ }
61
+ throw (err);
62
+ }
63
+ });
64
+ }
65
+ exports.request = request;
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "fishpi",
3
+ "version": "0.0.1",
4
+ "description": "A Package to use API of fishpi.",
5
+ "main": "./lib/src/index.js",
6
+ "files": [
7
+ "lib/**/*"
8
+ ],
9
+ "scripts": {
10
+ "build": "tsc"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/imlinhanchao/fishpi-api-package.git"
15
+ },
16
+ "license": "MIT",
17
+ "author": {
18
+ "name": "Hancel.Lin",
19
+ "email": "imlinhanchao@foxmail.com",
20
+ "url": "https://github.com/imlinhanchao"
21
+ },
22
+ "engines": {
23
+ "node": ">=12.0"
24
+ },
25
+ "keywords": [],
26
+ "bugs": {
27
+ "url": "https://github.com/imlinhanchao/fishpi-api-package/issues"
28
+ },
29
+ "homepage": "https://github.com/imlinhanchao/fishpi-api-package#readme",
30
+ "dependencies": {
31
+ "axios": "^0.25.0",
32
+ "form-data": "^4.0.0",
33
+ "reconnecting-websocket": "^4.4.0",
34
+ "ws": "^8.4.2"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^12.20.11",
38
+ "@types/ws": "^8.2.2",
39
+ "ts-node": "^10.2.1",
40
+ "typescript": "^4.2.4"
41
+ },
42
+ "release": {
43
+ "branches": [
44
+ "master"
45
+ ]
46
+ }
47
+ }