1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-03-26 21:12:59 +02:00

API: Resolves #4655: Don't compress image when resource is added through api (#4660)

This commit is contained in:
Nishant Mittal 2021-03-14 20:58:34 +05:30 committed by GitHub
parent 74cd19f942
commit f8b7d20255
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -326,6 +326,26 @@ describe('services_rest_Api', function() {
expect(response.body.indexOf(resource.id) >= 0).toBe(true);
}));
it('should not compress images uploaded through resource api', (async () => {
const originalImagePath = `${__dirname}/../tests/support/photo-large.png`;
await api.route(RequestMethod.POST, 'resources', null, JSON.stringify({
title: 'testing resource',
}), [
{
path: originalImagePath,
},
]);
const resources = await Resource.all();
expect(resources.length).toBe(1);
const uploadedImagePath = Resource.fullPath(resources[0]);
const originalImageSize = (await shim.fsDriver().stat(originalImagePath)).size;
const uploadedImageSize = (await shim.fsDriver().stat(uploadedImagePath)).size;
expect(originalImageSize).toEqual(uploadedImageSize);
}));
it('should delete resources', (async () => {
const f = await Folder.save({ title: 'mon carnet' });

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -51,7 +51,10 @@ export default async function(request: Request, id: string = null, link: string
if (!request.files.length) throw new ErrorBadRequest('Resource cannot be created without a file');
const filePath = request.files[0].path;
const defaultProps = request.bodyJson(readonlyProperties('POST'));
return shim.createResourceFromPath(filePath, defaultProps, { userSideValidation: true });
return shim.createResourceFromPath(filePath, defaultProps, {
userSideValidation: true,
resizeLargeImages: 'never',
});
}
return defaultAction(BaseModel.TYPE_RESOURCE, request, id, link);