UNPKG

chzzk

Version:

네이버 라이브 스트리밍 서비스 CHZZK의 비공식 API 라이브러리

186 lines (185 loc) 8.79 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChzzkManage = void 0; const DEFAULT_SUBSCRIBER_SEARCH_OPTIONS = { page: 0, size: 50, sortType: "RECENT" }; const DEFAULT_FOLLOWER_SEARCH_OPTIONS = { page: 0, size: 50 }; const DEFAULT_MANAGE_VIDEO_SEARCH_OPTIONS = { videoType: "REPLAY", page: 0, size: 50 }; class ChzzkManage { constructor(client) { this.client = client; } temporaryRestrict(channelId, targetId) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/temporary-restrict-users`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ targetId }) }).then(r => r.json()).then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }).catch(() => null); }); } restrict(channelId, targetId) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/restrict-users`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ targetId }) }).then(r => r.json()).then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }).catch(() => null); }); } removeRestrict(channelId, targetId) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/restrict-users/${targetId}`, { method: "DELETE" }); }); } chatActivityCount(channelId, targetId) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/users/${targetId}/chat-activity-count`) .then(r => r.json()).then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }).catch(() => null); }); } setRole(channelId, targetId, userRoleType) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/streaming-roles`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ targetId, userRoleType }) }).then(r => r.json()).then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }).catch(() => null); }); } removeRole(channelId, targetId) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/streaming-roles/${targetId}`, { method: "DELETE" }); }); } setting(channelId, params) { return __awaiter(this, void 0, void 0, function* () { const options = params ? { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(params) } : null; return this.client.fetch(`/manage/v1/channels/${channelId}/live-setting`, options) .then(r => r.json()) .then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }); }); } chatRule(channelId) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/chat-rules`) .then(r => r.json()) .then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }); }); } setChatRule(channelId, rule) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/chat-rules`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ rule }) }); }); } prohibitWords(channelId) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/prohibit-words`) .then(r => r.json()) .then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }) .then(content => content['prohibitWords']) .catch(() => null); }); } addProhibitWord(channelId, word) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/prohibit-words`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ word }) }); }); } stream(channelId) { return __awaiter(this, void 0, void 0, function* () { return this.client.fetch(`/manage/v1/channels/${channelId}/streams`) .then(r => r.json()) .then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }) .catch(() => null); }); } subscribers(channelId, options) { return __awaiter(this, void 0, void 0, function* () { options = Object.assign(Object.assign({}, DEFAULT_SUBSCRIBER_SEARCH_OPTIONS), options); const params = new URLSearchParams({ page: options.page.toString(), size: options.size.toString(), sortType: options.sortType }); if (options === null || options === void 0 ? void 0 : options.publishPeriod) { params.set("publishPeriod", options.publishPeriod.toString()); } if (options === null || options === void 0 ? void 0 : options.tier) { params.set("tier", options.tier); } if (options === null || options === void 0 ? void 0 : options.userNickname) { params.set("userNickname", options.userNickname); } return this.client.fetch(`/manage/v1/channels/${channelId}/subscribers?${params.toString()}`) .then(r => r.json()) .then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }) .catch(() => null); }); } followers(channelId, options) { var _a; return __awaiter(this, void 0, void 0, function* () { options = Object.assign(Object.assign({}, DEFAULT_FOLLOWER_SEARCH_OPTIONS), options); const params = new URLSearchParams({ page: options.page.toString(), size: options.size.toString(), userNickname: (_a = options.userNickname) !== null && _a !== void 0 ? _a : "" }); return this.client.fetch(`/manage/v1/channels/${channelId}/followers?${params.toString()}`) .then(r => r.json()) .then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }) .catch(() => null); }); } videos(channelId, options) { return __awaiter(this, void 0, void 0, function* () { options = Object.assign(Object.assign({}, DEFAULT_MANAGE_VIDEO_SEARCH_OPTIONS), options); const params = new URLSearchParams({ page: options.page.toString(), size: options.size.toString(), videoType: options.videoType }); return this.client.fetch(`/manage/v1/channels/${channelId}/videos?${params.toString()}`) .then(r => r.json()) .then(data => { var _a; return (_a = data['content']) !== null && _a !== void 0 ? _a : null; }) .catch(() => null); }); } } exports.ChzzkManage = ChzzkManage;