优化文件上传:提供多ipfs网关查询
This commit is contained in:
38
public/ipfs.html
Normal file
38
public/ipfs.html
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh_cn">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>ipfs资源获取</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
let hash = window.location.hash.substr(1);
|
||||||
|
if (hash) {
|
||||||
|
console.log(hash);
|
||||||
|
let loaded_config = JSON.parse(localStorage['hole_config'] || '{}');
|
||||||
|
let ipfs_list = loaded_config.ipfs_gateway_list || [];
|
||||||
|
console.log(ipfs_list);
|
||||||
|
ipfs_list.forEach((patt, idx) => {
|
||||||
|
let url = patt.replaceAll("<hash>", hash);
|
||||||
|
var p = document.createElement('p');
|
||||||
|
p.id = idx;
|
||||||
|
p.appendChild(document.createTextNode(`${url}: 测试中...`));
|
||||||
|
document.body.appendChild(p);
|
||||||
|
fetch(url)
|
||||||
|
.then(resp => {
|
||||||
|
if (resp.ok) {
|
||||||
|
window.location = url;
|
||||||
|
} else {
|
||||||
|
throw Error(resp.status);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(url, error);
|
||||||
|
document.getElementById(idx).innerHTML = `${url}: 获取数据失败, ${error}`;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</html>
|
||||||
@@ -691,7 +691,8 @@ export class PostForm extends Component {
|
|||||||
let new_text =
|
let new_text =
|
||||||
this.state.text +
|
this.state.text +
|
||||||
'\n' +
|
'\n' +
|
||||||
(file_type.startsWith('image/') ? `` : url);
|
(file_type.startsWith('image/') ? `` : url) +
|
||||||
|
` [加载失败请点击此](${window.location.origin}/ipfs.html#${data.hash})\n\n---\n`;
|
||||||
this.setState({ text: new_text });
|
this.setState({ text: new_text });
|
||||||
this.area_ref.current.set(new_text);
|
this.area_ref.current.set(new_text);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user