mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-08-12 17:10:37 +00:00
feat: add event privacy endpoint
This commit is contained in:
parent
63d89aa906
commit
eb1b5ba0ea
14
interface.d.ts
vendored
14
interface.d.ts
vendored
@ -626,6 +626,20 @@ export function event_del(
|
|||||||
params: { evId: string | number } & RequestBaseConfig,
|
params: { evId: string | number } & RequestBaseConfig,
|
||||||
): Promise<Response>
|
): Promise<Response>
|
||||||
|
|
||||||
|
export const enum EventPrivacy {
|
||||||
|
everyone = 0,
|
||||||
|
following = 1,
|
||||||
|
onlyMe = 2,
|
||||||
|
mutualFollowing = 6,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function event_privacy(
|
||||||
|
params: {
|
||||||
|
evId: string | number
|
||||||
|
privacy: EventPrivacy
|
||||||
|
} & RequestBaseConfig,
|
||||||
|
): Promise<Response>
|
||||||
|
|
||||||
export function event_forward(
|
export function event_forward(
|
||||||
params: {
|
params: {
|
||||||
forwords: string
|
forwords: string
|
||||||
|
|||||||
34
module/event_privacy.js
Normal file
34
module/event_privacy.js
Normal file
@ -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))
|
||||||
|
}
|
||||||
@ -843,6 +843,18 @@ tags: 歌单标签
|
|||||||
41、21 分享视频
|
41、21 分享视频
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 修改动态可见权限
|
||||||
|
|
||||||
|
说明 : 登录后调用此接口,可以修改当前账号本人发布的单条动态的可见权限。此接口只负责一次原子修改;上游没有批量修改接口,如需批量操作,请由调用方逐条调用并自行处理限速、失败重试和部分成功。
|
||||||
|
|
||||||
|
**必选参数 :** `evId` : 动态 id
|
||||||
|
|
||||||
|
`privacy` : 目标可见权限。`0` 为所有人,`1` 为我关注的人,`2` 为仅自己,`6` 为互相关注的人
|
||||||
|
|
||||||
|
**接口地址 :** `/event/privacy`
|
||||||
|
|
||||||
|
**调用例子 :** `/event/privacy?evId=6712917601&privacy=0`
|
||||||
|
|
||||||
### 转发用户动态
|
### 转发用户动态
|
||||||
|
|
||||||
说明 : 登录后调用此接口 ,可以转发用户动态
|
说明 : 登录后调用此接口 ,可以转发用户动态
|
||||||
|
|||||||
34
test/event_privacy.test.js
Normal file
34
test/event_privacy.test.js
Normal file
@ -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)
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user