Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
54145a authored Feb 21, 2024
1 parent 3e05da7 commit 756fb7b
Showing 1 changed file with 67 additions and 24 deletions.
91 changes: 67 additions & 24 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#text,
#file {
#inputText,
#inputFile,
#inputHash {
width: 95%;
}

Expand All @@ -22,38 +23,80 @@
</head>

<body>
在这里输入上传的文本: <br>
<textarea id="text" cols="30" rows="10"></textarea><br>
<h1>Dao3 Static 工具</h1>
<h2>Hash获取文件</h2>
<input id="inputHash" type="text"><br>
<button onclick="get()">获取</button>
<h2>上传文本</h2>
<textarea id="inputText" cols="30" rows="10"></textarea><br>
<button onclick="postText()">上传文本</button><br>
上传文件 <br>
<input type="file" multiple="false" id="file" onchange="postFile()"><br>
上传结果 <br>
<code id="result">
<code id="recent"></code>
<h2>上传文件</h2>
<input id="inputFile" type="file" multiple="false"onchange="postFile()"><br>
<h2>上传结果</h2>
<div id="result"></div>
<script>
"use strict";
class Static {
/**
* @param {URL} baseUrl
*/
constructor(baseUrl) {
this.baseUrl = baseUrl;
}
/**
* @param {string} hash
* @returns {URL}
*/
get(hash) {
return new URL(`${this.baseUrl.toString()}${hash}.json`);
}
/**
* @param {string|Blob} data
* @returns {object}
*/
async post(data) {
const postResult = await fetch(this.baseUrl, {
method: "POST",
headers: {},
body: data,
mode: "cors"
});
const resultData = await postResult.json();
return resultData;
}
}
const dao3Static = new Static("https://static.dao3.fun/block/");
const resultDisplay = document.getElementById("result");
if (!localStorage.getItem("results")) {
localStorage.setItem("results", JSON.stringify([]));
}
for (const data of JSON.parse(localStorage.getItem("results")).slice(0, 100)) {
const code = document.createElement("code");
code.textContent = `${new Date(data.time).toLocaleString()} ${JSON.stringify(data.result)}`;
resultDisplay.appendChild(code);
resultDisplay.appendChild(document.createElement("br"));
}
function get() {
const hash = document.getElementById("inputHash").value;
open(dao3Static.get(hash),"_blank");
}
async function post(data) {
const postResult = await fetch("https://static.dao3.fun/block/", {
method: "POST",
headers: {},
body: data,
mode: "cors"
const resultData = await dao3Static.post(data);
const results = JSON.parse(localStorage.getItem("results"));
results.unshift({
time: Date.now(),
result: resultData
});
const resultData = await postResult.json();
if (resultData.Key) {
const hash = resultData.Key;
resultDisplay.textContent = `https://static.dao3.fun/block/${hash}.json`;
} else {
resultDisplay.textContent = JSON.stringify(resultData);
}
localStorage.setItem("results", JSON.stringify(results));
location.reload();
}
async function postFile() {
const input = document.getElementById("file");
const input = document.getElementById("inputFile");
const file = input.files[0];
await post(file);
};
}
async function postText() {
const text = document.getElementById("text");
const text = document.getElementById("inputText");
const data = text.value;
if (data.length === 0) return;
await post(data);
Expand Down

0 comments on commit 756fb7b

Please sign in to comment.