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

View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "datasquirel", "name": "datasquirel",
"version": "1.9.5", "version": "1.9.6",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "index.js", "main": "index.js",
"bin": { "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