FIX: Fetch csrf token if needed before uploading (#23825)

This commit is contained in:
Jarek Radosz 2023-10-09 15:47:36 +02:00 committed by GitHub
parent f13f2fecfe
commit 53c9c9c1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import { cacheShortUploadUrl } from "pretty-text/upload-short-url";
import { inject as service } from "@ember/service";
import { run } from "@ember/runloop";
import escapeRegExp from "discourse-common/utils/escape-regexp";
import { updateCsrfToken } from "discourse/lib/ajax";
// Note: This mixin is used _in addition_ to the ComposerUpload mixin
// on the composer-editor component. It overrides some, but not all,
@ -39,6 +40,8 @@ import escapeRegExp from "discourse-common/utils/escape-regexp";
//
export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
dialog: service(),
session: service(),
uploadRootPath: "/uploads",
uploadTargetBound: false,
useUploadPlaceholders: true,
@ -596,8 +599,13 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
},
@bind
_addFiles(files, opts = {}) {
async _addFiles(files, opts = {}) {
if (!this.session.csrfToken) {
await updateCsrfToken();
}
files = Array.isArray(files) ? files : [files];
try {
this._uppyInstance.addFiles(
files.map((file) => {

View File

@ -3,7 +3,7 @@ import { run } from "@ember/runloop";
import ExtendableUploader from "discourse/mixins/extendable-uploader";
import { or } from "@ember/object/computed";
import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import { ajax, updateCsrfToken } from "discourse/lib/ajax";
import {
bindFileInputChangeListener,
displayErrorForUpload,
@ -429,8 +429,13 @@ export default Mixin.create(UppyS3Multipart, ExtendableUploader, {
},
@bind
_addFiles(files, opts = {}) {
async _addFiles(files, opts = {}) {
if (!this.session.csrfToken) {
await updateCsrfToken();
}
files = Array.isArray(files) ? files : [files];
try {
this._uppyInstance.addFiles(
files.map((file) => {