stop use ipfs
This commit is contained in:
@@ -10,13 +10,13 @@ import {
|
|||||||
TAG_RE,
|
TAG_RE,
|
||||||
split_text,
|
split_text,
|
||||||
} from './text_splitter';
|
} from './text_splitter';
|
||||||
import { save_config } from './Config';
|
|
||||||
import renderMd from './Markdown';
|
import renderMd from './Markdown';
|
||||||
|
|
||||||
export { format_time, Time, TitleLine };
|
export { format_time, Time, TitleLine };
|
||||||
|
|
||||||
export const API_BASE = `${process.env.REACT_APP_BACKEND || '/'}_api/v1`;
|
export const API_BASE = `${process.env.REACT_APP_BACKEND || '/'}_api/v1`;
|
||||||
export const API_BASE_2 = `${process.env.REACT_APP_BACKEND || '/'}_api/v2`;
|
export const API_BASE_2 = `${process.env.REACT_APP_BACKEND || '/'}_api/v2`;
|
||||||
|
export const STORAGE_BASE = `${process.env.REACT_APP_STORAGE || ''}`;
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
|
// https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
|
||||||
function escape_regex(string) {
|
function escape_regex(string) {
|
||||||
@@ -429,29 +429,3 @@ export class ClickHandler extends PureComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function test_ipfs(hash) {
|
|
||||||
let key = 'testing_' + hash;
|
|
||||||
window[key] = { curr: 0 };
|
|
||||||
window.config.ipfs_gateway_list.forEach((url) => {
|
|
||||||
fetch(url.replaceAll('<hash>', hash), { method: 'HEAD' })
|
|
||||||
.then((res) => {
|
|
||||||
if (res.ok) {
|
|
||||||
console.log(url, 'success!');
|
|
||||||
if (window[key]) {
|
|
||||||
window[key].curr += 1;
|
|
||||||
window[key][url] = window[key].curr;
|
|
||||||
let list = window.config.ipfs_gateway_list;
|
|
||||||
list.sort(
|
|
||||||
(x, y) => (window[key][x] || 9999) - (window[key][y] || 999),
|
|
||||||
);
|
|
||||||
window.config.ipfs_gateway_list = list;
|
|
||||||
save_config(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.log(url, 'fail!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -33,16 +33,6 @@ const DEFAULT_CONFIG = {
|
|||||||
block_cw: ['xxg', 'zzxg'],
|
block_cw: ['xxg', 'zzxg'],
|
||||||
block_words_v4: ['🕷️', '[系统自动代发]'],
|
block_words_v4: ['🕷️', '[系统自动代发]'],
|
||||||
whitelist_cw: [],
|
whitelist_cw: [],
|
||||||
ipfs_gateway_list: [
|
|
||||||
'https://<hash>.ipfs.dweb.link/',
|
|
||||||
'https://<hash>.ipfs.infura-ipfs.io/',
|
|
||||||
'https://gateway.pinata.cloud/ipfs/<hash>',
|
|
||||||
'https://ipfs.eth.aragon.network/ipfs/<hash>',
|
|
||||||
'https://gateway.ipfs.io/ipfs/<hash>',
|
|
||||||
'https://ipfs.fleek.co/ipfs/<hash>',
|
|
||||||
'https://cloudflare-ipfs.com/ipfs/<hash>',
|
|
||||||
'https://ipfs.2read.net/ipfs/<hash>',
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function load_config() {
|
export function load_config() {
|
||||||
@@ -70,6 +60,7 @@ export function load_config() {
|
|||||||
console.log('config loaded', config);
|
console.log('config loaded', config);
|
||||||
window.config = config;
|
window.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function save_config(need_load = true) {
|
export function save_config(need_load = true) {
|
||||||
localStorage['hole_config'] = JSON.stringify(window.config);
|
localStorage['hole_config'] = JSON.stringify(window.config);
|
||||||
if (need_load) load_config();
|
if (need_load) load_config();
|
||||||
@@ -411,18 +402,6 @@ export class ConfigUI extends PureComponent {
|
|||||||
parse={(string) => string.split('\n')}
|
parse={(string) => string.split('\n')}
|
||||||
/>
|
/>
|
||||||
<hr />
|
<hr />
|
||||||
<ConfigTextArea
|
|
||||||
id="ipfs_gateway_list"
|
|
||||||
callback={this.save_changes_bound}
|
|
||||||
name="候选ipfs网关"
|
|
||||||
description={
|
|
||||||
'<hash>表示要替换的哈希值。下次上传文件会使用第一行的,上传后根据速度调整。'
|
|
||||||
}
|
|
||||||
display={(array) => array.join('\n')}
|
|
||||||
sift={(array) => array.filter((v) => v)}
|
|
||||||
parse={(string) => string.split('\n')}
|
|
||||||
/>
|
|
||||||
<hr />
|
|
||||||
<ConfigSwitch
|
<ConfigSwitch
|
||||||
callback={this.save_changes_bound}
|
callback={this.save_changes_bound}
|
||||||
id="pressure"
|
id="pressure"
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import React, { Component } from 'react';
|
|||||||
import {
|
import {
|
||||||
API_BASE,
|
API_BASE,
|
||||||
API_BASE_2,
|
API_BASE_2,
|
||||||
|
STORAGE_BASE,
|
||||||
SafeTextarea,
|
SafeTextarea,
|
||||||
PromotionBar,
|
PromotionBar,
|
||||||
HighlightedMarkdown,
|
HighlightedMarkdown,
|
||||||
test_ipfs,
|
|
||||||
} from './Common';
|
} from './Common';
|
||||||
import { MessageViewer } from './Message';
|
import { MessageViewer } from './Message';
|
||||||
import { LoginPopup } from './infrastructure/widgets';
|
import { LoginPopup } from './infrastructure/widgets';
|
||||||
@@ -671,7 +671,7 @@ export class PostForm extends Component {
|
|||||||
xh.addEventListener('load', this.upload_complete.bind(this), false);
|
xh.addEventListener('load', this.upload_complete.bind(this), false);
|
||||||
xh.addEventListener('error', this.upload_error.bind(this), false);
|
xh.addEventListener('error', this.upload_error.bind(this), false);
|
||||||
xh.addEventListener('abort', this.upload_abort.bind(this), false);
|
xh.addEventListener('abort', this.upload_abort.bind(this), false);
|
||||||
xh.open('POST', API_BASE + '/upload');
|
xh.open('POST', API_BASE_2 + '/upload');
|
||||||
xh.setRequestHeader('User-Token', this.props.token);
|
xh.setRequestHeader('User-Token', this.props.token);
|
||||||
xh.send(f);
|
xh.send(f);
|
||||||
}
|
}
|
||||||
@@ -679,20 +679,13 @@ export class PostForm extends Component {
|
|||||||
|
|
||||||
update_text_after_upload(data) {
|
update_text_after_upload(data) {
|
||||||
const { file_name, file_type } = this.state;
|
const { file_name, file_type } = this.state;
|
||||||
let url =
|
let url = `${STORAGE_BASE}/${data.path}?filename=${encodeURIComponent(
|
||||||
(window.config.ipfs_gateway_list[0] || '<hash>(无ipfs网关)').replaceAll(
|
file_name,
|
||||||
'<hash>',
|
)}&filetype=${encodeURIComponent(file_type)}`;
|
||||||
data.hash,
|
|
||||||
) +
|
|
||||||
`?filename=${encodeURIComponent(file_name)}&filetype=${encodeURIComponent(
|
|
||||||
file_type,
|
|
||||||
)}`;
|
|
||||||
test_ipfs(data.hash);
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -884,28 +877,7 @@ export class PostForm extends Component {
|
|||||||
</small>
|
</small>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<small>
|
<small>上传文件限制200M,保留至少一个月。也可使用第三方图床。</small>
|
||||||
首选ipfs网关可以在设置中修改,如效果不佳仍可使用图床,例如:
|
|
||||||
<a href="https://imgtu.com/" target="_blank">
|
|
||||||
路过图床
|
|
||||||
</a>
|
|
||||||
、
|
|
||||||
<a href="https://sm.ms/" target="_blank">
|
|
||||||
sm.ms
|
|
||||||
</a>
|
|
||||||
、
|
|
||||||
<a
|
|
||||||
href="https://bbs.pku.edu.cn/v2/post-read.php?bid=154&threadid=3743"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
未名BBS
|
|
||||||
</a>
|
|
||||||
、
|
|
||||||
<a href="https://zhuanlan.zhihu.com/write" target="_blank">
|
|
||||||
知乎
|
|
||||||
</a>
|
|
||||||
。
|
|
||||||
</small>
|
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user