mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 19:53:21 +02:00
feat: images
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-black-50 d-flex align-items-center justify-content-center h-100 py-3">
|
||||
<textarea id="postBody" name="postBody">{{.Body}}</textarea>
|
||||
<textarea id="postBody" name="postBody">{{.Post.Body}}</textarea>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -49,43 +49,43 @@
|
||||
},
|
||||
license_key: 'gpl',
|
||||
images_upload_handler: (blobInfo, progress) => new Promise((resolve, reject) => {
|
||||
// const xhr = new XMLHttpRequest();
|
||||
// xhr.withCredentials = false;
|
||||
// xhr.open('POST', 'postAcceptor.php');
|
||||
//
|
||||
// xhr.upload.onprogress = (e) => {
|
||||
// progress(e.loaded / e.total * 100);
|
||||
// };
|
||||
//
|
||||
// xhr.onload = () => {
|
||||
// if (xhr.status === 403) {
|
||||
// reject({message: 'HTTP Error: ' + xhr.status, remove: true});
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (xhr.status < 200 || xhr.status >= 300) {
|
||||
// reject('HTTP Error: ' + xhr.status);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// const json = JSON.parse(xhr.responseText);
|
||||
//
|
||||
// if (!json || typeof json.location != 'string') {
|
||||
// reject('Invalid JSON: ' + xhr.responseText);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// resolve(json.location);
|
||||
// };
|
||||
//
|
||||
// xhr.onerror = () => {
|
||||
// reject('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
|
||||
// };
|
||||
//
|
||||
// const formData = new FormData();
|
||||
// formData.append('file', blobInfo.blob(), blobInfo.filename());
|
||||
//
|
||||
// xhr.send(formData);
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.withCredentials = false;
|
||||
xhr.open('POST', `/post/{{.Post.ID}}/image/create`);
|
||||
|
||||
xhr.upload.onprogress = (e) => {
|
||||
progress(e.loaded / e.total * 100);
|
||||
};
|
||||
|
||||
xhr.onload = () => {
|
||||
if (xhr.status === 403) {
|
||||
reject({message: 'HTTP Error: ' + xhr.status, remove: true});
|
||||
return;
|
||||
}
|
||||
|
||||
if (xhr.status < 200 || xhr.status >= 300) {
|
||||
reject('HTTP Error: ' + xhr.status);
|
||||
return;
|
||||
}
|
||||
|
||||
const json = JSON.parse(xhr.responseText);
|
||||
|
||||
if (!json || typeof json.location != 'string') {
|
||||
reject('Invalid JSON: ' + xhr.responseText);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(`http{{ if .Secured }}s{{ end }}://${window.location.host}${json.location}`);
|
||||
};
|
||||
|
||||
xhr.onerror = () => {
|
||||
reject('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
|
||||
};
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', blobInfo.blob(), blobInfo.filename());
|
||||
|
||||
xhr.send(formData);
|
||||
}),
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user