From eb1b5ba0eacc17b6990a353ebc1de6b8240c0de9 Mon Sep 17 00:00:00 2001 From: tanjuntao Date: Sat, 1 Aug 2026 10:25:00 +0800 Subject: [PATCH] feat: add event privacy endpoint --- interface.d.ts | 14 ++++++++++++++ module/event_privacy.js | 34 ++++++++++++++++++++++++++++++++++ public/docs/home.md | 12 ++++++++++++ test/event_privacy.test.js | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 module/event_privacy.js create mode 100644 test/event_privacy.test.js diff --git a/interface.d.ts b/interface.d.ts index c260f4f..20b82d0 100644 --- a/interface.d.ts +++ b/interface.d.ts @@ -626,6 +626,20 @@ export function event_del( params: { evId: string | number } & RequestBaseConfig, ): Promise +export const enum EventPrivacy { + everyone = 0, + following = 1, + onlyMe = 2, + mutualFollowing = 6, +} + +export function event_privacy( + params: { + evId: string | number + privacy: EventPrivacy + } & RequestBaseConfig, +): Promise + export function event_forward( params: { forwords: string diff --git a/module/event_privacy.js b/module/event_privacy.js new file mode 100644 index 0000000..c756128 --- /dev/null +++ b/module/event_privacy.js @@ -0,0 +1,34 @@ +// 修改本人动态的可见权限 + +const createOption = require('../util/option.js') + +const PRIVACY_VALUES = new Set([0, 1, 2, 6]) + +module.exports = (query, request) => { + const eventId = String(query.evId ?? '').trim() + const rawPrivacy = String(query.privacy ?? '').trim() + const privacy = Number(rawPrivacy) + + if ( + !eventId || + !rawPrivacy || + !Number.isInteger(privacy) || + !PRIVACY_VALUES.has(privacy) + ) { + return Promise.resolve({ + status: 400, + body: { + code: 400, + message: 'evId is required and privacy must be one of 0, 1, 2, 6', + }, + cookie: [], + }) + } + + const data = { + eventId, + privacy, + } + + return request(`/api/event/privacy/op`, data, createOption(query)) +} diff --git a/public/docs/home.md b/public/docs/home.md index 409ccff..fb2bc75 100644 --- a/public/docs/home.md +++ b/public/docs/home.md @@ -843,6 +843,18 @@ tags: 歌单标签 41、21 分享视频 ``` +### 修改动态可见权限 + +说明 : 登录后调用此接口,可以修改当前账号本人发布的单条动态的可见权限。此接口只负责一次原子修改;上游没有批量修改接口,如需批量操作,请由调用方逐条调用并自行处理限速、失败重试和部分成功。 + +**必选参数 :** `evId` : 动态 id + +`privacy` : 目标可见权限。`0` 为所有人,`1` 为我关注的人,`2` 为仅自己,`6` 为互相关注的人 + +**接口地址 :** `/event/privacy` + +**调用例子 :** `/event/privacy?evId=6712917601&privacy=0` + ### 转发用户动态 说明 : 登录后调用此接口 ,可以转发用户动态 diff --git a/test/event_privacy.test.js b/test/event_privacy.test.js new file mode 100644 index 0000000..3467acd --- /dev/null +++ b/test/event_privacy.test.js @@ -0,0 +1,34 @@ +const assert = require('assert') +const eventPrivacy = require('../module/event_privacy') + +describe('event privacy modules', () => { + it('updates event privacy with the official client parameters', async () => { + let captured + const expected = { status: 200, body: { code: 200 }, cookie: [] } + const result = await eventPrivacy( + { evId: '123456789012345678', privacy: '0', cookie: { MUSIC_U: 'x' } }, + async (uri, data, options) => { + captured = { uri, data, options } + return expected + }, + ) + + assert.strictEqual(result, expected) + assert.strictEqual(captured.uri, '/api/event/privacy/op') + assert.deepStrictEqual(captured.data, { + eventId: '123456789012345678', + privacy: 0, + }) + assert.strictEqual(captured.options.crypto, '') + }) + + it('rejects unknown event privacy values before making a request', async () => { + let requested = false + const result = await eventPrivacy({ evId: '1', privacy: '3' }, async () => { + requested = true + }) + + assert.strictEqual(requested, false) + assert.strictEqual(result.status, 400) + }) +})