Browse Source

优化文件上传:提供多ipfs网关查询

pull/16/head
hole-thu 3 years ago
parent
commit
de7ac42f65
  1. 38
      public/ipfs.html
  2. 3
      src/UserAction.js

38
public/ipfs.html

@ -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>

3
src/UserAction.js

@ -691,7 +691,8 @@ export class PostForm extends Component {
let new_text =
this.state.text +
'\n' +
(file_type.startsWith('image/') ? `![](${url})` : url);
(file_type.startsWith('image/') ? `![](${url})` : url) +
` [加载失败请点击此](${window.location.origin}/ipfs.html#${data.hash})\n\n---\n`;
this.setState({ text: new_text });
this.area_ref.current.set(new_text);
}

Loading…
Cancel
Save