mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 18:58:10 +00:00
FIX: make sure pasting an image in the composer is considered as an image instead of an attachment
This commit is contained in:
parent
256519dddf
commit
e6f849f873
@ -162,11 +162,12 @@ Discourse.Utilities = {
|
||||
}
|
||||
|
||||
var upload = files[0];
|
||||
var type = Discourse.Utilities.isAnImage(upload.name) ? 'image' : 'attachment';
|
||||
|
||||
// CHROME ONLY: if the image was pasted, sets its name to a default one
|
||||
if (upload instanceof Blob && !(upload instanceof File) && upload.type === "image/png") { upload.name = "blob.png"; }
|
||||
|
||||
var type = Discourse.Utilities.isAnImage(upload.name) ? 'image' : 'attachment';
|
||||
|
||||
return Discourse.Utilities.validateUploadedFile(upload, type, bypassNewUserRestriction);
|
||||
},
|
||||
|
||||
|
@ -60,14 +60,16 @@ test("prevents files that are too big from being uploaded", function() {
|
||||
ok(bootbox.alert.calledWith(I18n.t('post.errors.file_too_large', { max_size_kb: 5 })));
|
||||
});
|
||||
|
||||
var imageSize = 10 * 1024;
|
||||
|
||||
var dummyBlob = function() {
|
||||
var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
|
||||
if (BlobBuilder) {
|
||||
var bb = new BlobBuilder();
|
||||
bb.append([1]);
|
||||
bb.append([new Int8Array(imageSize)]);
|
||||
return bb.getBlob("image/png");
|
||||
} else {
|
||||
return new Blob([1], { "type" : "image\/png" });
|
||||
return new Blob([new Int8Array(imageSize)], { "type" : "image\/png" });
|
||||
}
|
||||
};
|
||||
|
||||
@ -75,10 +77,11 @@ test("allows valid uploads to go through", function() {
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
Discourse.User.currentProp("trust_level", 1);
|
||||
Discourse.SiteSettings.max_image_size_kb = 15;
|
||||
Discourse.SiteSettings.max_attachment_size_kb = 1;
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
||||
// image
|
||||
var image = { name: "image.png", size: 10 * 1024 };
|
||||
var image = { name: "image.png", size: imageSize };
|
||||
ok(validUpload([image]));
|
||||
// pasted image
|
||||
var pastedImage = dummyBlob();
|
||||
|
Loading…
x
Reference in New Issue
Block a user