mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 06:25:15 +08:00
FIX: Fetch csrf token if needed before uploading (#23825)
This commit is contained in:
parent
f13f2fecfe
commit
53c9c9c1e6
|
@ -24,6 +24,7 @@ import { cacheShortUploadUrl } from "pretty-text/upload-short-url";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { run } from "@ember/runloop";
|
import { run } from "@ember/runloop";
|
||||||
import escapeRegExp from "discourse-common/utils/escape-regexp";
|
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
|
// Note: This mixin is used _in addition_ to the ComposerUpload mixin
|
||||||
// on the composer-editor component. It overrides some, but not all,
|
// 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, {
|
export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
dialog: service(),
|
dialog: service(),
|
||||||
|
session: service(),
|
||||||
|
|
||||||
uploadRootPath: "/uploads",
|
uploadRootPath: "/uploads",
|
||||||
uploadTargetBound: false,
|
uploadTargetBound: false,
|
||||||
useUploadPlaceholders: true,
|
useUploadPlaceholders: true,
|
||||||
|
@ -596,8 +599,13 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, {
|
||||||
},
|
},
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
_addFiles(files, opts = {}) {
|
async _addFiles(files, opts = {}) {
|
||||||
|
if (!this.session.csrfToken) {
|
||||||
|
await updateCsrfToken();
|
||||||
|
}
|
||||||
|
|
||||||
files = Array.isArray(files) ? files : [files];
|
files = Array.isArray(files) ? files : [files];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this._uppyInstance.addFiles(
|
this._uppyInstance.addFiles(
|
||||||
files.map((file) => {
|
files.map((file) => {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { run } from "@ember/runloop";
|
||||||
import ExtendableUploader from "discourse/mixins/extendable-uploader";
|
import ExtendableUploader from "discourse/mixins/extendable-uploader";
|
||||||
import { or } from "@ember/object/computed";
|
import { or } from "@ember/object/computed";
|
||||||
import EmberObject from "@ember/object";
|
import EmberObject from "@ember/object";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax, updateCsrfToken } from "discourse/lib/ajax";
|
||||||
import {
|
import {
|
||||||
bindFileInputChangeListener,
|
bindFileInputChangeListener,
|
||||||
displayErrorForUpload,
|
displayErrorForUpload,
|
||||||
|
@ -429,8 +429,13 @@ export default Mixin.create(UppyS3Multipart, ExtendableUploader, {
|
||||||
},
|
},
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
_addFiles(files, opts = {}) {
|
async _addFiles(files, opts = {}) {
|
||||||
|
if (!this.session.csrfToken) {
|
||||||
|
await updateCsrfToken();
|
||||||
|
}
|
||||||
|
|
||||||
files = Array.isArray(files) ? files : [files];
|
files = Array.isArray(files) ? files : [files];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this._uppyInstance.addFiles(
|
this._uppyInstance.addFiles(
|
||||||
files.map((file) => {
|
files.map((file) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user