Skip to content

Commit

Permalink
cors request
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Jan 8, 2024
1 parent e363c2b commit 6bceb73
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions manual/spec_sstp.html
Original file line number Diff line number Diff line change
Expand Up @@ -705,14 +705,37 @@ <h1>Commandヘッダに指定できるコマンドと、返ってくる追加デ
const version = await jsstp.GetShortVersion();
document.getElementById("GetShortVersionResultTextBox").style.display = "block";
document.getElementById("GetShortVersionResultTextBox").value = version.text_content;
//创建一个流对象获取version.json
let reader = new FileReader();
reader.readAsText(await (await fetch("https://ssp.shillest.net/archive/version.json")).blob());
reader.onload = async () => {
const json = JSON.parse(reader.result);
const latestVersion = json["ssp.full.version"];
document.getElementById("GetShortVersionResultTextBox").style.color = (version == latestVersion) ? "green" : "red";
};
//创建一个cors获取version.json
fetch("https://ssp.shillest.net/archive/version.json", {
method: 'GET',
mode: 'cors',
}).then(function (response) {
//if response.type is "cors", get the json file from response.body as ReadableStream
if (response.type === "cors") {
//ReadableStream init
const reader = response.body.getReader();
//buffer init
let buffer = "";
//ReadableStream read to data process
reader.read().then(function processText({ done, value }) {
//if ReadableStream is done
if (done) {
const json = JSON.parse(buffer);
const latestVersion = json["ssp.full.version"];
document.getElementById("GetShortVersionResultTextBox").style.color = (version == latestVersion) ? "green" : "red";
return;
}
//decode the ReadableStream to string
let text = new TextDecoder("utf-8").decode(value);
//log the text
console.log(text);
//append the text to buffer
buffer += text;
//read next
return reader.read().then(processText);
});
}
});
} else {
document.getElementById("GetShortVersionResultTextBox").style.display = "none";
}
Expand Down

0 comments on commit 6bceb73

Please sign in to comment.