新上传格式
This commit is contained in:
@@ -27,7 +27,11 @@ function escape_regex(string) {
|
|||||||
function is_video(s) {
|
function is_video(s) {
|
||||||
try {
|
try {
|
||||||
let url = new URL(s);
|
let url = new URL(s);
|
||||||
return url.pathname.endsWith('.mp4') || url.pathname.endsWith('.mov');
|
return (
|
||||||
|
url.pathname.endsWith('.mp4') ||
|
||||||
|
url.pathname.endsWith('.mov') ||
|
||||||
|
(url.searchParams.get('filetype') || '').startsWith('video/')
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -433,8 +433,9 @@ export class PostForm extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
text: '',
|
text: '',
|
||||||
upload_progress: '',
|
upload_progress_text: '',
|
||||||
is_loading: false,
|
is_loading: false,
|
||||||
|
file_name: '',
|
||||||
file_type: '',
|
file_type: '',
|
||||||
cw: window.CW_BACKUP || '',
|
cw: window.CW_BACKUP || '',
|
||||||
allow_search: window.AS_BACKUP || false,
|
allow_search: window.AS_BACKUP || false,
|
||||||
@@ -579,7 +580,8 @@ export class PostForm extends Component {
|
|||||||
console.log(event);
|
console.log(event);
|
||||||
let f = event.target.files[0];
|
let f = event.target.files[0];
|
||||||
if (f) {
|
if (f) {
|
||||||
this.setState({ is_loading: true, file_type: f.type });
|
console.log(f);
|
||||||
|
this.setState({ is_loading: true, file_name: f.name, file_type: f.type });
|
||||||
// let data = new FormData();
|
// let data = new FormData();
|
||||||
// data.append('file', f);
|
// data.append('file', f);
|
||||||
|
|
||||||
@@ -599,15 +601,19 @@ export class PostForm extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_text_after_upload(data) {
|
update_text_after_upload(data) {
|
||||||
|
const { file_name, file_type } = this.state;
|
||||||
let url =
|
let url =
|
||||||
(window.config.ipfs_gateway[0] || '<hash>(无ipfs网关)').replaceAll(
|
(window.config.ipfs_gateway[0] || '<hash>(无ipfs网关)').replaceAll(
|
||||||
'<hash>',
|
'<hash>',
|
||||||
data.hash,
|
data.hash,
|
||||||
) + data.filename;
|
) +
|
||||||
|
`?filename=${encodeURIComponent(file_name)}&filetype=${encodeURIComponent(
|
||||||
|
file_type,
|
||||||
|
)}`;
|
||||||
let new_text =
|
let new_text =
|
||||||
this.state.text +
|
this.state.text +
|
||||||
'\n' +
|
'\n' +
|
||||||
(this.state.file_type.startsWith('image/') ? `` : url);
|
(file_type.startsWith('image/') ? `` : url);
|
||||||
this.setState({ text: new_text });
|
this.setState({ text: new_text });
|
||||||
this.area_ref.current.set(new_text);
|
this.area_ref.current.set(new_text);
|
||||||
}
|
}
|
||||||
@@ -615,7 +621,9 @@ export class PostForm extends Component {
|
|||||||
upload_progress(event) {
|
upload_progress(event) {
|
||||||
console.log(event.loaded, event.total);
|
console.log(event.loaded, event.total);
|
||||||
this.setState({
|
this.setState({
|
||||||
upload_progress: `${((event.loaded * 100) / event.total).toFixed(2)}%`,
|
upload_progress_text: `${((event.loaded * 100) / event.total).toFixed(
|
||||||
|
2,
|
||||||
|
)}%`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -655,8 +663,9 @@ export class PostForm extends Component {
|
|||||||
poll_options,
|
poll_options,
|
||||||
preview,
|
preview,
|
||||||
loading_status,
|
loading_status,
|
||||||
upload_progress,
|
upload_progress_text,
|
||||||
is_loading,
|
is_loading,
|
||||||
|
file_name,
|
||||||
} = this.state;
|
} = this.state;
|
||||||
return (
|
return (
|
||||||
<form onSubmit={this.on_submit.bind(this)} className="post-form box">
|
<form onSubmit={this.on_submit.bind(this)} className="post-form box">
|
||||||
@@ -735,8 +744,12 @@ export class PostForm extends Component {
|
|||||||
onChange={this.on_file_change.bind(this)}
|
onChange={this.on_file_change.bind(this)}
|
||||||
disabled={is_loading}
|
disabled={is_loading}
|
||||||
/>
|
/>
|
||||||
{is_loading && !!upload_progress && (
|
{is_loading && (
|
||||||
<small>上传中: {upload_progress}</small>
|
<p>
|
||||||
|
<small>
|
||||||
|
上传 <i>{file_name}</i> 中: {upload_progress_text}
|
||||||
|
</small>
|
||||||
|
</p>
|
||||||
)}
|
)}
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
|
|||||||
Reference in New Issue
Block a user