Comparing version 0.0.1 to 0.0.2
@@ -1,2 +0,2 @@ | ||
import { ApiResponse, ChatRoomMessage, RedPacket } from '..'; | ||
import { ApiResponse, ChatRoomMessage, RedPacket } from './typing'; | ||
declare class ChatRoom { | ||
@@ -80,4 +80,4 @@ private _apiKey; | ||
*/ | ||
addListener(wsCallback: Function): void; | ||
addListener(wsCallback: Function): Promise<void>; | ||
} | ||
export default ChatRoom; |
@@ -286,66 +286,68 @@ "use strict"; | ||
addListener(wsCallback) { | ||
if (this._rws !== null) { | ||
if (this._wsCallbacks.indexOf(wsCallback) < 0) | ||
this._wsCallbacks.push(wsCallback); | ||
return; | ||
} | ||
this._wsCallbacks.push(wsCallback); | ||
this._rws = new reconnecting_websocket_1.default(`wss://${utils_1.domain}chat-room-channel?apiKey=${this._apiKey}`, [], { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
WebSocket: window ? window.WebSocket : Promise.resolve().then(() => __importStar(require('ws'))), | ||
connectionTimeout: 10000 | ||
}); | ||
this._rws.onopen = (e) => { | ||
if (this._wsTimer) { | ||
clearInterval(this._wsTimer); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this._rws !== null) { | ||
if (this._wsCallbacks.indexOf(wsCallback) < 0) | ||
this._wsCallbacks.push(wsCallback); | ||
return; | ||
} | ||
this._wsTimer = setInterval(() => { | ||
var _a; | ||
(_a = this._rws) === null || _a === void 0 ? void 0 : _a.send('-hb-'); | ||
}, 1000 * 60 * 3); | ||
}; | ||
this._rws.onmessage = (e) => __awaiter(this, void 0, void 0, function* () { | ||
let msg = JSON.parse(e.data); | ||
let data = null; | ||
switch (msg.type) { | ||
case 'online': { | ||
data = this._onlines = msg.users; | ||
break; | ||
this._wsCallbacks.push(wsCallback); | ||
this._rws = new reconnecting_websocket_1.default(`wss://${utils_1.domain}chat-room-channel?apiKey=${this._apiKey}`, [], { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
WebSocket: utils_1.isBrowse ? window.WebSocket : (yield Promise.resolve().then(() => __importStar(require('ws')))).WebSocket, | ||
connectionTimeout: 10000 | ||
}); | ||
this._rws.onopen = (e) => { | ||
if (this._wsTimer) { | ||
clearInterval(this._wsTimer); | ||
} | ||
case 'revoke': { | ||
data = msg.oId; | ||
break; | ||
} | ||
case 'msg': { | ||
let { oId, time, userName, userNickname, userAvatarURL, content, md } = msg; | ||
try { | ||
let { msg, recivers, money, count, type, got, who, msgType } = JSON.parse(content); | ||
if (msgType === 'redPacket') { | ||
data = { | ||
oId, time, userName, userNickname, userAvatarURL, | ||
redpacket: { msg, recivers, money, count, type, got, who } | ||
}; | ||
msg.type = 'redPacket'; | ||
break; | ||
this._wsTimer = setInterval(() => { | ||
var _a; | ||
(_a = this._rws) === null || _a === void 0 ? void 0 : _a.send('-hb-'); | ||
}, 1000 * 60 * 3); | ||
}; | ||
this._rws.onmessage = (e) => __awaiter(this, void 0, void 0, function* () { | ||
let msg = JSON.parse(e.data); | ||
let data = null; | ||
switch (msg.type) { | ||
case 'online': { | ||
data = this._onlines = msg.users; | ||
break; | ||
} | ||
case 'revoke': { | ||
data = msg.oId; | ||
break; | ||
} | ||
case 'msg': { | ||
let { oId, time, userName, userNickname, userAvatarURL, content, md } = msg; | ||
try { | ||
let { msg, recivers, money, count, type, got, who, msgType } = JSON.parse(content); | ||
if (msgType === 'redPacket') { | ||
data = { | ||
oId, time, userName, userNickname, userAvatarURL, | ||
redpacket: { msg, recivers, money, count, type, got, who } | ||
}; | ||
msg.type = 'redPacket'; | ||
break; | ||
} | ||
} | ||
catch (e) { } | ||
data = { oId, time, userName, userNickname, userAvatarURL, content, md }; | ||
break; | ||
} | ||
catch (e) { } | ||
data = { oId, time, userName, userNickname, userAvatarURL, content, md }; | ||
break; | ||
case 'redPacketStatus': { | ||
let { oId, count, got, whoGive, whoGot } = msg; | ||
data = { oId, count, got, whoGive, whoGot }; | ||
break; | ||
} | ||
} | ||
case 'redPacketStatus': { | ||
let { oId, count, got, whoGive, whoGot } = msg; | ||
data = { oId, count, got, whoGive, whoGot }; | ||
break; | ||
} | ||
} | ||
this._wsCallbacks.forEach(call => call(Object.assign({ msg: { type: msg.type, data } }, e))); | ||
this._wsCallbacks.forEach(call => call(Object.assign({ msg: { type: msg.type, data } }, e))); | ||
}); | ||
this._rws.onerror = (e) => { | ||
console.error(e); | ||
}; | ||
this._rws.onclose = (e) => { | ||
}; | ||
}); | ||
this._rws.onerror = (e) => { | ||
console.error(e); | ||
}; | ||
this._rws.onclose = (e) => { | ||
}; | ||
} | ||
} | ||
exports.default = ChatRoom; |
@@ -1,2 +0,2 @@ | ||
import { ApiResponse, Account, UserInfo, AtUserList, UploadInfo } from '..'; | ||
import { ApiResponse, Account, UserInfo, AtUserList, UploadInfo } from './typing'; | ||
import ChatRoom from './chatroom'; | ||
@@ -3,0 +3,0 @@ import Notice from './notice'; |
@@ -103,3 +103,4 @@ "use strict"; | ||
} | ||
rsp.data.data.sysMetal = (0, utils_1.toMetal)(rsp.data.data.sysMetal); | ||
if (rsp.data.data) | ||
rsp.data.data.sysMetal = (0, utils_1.toMetal)(rsp.data.data.sysMetal); | ||
return rsp.data; | ||
@@ -271,3 +272,3 @@ } | ||
let data; | ||
if (window) { | ||
if (utils_1.isBrowse) { | ||
data = new FormData(); | ||
@@ -287,5 +288,5 @@ files.forEach(f => data.append('file[]', f)); | ||
data, | ||
headers: data.getHeaders() | ||
headers: utils_1.isBrowse ? undefined : data.getHeaders() | ||
}); | ||
return rsp.data.data; | ||
return rsp.data; | ||
} | ||
@@ -292,0 +293,0 @@ catch (e) { |
@@ -1,2 +0,2 @@ | ||
import { ApiResponse, NoticeCount, NoticeList } from '..'; | ||
import { ApiResponse, NoticeCount, NoticeList } from './typing'; | ||
declare class Notice { | ||
@@ -3,0 +3,0 @@ private _apiKey; |
@@ -1,5 +0,6 @@ | ||
import { Metal } from '..'; | ||
import { Metal } from './typing'; | ||
declare const domain = "fishpi.cn/"; | ||
declare function request(opt: any): Promise<any>; | ||
declare function toMetal(sysMetal: string): Metal; | ||
export { request, domain, toMetal, }; | ||
declare const isBrowse: boolean; | ||
export { request, domain, toMetal, isBrowse }; |
@@ -34,3 +34,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toMetal = exports.domain = exports.request = void 0; | ||
exports.isBrowse = exports.toMetal = exports.domain = exports.request = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
@@ -43,4 +43,6 @@ const https = __importStar(require("https")); | ||
let { url, method = 'get', headers = {}, data } = opt; | ||
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`; | ||
headers['Referer'] = `https://${domain}`; | ||
if (!isBrowse) { | ||
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`; | ||
headers['Referer'] = `https://${domain}`; | ||
} | ||
let options = { | ||
@@ -86,1 +88,3 @@ method, headers, | ||
exports.toMetal = toMetal; | ||
const isBrowse = typeof window !== 'undefined'; | ||
exports.isBrowse = isBrowse; |
{ | ||
"name": "fishpi", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A Package to use API of fishpi.", | ||
@@ -10,2 +10,3 @@ "main": "./lib/src/index.js", | ||
"scripts": { | ||
"prebuild": "rm -rf lib", | ||
"build": "tsc" | ||
@@ -12,0 +13,0 @@ }, |
# 摸鱼派 API Package | ||
摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。 | ||
## 支援 | ||
- 用户信息; | ||
- 聊天室; | ||
- 文件上传; | ||
- 通知信息; | ||
## 功能 | ||
## 安装 | ||
@@ -18,2 +21,33 @@ | ||
// 登录获取 apiKey | ||
let apiKey = ''; | ||
let fish = new FishPi(); | ||
let rsp = await fish.login({ | ||
username: 'username', | ||
passwd: 'password123456' | ||
}); | ||
if (rsp.code == 0) apiKey = rsp.Key; | ||
// 通过 apiKey 获取登录用户信息 | ||
let fish = new FishPi(apiKey); | ||
console.dir(await fish.info()); | ||
// 获取用户自定义表情包 | ||
let emojis = fish.emoji.get(); | ||
// 获取默认表情包 | ||
let defaultEmoji = fish.emoji.default; | ||
// 监听聊天室消息 | ||
fish.chatroom.addListener((ev:any) => console.dir(ev)); | ||
// 向聊天室发送信息(需要登录) | ||
fish.chatroom.send('Hello World!'); | ||
// 向聊天室发送红包 | ||
fish.chatroom.redpacket.send({ | ||
type: 'random'; | ||
money: 32; | ||
count: 2; | ||
msg: '摸鱼者,事竟成!'; | ||
recivers: []; | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53
1
1
39846
13
1051