七牛云直播相关接口修正

This commit is contained in:
lxy 2025-07-11 16:51:38 +08:00
parent dde0a82476
commit a71d5d339f
5 changed files with 398 additions and 35 deletions

View File

@ -29,7 +29,7 @@ export declare class QiniuCloudInstance {
*/
getLiveToken(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, host: string, rawQuery?: string, contentType?: string, bodyStr?: string): string;
/**
* todo()
*
* @param hub
* @param streamTitle
* @param host
@ -118,6 +118,28 @@ export declare class QiniuCloudInstance {
expireAt: number;
};
getPlayBackUrl(hub: string, playBackDomain: string, streamTitle: string, start: number, end: number, method: 'GET' | 'POST' | 'PUT' | 'DELETE', host: string, rawQuery?: string): Promise<string>;
/**
*
* @param hub
* @param streamTitle
* @param host
* @param disabledTill
* @param disablePeriodSecond
*/
disabledStream(hub: string, streamTitle: string, host: string, disabledTill: number, //禁播结束时间 -1永久禁播0解除禁播
disablePeriodSecond?: number): Promise<void>;
/**
*
* @param hub
* @param host
* @param liveOnly
* @param prefix
* @param limit
* @param marker
* @returns
*/
getLiveStreamList(hub: string, host: string, liveOnly?: boolean, prefix?: string, limit?: number, //取值范围0~5000
marker?: string): Promise<any>;
/**
* 访
* @param path

View File

@ -167,7 +167,7 @@ export class QiniuCloudInstance {
return toke;
}
/**
* 创建直播流 todo(调用七牛云接口不成功)
* 创建直播流
* @param hub
* @param streamTitle
* @param host
@ -192,17 +192,30 @@ export class QiniuCloudInstance {
key,
});
const contentType = 'application/json';
const token = this.getLiveToken('POST', path, host, '', '', bodyStr);
const token = this.getLiveToken('POST', path, host, undefined, contentType, bodyStr);
const url = `https://pili.qiniuapi.com/v2/hubs/${hub}/streams`;
await global.fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
// mode: 'no-cors',
});
let response;
try {
response = await global.fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
// mode: 'no-cors',
});
}
catch (err) {
throw new OakNetworkException();
}
if (response.status !== 200) {
const json = await response.json();
const { error } = json;
throw new OakExternalException('qiniu', response.status.toString(), error, {
status: response.status,
});
}
const obj = this.getStreamObj(hub, streamTitle, expireAt, publishDomain, playDomainType, playDomain, publishSecurity, publishKey, playKey);
return obj;
}
@ -378,6 +391,91 @@ export class QiniuCloudInstance {
});
return `https://${playBackDomain}/${streamTitle}.m3u8`;
}
/**
* 禁用直播流
* @param hub
* @param streamTitle
* @param host
* @param disabledTill
* @param disablePeriodSecond
*/
async disabledStream(hub, streamTitle, host, disabledTill, //禁播结束时间 -1永久禁播0解除禁播
disablePeriodSecond) {
const encodedStreamTitle = this.urlSafeBase64Encode(streamTitle);
const path = `/v2/hubs/${hub}/streams/${encodedStreamTitle}/disabled`;
const bodyStr = JSON.stringify({
disabledTill,
disablePeriodSecond,
});
const contentType = 'application/json';
const token = this.getLiveToken('POST', path, host, undefined, contentType, bodyStr);
const url = `https://pili.qiniuapi.com${path}`;
let response;
try {
response = await global.fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
});
}
catch (err) {
throw new OakNetworkException();
}
if (response.status !== 200) {
const json = await response.json();
const { error } = json;
throw new OakExternalException('qiniu', response.status.toString(), error, {
status: response.status,
});
}
}
/**
* 查询直播流列表
* @param hub
* @param host
* @param liveOnly
* @param prefix
* @param limit
* @param marker
* @returns 直播流名称
*/
async getLiveStreamList(hub, host, liveOnly, prefix, limit, //取值范围0~5000
marker) {
const path = `/v2/hubs/${hub}/streams`;
const url = new URL(`https://${host}${path}`);
if (liveOnly) {
url.searchParams.set('liveOnly', 'true');
}
if (prefix && prefix !== '') {
url.searchParams.set('prefix', prefix);
}
if (limit) {
url.searchParams.set('limit', limit.toString());
}
if (marker && marker !== '') {
url.searchParams.set('prefix', marker);
}
const contentType = 'application/x-www-form-urlencoded';
const token = this.getLiveToken('GET', path, host, undefined, contentType);
let response;
try {
response = await fetch(url.toString(), {
method: 'GET',
headers: {
Authorization: token,
'Content-Type': contentType,
},
});
}
catch (err) {
throw new OakNetworkException();
}
const json = await response.json();
return json.items.map((ele) => ele.key);
}
/**
* 管理端访问七牛云服务器
* @param path

View File

@ -29,7 +29,7 @@ export declare class QiniuCloudInstance {
*/
getLiveToken(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, host: string, rawQuery?: string, contentType?: string, bodyStr?: string): string;
/**
* todo()
*
* @param hub
* @param streamTitle
* @param host
@ -118,6 +118,28 @@ export declare class QiniuCloudInstance {
expireAt: number;
};
getPlayBackUrl(hub: string, playBackDomain: string, streamTitle: string, start: number, end: number, method: 'GET' | 'POST' | 'PUT' | 'DELETE', host: string, rawQuery?: string): Promise<string>;
/**
*
* @param hub
* @param streamTitle
* @param host
* @param disabledTill
* @param disablePeriodSecond
*/
disabledStream(hub: string, streamTitle: string, host: string, disabledTill: number, //禁播结束时间 -1永久禁播0解除禁播
disablePeriodSecond?: number): Promise<void>;
/**
*
* @param hub
* @param host
* @param liveOnly
* @param prefix
* @param limit
* @param marker
* @returns
*/
getLiveStreamList(hub: string, host: string, liveOnly?: boolean, prefix?: string, limit?: number, //取值范围0~5000
marker?: string): Promise<any>;
/**
* 访
* @param path

View File

@ -171,7 +171,7 @@ class QiniuCloudInstance {
return toke;
}
/**
* 创建直播流 todo(调用七牛云接口不成功)
* 创建直播流
* @param hub
* @param streamTitle
* @param host
@ -196,17 +196,30 @@ class QiniuCloudInstance {
key,
});
const contentType = 'application/json';
const token = this.getLiveToken('POST', path, host, '', '', bodyStr);
const token = this.getLiveToken('POST', path, host, undefined, contentType, bodyStr);
const url = `https://pili.qiniuapi.com/v2/hubs/${hub}/streams`;
await global.fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
// mode: 'no-cors',
});
let response;
try {
response = await global.fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
// mode: 'no-cors',
});
}
catch (err) {
throw new Exception_1.OakNetworkException();
}
if (response.status !== 200) {
const json = await response.json();
const { error } = json;
throw new Exception_1.OakExternalException('qiniu', response.status.toString(), error, {
status: response.status,
});
}
const obj = this.getStreamObj(hub, streamTitle, expireAt, publishDomain, playDomainType, playDomain, publishSecurity, publishKey, playKey);
return obj;
}
@ -382,6 +395,91 @@ class QiniuCloudInstance {
});
return `https://${playBackDomain}/${streamTitle}.m3u8`;
}
/**
* 禁用直播流
* @param hub
* @param streamTitle
* @param host
* @param disabledTill
* @param disablePeriodSecond
*/
async disabledStream(hub, streamTitle, host, disabledTill, //禁播结束时间 -1永久禁播0解除禁播
disablePeriodSecond) {
const encodedStreamTitle = this.urlSafeBase64Encode(streamTitle);
const path = `/v2/hubs/${hub}/streams/${encodedStreamTitle}/disabled`;
const bodyStr = JSON.stringify({
disabledTill,
disablePeriodSecond,
});
const contentType = 'application/json';
const token = this.getLiveToken('POST', path, host, undefined, contentType, bodyStr);
const url = `https://pili.qiniuapi.com${path}`;
let response;
try {
response = await global.fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
});
}
catch (err) {
throw new Exception_1.OakNetworkException();
}
if (response.status !== 200) {
const json = await response.json();
const { error } = json;
throw new Exception_1.OakExternalException('qiniu', response.status.toString(), error, {
status: response.status,
});
}
}
/**
* 查询直播流列表
* @param hub
* @param host
* @param liveOnly
* @param prefix
* @param limit
* @param marker
* @returns 直播流名称
*/
async getLiveStreamList(hub, host, liveOnly, prefix, limit, //取值范围0~5000
marker) {
const path = `/v2/hubs/${hub}/streams`;
const url = new url_1.url(`https://${host}${path}`);
if (liveOnly) {
url.searchParams.set('liveOnly', 'true');
}
if (prefix && prefix !== '') {
url.searchParams.set('prefix', prefix);
}
if (limit) {
url.searchParams.set('limit', limit.toString());
}
if (marker && marker !== '') {
url.searchParams.set('prefix', marker);
}
const contentType = 'application/x-www-form-urlencoded';
const token = this.getLiveToken('GET', path, host, undefined, contentType);
let response;
try {
response = await fetch(url.toString(), {
method: 'GET',
headers: {
Authorization: token,
'Content-Type': contentType,
},
});
}
catch (err) {
throw new Exception_1.OakNetworkException();
}
const json = await response.json();
return json.items.map((ele) => ele.key);
}
/**
* 管理端访问七牛云服务器
* @param path

View File

@ -190,7 +190,7 @@ export class QiniuCloudInstance {
}
/**
* todo()
*
* @param hub
* @param streamTitle
* @param host
@ -226,18 +226,31 @@ export class QiniuCloudInstance {
key,
});
const contentType = 'application/json';
const token = this.getLiveToken('POST', path, host, '', '', bodyStr);
const token = this.getLiveToken('POST', path, host, undefined, contentType, bodyStr);
const url = `https://pili.qiniuapi.com/v2/hubs/${hub}/streams`;
await global.fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
// mode: 'no-cors',
});
let response: Response;
try {
response = await global.fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
// mode: 'no-cors',
});
}
catch (err) {
throw new OakNetworkException();
}
if (response.status !== 200) {
const json = await response.json();
const { error } = json;
throw new OakExternalException('qiniu', response.status.toString(), error, {
status: response.status,
});
}
const obj = this.getStreamObj(
hub,
streamTitle,
@ -557,6 +570,116 @@ export class QiniuCloudInstance {
return `https://${playBackDomain}/${streamTitle}.m3u8`;
}
/**
*
* @param hub
* @param streamTitle
* @param host
* @param disabledTill
* @param disablePeriodSecond
*/
async disabledStream(
hub: string,
streamTitle: string,
host: string,
disabledTill: number, //禁播结束时间 -1永久禁播0解除禁播
disablePeriodSecond?: number, //禁播时长当disabledTill为0时生效
) {
const encodedStreamTitle = this.urlSafeBase64Encode(streamTitle);
const path = `/v2/hubs/${hub}/streams/${encodedStreamTitle}/disabled`;
const bodyStr = JSON.stringify({
disabledTill,
disablePeriodSecond,
});
const contentType = 'application/json';
const token = this.getLiveToken(
'POST',
path,
host,
undefined,
contentType,
bodyStr
);
const url = `https://pili.qiniuapi.com${path}`;
let response: Response;
try {
response = await global.fetch(url, {
method: 'POST',
headers: {
Authorization: token,
'Content-Type': contentType,
},
body: bodyStr,
});
} catch (err) {
throw new OakNetworkException();
}
if (response.status !== 200) {
const json = await response.json();
const { error } = json;
throw new OakExternalException('qiniu', response.status.toString(), error, {
status: response.status,
});
}
}
/**
*
* @param hub
* @param host
* @param liveOnly
* @param prefix
* @param limit
* @param marker
* @returns
*/
async getLiveStreamList(
hub: string,
host: string,
liveOnly?: boolean,
prefix?: string,
limit?: number, //取值范围0~5000
marker?: string,
) {
const path = `/v2/hubs/${hub}/streams`;
const url = new URL(`https://${host}${path}`);
if (liveOnly) {
url.searchParams.set('liveOnly', 'true');
}
if (prefix && prefix !== '') {
url.searchParams.set('prefix', prefix);
}
if (limit) {
url.searchParams.set('limit', limit.toString());
}
if (marker && marker !== '') {
url.searchParams.set('prefix', marker);
}
const contentType = 'application/x-www-form-urlencoded';
const token = this.getLiveToken(
'GET',
path,
host,
undefined,
contentType
);
let response: Response;
try {
response = await fetch(url.toString(), {
method: 'GET',
headers: {
Authorization: token,
'Content-Type': contentType,
},
});
} catch (err) {
throw new OakNetworkException();
}
const json = await response.json();
return json.items.map((ele: any) => ele.key);
}
/**
* 访
* @param path