完善web一些功能
This commit is contained in:
@@ -1,71 +1,86 @@
|
||||
function get(url){
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
return data;
|
||||
})
|
||||
.catch(error => {
|
||||
return error;
|
||||
});
|
||||
}
|
||||
function post(url,formData,isJSON) {
|
||||
return fetch(url, {
|
||||
method: "POST",
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
if(isJSON){
|
||||
function get(url) {
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
return data;
|
||||
})
|
||||
.catch(error => {
|
||||
return error;
|
||||
});
|
||||
}
|
||||
function post(url, formData, isJSON) {
|
||||
return sendPost(url,true,formData,isJSON)
|
||||
}
|
||||
function sendPost(url, isFormData, formData, isJSON) {
|
||||
var obj = {};
|
||||
if (isFormData) {
|
||||
obj = {
|
||||
method: "POST",
|
||||
body: formData
|
||||
}
|
||||
return response.blob();
|
||||
})
|
||||
.then(blob => {
|
||||
if(isJSON){
|
||||
return blob;
|
||||
} else {
|
||||
obj = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(formData)
|
||||
}
|
||||
const imageUrl = URL.createObjectURL(blob);
|
||||
return imageUrl;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("There was a problem with the fetch operation:", error);
|
||||
throw error; // 重新抛出错误以便外部捕获
|
||||
});
|
||||
}
|
||||
return fetch(url, obj)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
if (isJSON) {
|
||||
return response.json();
|
||||
}
|
||||
return response.blob();
|
||||
})
|
||||
.then(blob => {
|
||||
if (isJSON) {
|
||||
return blob;
|
||||
}
|
||||
const imageUrl = URL.createObjectURL(blob);
|
||||
return imageUrl;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("There was a problem with the fetch operation:", error);
|
||||
throw error; // 重新抛出错误以便外部捕获
|
||||
});
|
||||
}
|
||||
|
||||
function post2blob(url,formData) {
|
||||
function post2blob(url, formData) {
|
||||
return fetch(url, {
|
||||
method: "POST",
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(blob => {
|
||||
return blob;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("There was a problem with the fetch operation:", error);
|
||||
throw error; // 重新抛出错误以便外部捕获
|
||||
});
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(blob => {
|
||||
return blob;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("There was a problem with the fetch operation:", error);
|
||||
throw error; // 重新抛出错误以便外部捕获
|
||||
});
|
||||
}
|
||||
|
||||
function buildFormData(json){
|
||||
function buildFormData(json) {
|
||||
const formData = new FormData();
|
||||
|
||||
Object.keys(json).forEach(key => {
|
||||
const value = json[key];
|
||||
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((item, index) => {
|
||||
formData.append(`${key}[${index}]`, item);
|
||||
@@ -81,101 +96,119 @@ function buildFormData(json){
|
||||
|
||||
//----------------直播配置相关接口
|
||||
function getLiveVideoList() {
|
||||
return get("/live/video/list");
|
||||
return get("/live/video/list");
|
||||
}
|
||||
function getHttpImage(url) {
|
||||
const encode = encodeURI(url);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("url", encode);
|
||||
return post("/file/img",formData,false)
|
||||
.then(blob=>{
|
||||
return blob;
|
||||
})
|
||||
return post("/file/img", formData, false)
|
||||
.then(blob => {
|
||||
return blob;
|
||||
})
|
||||
}
|
||||
function getHttpTmpImage(url) {
|
||||
const encode = encodeURI(url);
|
||||
const formData = new FormData();
|
||||
formData.append("url", encode);
|
||||
return post2blob("/file/imgTmp",formData)
|
||||
.then(blob=>{
|
||||
return blob;
|
||||
})
|
||||
return post2blob("/file/imgTmp", formData)
|
||||
.then(blob => {
|
||||
return blob;
|
||||
})
|
||||
}
|
||||
function addRoomConfig(json){
|
||||
const formData=buildFormData(json)
|
||||
return post("/live/config/set",formData,true)
|
||||
function addRoomConfig(config) {
|
||||
const formData = buildFormData(config)
|
||||
return post("/live/config/set", formData, true)
|
||||
}
|
||||
function getRoomConfig(roomId){
|
||||
return get("/live/config/get?roomId="+roomId)
|
||||
function setArrayRoomConfig(rooms, config) {
|
||||
var json = {
|
||||
"config": config,
|
||||
"array": rooms
|
||||
}
|
||||
return sendPost("/live/config/set/array", false, json, true)
|
||||
}
|
||||
function deleteRoomConfig(roomId){
|
||||
return get("/live/config/delete?roomId="+roomId)
|
||||
function deleteArrayRoomConfig(rooms) {
|
||||
return sendPost("/live/config/delete/array", false,rooms, true)
|
||||
}
|
||||
function checkFollowStatus(userId){
|
||||
return get("/live/config/follow/check?userId="+userId)
|
||||
function deleteAllRoomConfig() {
|
||||
return get("/live/config/delete/all")
|
||||
}
|
||||
function confirmFollowStatus(userId){
|
||||
return get("/live/config/follow/confirm?userId="+userId)
|
||||
function getRoomConfig(roomId) {
|
||||
return get("/live/config/get?roomId=" + roomId)
|
||||
}
|
||||
function addAllFollow(userId){
|
||||
return get("/live/config/follow/all?userId="+userId)
|
||||
function deleteRoomConfig(roomId) {
|
||||
return get("/live/config/delete?roomId=" + roomId)
|
||||
}
|
||||
function addFollow(uid,anchorId){
|
||||
return get("/live/config/follow/add?anchorId="+anchorId+"&uid="+uid)
|
||||
function checkFollowStatus(userId) {
|
||||
return get("/live/config/follow/check?userId=" + userId)
|
||||
}
|
||||
function addFollowList(uid,array){
|
||||
function confirmFollowStatus(userId) {
|
||||
return get("/live/config/follow/confirm?userId=" + userId)
|
||||
}
|
||||
function addAllFollow(userId) {
|
||||
return get("/live/config/follow/all?userId=" + userId)
|
||||
}
|
||||
function addFollow(uid, anchorId) {
|
||||
return get("/live/config/follow/add?anchorId=" + anchorId + "&uid=" + uid)
|
||||
}
|
||||
function addFollowList(uid, array) {
|
||||
const formData = new FormData();
|
||||
formData.append("array", array);
|
||||
return post("/live/config/follow/addList?uid="+uid,formData,true)
|
||||
return post("/live/config/follow/addList?uid=" + uid, formData, true)
|
||||
}
|
||||
function addFollowRoomList(array) {
|
||||
const formData = new FormData();
|
||||
formData.append("array", array);
|
||||
return post("/live/config/follow/roomId/addList", formData, true)
|
||||
}
|
||||
//----------------直播配置相关接口end
|
||||
//----------------首页相关接口
|
||||
function getAllLive(page,limit){
|
||||
return get("/live/list?page="+page+"&limit="+limit)
|
||||
function getAllLive(page, limit) {
|
||||
return get("/live/list?page=" + page + "&limit=" + limit)
|
||||
}
|
||||
function getAllConfig(page,limit){
|
||||
return get("/live/config/all?page="+page+"&limit="+limit)
|
||||
function getAllConfig(page, limit) {
|
||||
return get("/live/config/all?page=" + page + "&limit=" + limit)
|
||||
}
|
||||
//----------------首页相关接口end
|
||||
//----------------直播视频相关接口
|
||||
function startLiveVideo(roomId){
|
||||
return get("/live/video/start?roomId="+roomId)
|
||||
function startLiveVideo(roomId) {
|
||||
return get("/live/video/start?roomId=" + roomId)
|
||||
}
|
||||
function stopLiveVideo(roomId){
|
||||
return get("/live/video/stop?roomId="+roomId)
|
||||
function stopLiveVideo(roomId) {
|
||||
return get("/live/video/stop?roomId=" + roomId)
|
||||
}
|
||||
function getVideo(roomId,page,limit){
|
||||
return get("/file/list?roomId="+roomId+"&page="+page+"&limit="+limit)
|
||||
function getVideo(roomId, page, limit) {
|
||||
return get("/file/list?roomId=" + roomId + "&page=" + page + "&limit=" + limit)
|
||||
}
|
||||
function getPlayerVideo(roomId,videoId){
|
||||
return get('/video/play?roomId='+roomId+"&videoId="+videoId)
|
||||
function getPlayerVideo(roomId, videoId) {
|
||||
return get('/video/play?roomId=' + roomId + "&videoId=" + videoId)
|
||||
}
|
||||
//----------------直播视频相关接口end
|
||||
//----------------弹幕相关接口
|
||||
function startLiveDanmu(roomId){
|
||||
return get("/live/danmu/start?roomId="+roomId)
|
||||
function startLiveDanmu(roomId) {
|
||||
return get("/live/danmu/start?roomId=" + roomId)
|
||||
}
|
||||
function stopLiveDanmu(roomId){
|
||||
return get("/live/danmu/stop?roomId="+roomId)
|
||||
function stopLiveDanmu(roomId) {
|
||||
return get("/live/danmu/stop?roomId=" + roomId)
|
||||
}
|
||||
function getDanmu(roomId,videoId){
|
||||
return get("/live/danmu/get?roomId="+roomId+"&videoId="+videoId)
|
||||
function getDanmu(roomId, videoId) {
|
||||
return get("/live/danmu/get?roomId=" + roomId + "&videoId=" + videoId)
|
||||
}
|
||||
//----------------弹幕相关接口end
|
||||
//----------------用户相关接口
|
||||
function getBiliAllUser(){
|
||||
function getBiliAllUser() {
|
||||
return get("/user/list")
|
||||
}
|
||||
function login(){
|
||||
function login() {
|
||||
return get("/user/login")
|
||||
}
|
||||
function refreshCookie(userId){
|
||||
return get("/user/refreshCookie?uid="+userId)
|
||||
function refreshCookie(userId) {
|
||||
return get("/user/refreshCookie?uid=" + userId)
|
||||
}
|
||||
//----------------用户相关接口end
|
||||
//----------------礼物相关接口
|
||||
function getVideoGiftInfo(roomId,videoId){
|
||||
return get("/live/gift/info?roomId="+roomId+"&videoId="+videoId)
|
||||
function getVideoGiftInfo(roomId, videoId) {
|
||||
return get("/live/gift/info?roomId=" + roomId + "&videoId=" + videoId)
|
||||
}
|
||||
//----------------礼物相关接口end
|
||||
Reference in New Issue
Block a user