Update media types

This commit is contained in:
Benjamin Toby 2023-12-15 11:08:23 +01:00
parent 0fa2a7fa20
commit 36ccd43fc3
5 changed files with 57 additions and 15 deletions

View File

@ -15,13 +15,17 @@
*
* @param {{
* imageInputFile: { name:string },
* maxWidth: number,
* imagePreviewNode: HTMLImageElement,
* maxWidth?: number,
* imagePreviewNode?: HTMLImageElement,
* }} params - Single object passed
*
* @returns { Promise<FunctionReturn> } - Return Object
*/
module.exports = async function imageInputFileToBase64({ imageInputFile, maxWidth, imagePreviewNode }) {
module.exports = async function imageInputFileToBase64({
imageInputFile,
maxWidth,
imagePreviewNode,
}) {
/**
* Make https request
*
@ -58,8 +62,14 @@ module.exports = async function imageInputFileToBase64({ imageInputFile, maxWidt
if (MAX_WIDTH) {
const scaleSize = MAX_WIDTH / img.naturalWidth;
canvas.width = img.naturalWidth < MAX_WIDTH ? img.naturalWidth : MAX_WIDTH;
canvas.height = img.naturalWidth < MAX_WIDTH ? img.naturalHeight : img.naturalHeight * scaleSize;
canvas.width =
img.naturalWidth < MAX_WIDTH
? img.naturalWidth
: MAX_WIDTH;
canvas.height =
img.naturalWidth < MAX_WIDTH
? img.naturalHeight
: img.naturalHeight * scaleSize;
} else {
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;

View File

@ -14,20 +14,26 @@
*
* @param {{
* imageInput: HTMLInputElement,
* maxWidth: number,
* mimeType: [string='image/jpeg']
* maxWidth?: number,
* mimeType?: [string='image/jpeg']
* }} params - Single object passed
*
* @returns { Promise<FunctionReturn> } - Return Object
*/
module.exports = async function imageInputToBase64({ imageInput, maxWidth, mimeType }) {
module.exports = async function imageInputToBase64({
imageInput,
maxWidth,
mimeType,
}) {
/**
* Make https request
*
* @description make a request to datasquirel.com
*/
try {
let imagePreviewNode = document.querySelector(`[data-imagepreview='image']`);
let imagePreviewNode = document.querySelector(
`[data-imagepreview='image']`
);
let imageName = imageInput.files[0].name.replace(/\..*/, "");
let imageDataBase64;
@ -58,8 +64,14 @@ module.exports = async function imageInputToBase64({ imageInput, maxWidth, mimeT
if (MAX_WIDTH) {
const scaleSize = MAX_WIDTH / img.naturalWidth;
canvas.width = img.naturalWidth < MAX_WIDTH ? img.naturalWidth : MAX_WIDTH;
canvas.height = img.naturalWidth < MAX_WIDTH ? img.naturalHeight : img.naturalHeight * scaleSize;
canvas.width =
img.naturalWidth < MAX_WIDTH
? img.naturalWidth
: MAX_WIDTH;
canvas.height =
img.naturalWidth < MAX_WIDTH
? img.naturalHeight
: img.naturalHeight * scaleSize;
} else {
canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;
@ -71,9 +83,11 @@ module.exports = async function imageInputToBase64({ imageInput, maxWidth, mimeT
const srcEncoded = canvas.toDataURL(MIME_TYPE, QUALITY);
if (imagePreviewNode) {
document.querySelectorAll(`[data-imagepreview='image']`).forEach((img) => {
img.src = srcEncoded;
});
document
.querySelectorAll(`[data-imagepreview='image']`)
.forEach((img) => {
img.src = srcEncoded;
});
}
res(srcEncoded);

View File

@ -1,6 +1,6 @@
{
"name": "datasquirel",
"version": "1.9.5",
"version": "1.9.6",
"description": "Cloud-based SQL data management tool",
"main": "index.js",
"bin": {

9
publish.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
if [ -z "$1" ]; then
msg="Updates"
else
msg="$1"
fi
git add . && git commit -m "$msg" && git push && npm publish

9
push.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
if [ -z "$1" ]; then
msg="Updates"
else
msg="$1"
fi
git add . && git commit -m "$msg" && git push