mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 09:45:52 +01:00
refactor uploading files
This commit is contained in:
@@ -64,18 +64,7 @@ export default class AttachmentActionsWidget extends BasicWidget {
|
||||
const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below
|
||||
this.$uploadNewRevisionInput.val('');
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('upload', fileToUpload);
|
||||
|
||||
const result = await $.ajax({
|
||||
url: `${window.glob.baseApiUrl}attachments/${this.attachmentId}/file`,
|
||||
headers: await server.getHeaders(),
|
||||
data: formData,
|
||||
type: 'PUT',
|
||||
timeout: 60 * 60 * 1000,
|
||||
contentType: false, // NEEDED, DON'T REMOVE THIS
|
||||
processData: false, // NEEDED, DON'T REMOVE THIS
|
||||
});
|
||||
const result = await server.upload(`attachments/${this.attachmentId}/file`, fileToUpload);
|
||||
|
||||
if (result.uploaded) {
|
||||
toastService.showMessage("New attachment revision has been uploaded.");
|
||||
|
||||
@@ -49,16 +49,8 @@ export default class NoteContextAwareWidget extends BasicWidget {
|
||||
|
||||
async refresh() {
|
||||
if (this.isEnabled()) {
|
||||
const start = Date.now();
|
||||
|
||||
this.toggleInt(true);
|
||||
await this.refreshWithNote(this.note);
|
||||
|
||||
const end = Date.now();
|
||||
|
||||
if (glob.PROFILING_LOG && end - start > 10) {
|
||||
console.log(`Refresh of ${this.componentId} took ${end-start}ms`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.toggleInt(false);
|
||||
|
||||
@@ -100,18 +100,7 @@ export default class FilePropertiesWidget extends NoteContextAwareWidget {
|
||||
const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below
|
||||
this.$uploadNewRevisionInput.val('');
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('upload', fileToUpload);
|
||||
|
||||
const result = await $.ajax({
|
||||
url: `${window.glob.baseApiUrl}notes/${this.noteId}/file`,
|
||||
headers: await server.getHeaders(),
|
||||
data: formData,
|
||||
type: 'PUT',
|
||||
timeout: 60 * 60 * 1000,
|
||||
contentType: false, // NEEDED, DON'T REMOVE THIS
|
||||
processData: false, // NEEDED, DON'T REMOVE THIS
|
||||
});
|
||||
const result = await server.upload(`notes/${this.noteId}/file`, fileToUpload);
|
||||
|
||||
if (result.uploaded) {
|
||||
toastService.showMessage("New file revision has been uploaded.");
|
||||
|
||||
@@ -84,18 +84,7 @@ export default class ImagePropertiesWidget extends NoteContextAwareWidget {
|
||||
const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below
|
||||
this.$uploadNewRevisionInput.val('');
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('upload', fileToUpload);
|
||||
|
||||
const result = await $.ajax({
|
||||
url: `${window.glob.baseApiUrl}images/${this.noteId}`,
|
||||
headers: await server.getHeaders(),
|
||||
data: formData,
|
||||
type: 'PUT',
|
||||
timeout: 60 * 60 * 1000,
|
||||
contentType: false, // NEEDED, DON'T REMOVE THIS
|
||||
processData: false, // NEEDED, DON'T REMOVE THIS
|
||||
});
|
||||
const result = await server.upload(`images/${this.noteId}`, fileToUpload);
|
||||
|
||||
if (result.uploaded) {
|
||||
toastService.showMessage("New image revision has been uploaded.");
|
||||
|
||||
@@ -57,7 +57,7 @@ export default class AttachmentDetailTypeWidget extends TypeWidget {
|
||||
})
|
||||
);
|
||||
|
||||
const attachment = await froca.getAttachment(this.attachmentId);
|
||||
const attachment = await froca.getAttachment(this.attachmentId, true);
|
||||
|
||||
if (!attachment) {
|
||||
this.$wrapper.html("<strong>This attachment has been deleted.</strong>");
|
||||
|
||||
Reference in New Issue
Block a user