update
This commit is contained in:
@@ -1 +1,9 @@
|
||||
var headerModel=0;
|
||||
var headerModel=0;
|
||||
|
||||
function createUi(html){
|
||||
return fetch(html)
|
||||
.then(response=>response.text())
|
||||
.then(htmlText=>{
|
||||
return htmlText;
|
||||
})
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
/**
|
||||
*
|
||||
* @param {*} callback 回调
|
||||
*/
|
||||
function getLiveVideoList(callback){
|
||||
fetch("/live/video/list")
|
||||
function get(url){
|
||||
return fetch(url)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
@@ -11,9 +7,71 @@ function getLiveVideoList(callback){
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
callback.success(data);
|
||||
return data;
|
||||
})
|
||||
.catch(error => {
|
||||
callback.error(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){
|
||||
return response.json();
|
||||
}
|
||||
return response.blob();
|
||||
})
|
||||
.then(blob => {
|
||||
if(isJSON){
|
||||
return blob;
|
||||
}
|
||||
const imageUrl = URL.createObjectURL(blob);
|
||||
console.log("Image URL:", imageUrl);
|
||||
return imageUrl;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("There was a problem with the fetch operation:", error);
|
||||
throw error; // 重新抛出错误以便外部捕获
|
||||
});
|
||||
}
|
||||
function getLiveVideoList() {
|
||||
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;
|
||||
})
|
||||
}
|
||||
|
||||
function getBiliAllUser(){
|
||||
return get("/user/list")
|
||||
}
|
||||
function addRoomConfig(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);
|
||||
});
|
||||
} else if (value !== null && typeof value === 'object') {
|
||||
formData.append(key, value);
|
||||
} else {
|
||||
formData.append(key, value);
|
||||
}
|
||||
});
|
||||
return post("/live/config/set",formData)
|
||||
}
|
||||
Reference in New Issue
Block a user