mirror of
https://github.com/discourse/discourse.git
synced 2025-09-07 12:02:53 +08: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
2 changed files with 8 additions and 4 deletions
|
@ -162,11 +162,12 @@ Discourse.Utilities = {
|
||||||
}
|
}
|
||||||
|
|
||||||
var upload = files[0];
|
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
|
// 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"; }
|
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);
|
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 })));
|
ok(bootbox.alert.calledWith(I18n.t('post.errors.file_too_large', { max_size_kb: 5 })));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var imageSize = 10 * 1024;
|
||||||
|
|
||||||
var dummyBlob = function() {
|
var dummyBlob = function() {
|
||||||
var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
|
var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
|
||||||
if (BlobBuilder) {
|
if (BlobBuilder) {
|
||||||
var bb = new BlobBuilder();
|
var bb = new BlobBuilder();
|
||||||
bb.append([1]);
|
bb.append([new Int8Array(imageSize)]);
|
||||||
return bb.getBlob("image/png");
|
return bb.getBlob("image/png");
|
||||||
} else {
|
} 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.resetCurrent(Discourse.User.create());
|
||||||
Discourse.User.currentProp("trust_level", 1);
|
Discourse.User.currentProp("trust_level", 1);
|
||||||
Discourse.SiteSettings.max_image_size_kb = 15;
|
Discourse.SiteSettings.max_image_size_kb = 15;
|
||||||
|
Discourse.SiteSettings.max_attachment_size_kb = 1;
|
||||||
sandbox.stub(bootbox, "alert");
|
sandbox.stub(bootbox, "alert");
|
||||||
|
|
||||||
// image
|
// image
|
||||||
var image = { name: "image.png", size: 10 * 1024 };
|
var image = { name: "image.png", size: imageSize };
|
||||||
ok(validUpload([image]));
|
ok(validUpload([image]));
|
||||||
// pasted image
|
// pasted image
|
||||||
var pastedImage = dummyBlob();
|
var pastedImage = dummyBlob();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue