add types for blueimp-load-image

This commit is contained in:
Audric Ackermann 2020-11-24 13:19:21 +11:00
parent 9f14924e65
commit f673589c56
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4
8 changed files with 14 additions and 23 deletions

View File

@ -618,7 +618,6 @@
onBanUser: () => this.banUser(), onBanUser: () => this.banUser(),
onRetrySend: () => this.retrySend(), onRetrySend: () => this.retrySend(),
onShowDetail: () => this.trigger('show-message-detail', this), onShowDetail: () => this.trigger('show-message-detail', this),
onClickLinkPreview: url => this.trigger('navigate-to', url),
markRead: readAt => this.markRead(readAt), markRead: readAt => this.markRead(readAt),
onShowUserDetails: pubkey => onShowUserDetails: pubkey =>

View File

@ -58,6 +58,7 @@
"@journeyapps/sqlcipher": "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#b10f232fac62ba7f8775c9e086bb5558fe7d948b", "@journeyapps/sqlcipher": "https://github.com/scottnonnenberg-signal/node-sqlcipher.git#b10f232fac62ba7f8775c9e086bb5558fe7d948b",
"@reduxjs/toolkit": "^1.4.0", "@reduxjs/toolkit": "^1.4.0",
"@sindresorhus/is": "0.8.0", "@sindresorhus/is": "0.8.0",
"@types/blueimp-load-image": "^2.23.8",
"@types/dompurify": "^2.0.0", "@types/dompurify": "^2.0.0",
"@types/emoji-mart": "^2.11.3", "@types/emoji-mart": "^2.11.3",
"@types/moment": "^2.13.0", "@types/moment": "^2.13.0",

View File

@ -379,7 +379,6 @@ const { autoOrientImage } = require('./js/modules/auto_orient_image');
window.autoOrientImage = autoOrientImage; window.autoOrientImage = autoOrientImage;
window.dataURLToBlobSync = require('blueimp-canvas-to-blob'); window.dataURLToBlobSync = require('blueimp-canvas-to-blob');
window.filesize = require('filesize'); window.filesize = require('filesize');
window.loadImage = require('blueimp-load-image');
window.getGuid = require('uuid/v4'); window.getGuid = require('uuid/v4');
window.profileImages = require('./app/profile_images'); window.profileImages = require('./app/profile_images');

View File

@ -865,12 +865,6 @@ export class RegistrationTabs extends React.Component<{}, State> {
language, language,
trimName trimName
); );
// FIXME remove everything related to hasSeenLightModeDialog at some point in the future (27/08/2020)
const data = {
id: 'hasSeenLightModeDialog',
value: true,
};
await createOrUpdateItem(data);
trigger('openInbox'); trigger('openInbox');
} catch (e) { } catch (e) {
ToastUtils.pushToastError( ToastUtils.pushToastError(

View File

@ -1,7 +1,7 @@
import { StagedAttachmentType } from '../components/session/conversation/SessionCompositionBox'; import { StagedAttachmentType } from '../components/session/conversation/SessionCompositionBox';
import { SignalService } from '../protobuf'; import { SignalService } from '../protobuf';
import { Constants } from '../session'; import { Constants } from '../session';
import loadImage from 'blueimp-load-image';
export interface MaxScaleSize { export interface MaxScaleSize {
maxSize?: number; maxSize?: number;
maxHeight?: number; maxHeight?: number;
@ -40,8 +40,7 @@ export async function autoScale<T extends { contentType: string; file: any }>(
return; return;
} }
const gifMaxSize = Constants.CONVERSATION.MAX_ATTACHMENT_FILESIZE_BYTES; if (file.type === 'image/gif' && file.size <= Constants.CONVERSATION.MAX_ATTACHMENT_FILESIZE_BYTES) {
if (file.type === 'image/gif' && file.size <= gifMaxSize) {
resolve(attachment); resolve(attachment);
return; return;
} }
@ -51,12 +50,11 @@ export async function autoScale<T extends { contentType: string; file: any }>(
return; return;
} }
const canvas = window.loadImage.scale(img, { const canvas = (loadImage as any).scale(img, {
canvas: true, canvas: true,
maxWidth, maxWidth,
maxHeight, maxHeight,
}); });
let quality = 0.95; let quality = 0.95;
let i = 4; let i = 4;
let blob; let blob;
@ -66,22 +64,19 @@ export async function autoScale<T extends { contentType: string; file: any }>(
canvas.toDataURL('image/jpeg', quality) canvas.toDataURL('image/jpeg', quality)
); );
quality = (quality * maxSize) / blob.size; quality = (quality * maxSize) / blob.size;
// Should we disallow the algo drop the quality too low?
// if (quality < 0.5) {
// quality = 0.5;
// }
// NOTE: During testing with a large image, we observed the
// `quality` value being > 1. Should we clamp it to [0.5, 1.0]?
// See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob#Syntax
if (quality > 1) { if (quality > 1) {
quality = 1; quality = 0.95;
} }
} while (i > 0 && blob.size > maxSize); } while (i > 0 && blob.size > maxSize);
resolve({ resolve({
...attachment, ...attachment,
file: blob, file: blob,
}); });
}; };
img.src = url; img.src = url;
}); });

View File

@ -20,7 +20,6 @@ export function getTimerBucket(expiration: number, length: number): string {
if (delta > length) { if (delta > length) {
return '60'; return '60';
} }
const bucket = Math.round((delta / length) * 12); const bucket = Math.round((delta / length) * 12);
return padStart(String(bucket * 5), 2, '0'); return padStart(String(bucket * 5), 2, '0');

1
ts/window.d.ts vendored
View File

@ -100,7 +100,6 @@ declare global {
GroupBuffer: any; GroupBuffer: any;
SwarmPolling: SwarmPolling; SwarmPolling: SwarmPolling;
MediaRecorder: any; MediaRecorder: any;
loadImage: any;
dataURLToBlobSync: any; dataURLToBlobSync: any;
autoOrientImage: any; autoOrientImage: any;
contextMenuShown: boolean; contextMenuShown: boolean;

View File

@ -367,6 +367,11 @@
"@types/jquery" "*" "@types/jquery" "*"
"@types/underscore" "*" "@types/underscore" "*"
"@types/blueimp-load-image@^2.23.8":
version "2.23.8"
resolved "https://registry.yarnpkg.com/@types/blueimp-load-image/-/blueimp-load-image-2.23.8.tgz#0d10f12bf57f050aceac06dcc76390ae759c979a"
integrity sha512-dy98N4odO9L1zgo2a6yVHRRYUeYRJfl0hg3dcapyxqNq5KF8Zgz5lFWgDMOsMC06VAs0mnVKDRJE4+U/A5Km3A==
"@types/bytebuffer@^5.0.41": "@types/bytebuffer@^5.0.41":
version "5.0.41" version "5.0.41"
resolved "https://registry.yarnpkg.com/@types/bytebuffer/-/bytebuffer-5.0.41.tgz#6850dba4d4cd2846596b4842874d5bfc01cd3db1" resolved "https://registry.yarnpkg.com/@types/bytebuffer/-/bytebuffer-5.0.41.tgz#6850dba4d4cd2846596b4842874d5bfc01cd3db1"