2024-11-05 11:12:42 +00:00
"use strict" ;
( ( ) => {
var exports = { } ;
exports . id = 4196 ;
exports . ids = [ 4196 ] ;
exports . modules = {
/***/ 4809 :
/***/ ( ( module ) => {
module . exports = require ( "node-fetch" ) ;
/***/ } ) ,
/***/ 5184 :
/***/ ( ( module ) => {
module . exports = require ( "nodemailer" ) ;
/***/ } ) ,
/***/ 6109 :
/***/ ( ( module ) => {
module . exports = require ( "sanitize-html" ) ;
/***/ } ) ,
/***/ 2261 :
/***/ ( ( module ) => {
module . exports = require ( "serverless-mysql" ) ;
/***/ } ) ,
/***/ 7441 :
/***/ ( ( module ) => {
module . exports = require ( "sharp" ) ;
/***/ } ) ,
/***/ 4300 :
/***/ ( ( module ) => {
module . exports = require ( "buffer" ) ;
/***/ } ) ,
/***/ 2081 :
/***/ ( ( module ) => {
module . exports = require ( "child_process" ) ;
/***/ } ) ,
/***/ 6113 :
/***/ ( ( module ) => {
module . exports = require ( "crypto" ) ;
/***/ } ) ,
/***/ 7147 :
/***/ ( ( module ) => {
module . exports = require ( "fs" ) ;
/***/ } ) ,
/***/ 3685 :
/***/ ( ( module ) => {
module . exports = require ( "http" ) ;
/***/ } ) ,
/***/ 1017 :
/***/ ( ( module ) => {
module . exports = require ( "path" ) ;
/***/ } ) ,
/***/ 4142 :
/***/ ( ( module , _ _unused _webpack _exports , _ _webpack _require _ _ ) => {
// @ts-check
const nodeFetch = _ _webpack _require _ _ ( 4809 ) ;
const sharp = _ _webpack _require _ _ ( 7441 ) ;
const serverError = _ _webpack _require _ _ ( 2163 ) ;
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ / * *
*
* @ param { object } params
* @ param { string } params . imageSourceUrl
* @ param { string } params . imageWritePath
* @ param { number } [ params . maxSize ]
* @ param { string } [ params . sourceType ]
* / m o d u l e . e x p o r t s = a s y n c f u n c t i o n f s W r i t e I m a g e T o D i s k ( { i m a g e S o u r c e U r l , i m a g e W r i t e P a t h , m a x S i z e , s o u r c e T y p e , } ) {
try {
async function generateBuffer ( ) {
let imageBuffer ;
if ( sourceType ? . match ( "url" ) ) {
if ( imageSourceUrl . match ( /^http/i ) ) {
let fetchedImage = await nodeFetch ( imageSourceUrl , { } ) ;
imageBuffer = await fetchedImage . buffer ( ) ;
} else {
let readPath = ` ./public ${ imageSourceUrl } ` ;
imageBuffer = readPath ;
}
} else if ( sourceType ? . match ( "base64" ) ) {
imageBuffer = Buffer . from ( imageSourceUrl , "base64" ) ;
}
return imageBuffer ;
}
const buffer = await generateBuffer ( ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
let imagePath = imageWritePath ;
const MAX _SIZE = maxSize ? maxSize : 650 ;
// const sharpImage = sharp(imagePath);
const sharpImageRaw = sharp ( buffer ) ;
// let imageMetadata = await sharpImage.metadata();
let imageMetadataRaw = await sharpImageRaw . metadata ( ) ;
let { width , height , format } = imageMetadataRaw ;
if ( width && height && width > MAX _SIZE ) {
let resizeRatio = MAX _SIZE / width ;
sharpImageRaw . resize ( MAX _SIZE , Math . round ( height * resizeRatio ) , {
fit : "cover"
} ) ;
}
if ( format ) {
sharpImageRaw . toFormat ( format , {
quality : 80
} ) ;
}
await sharpImageRaw . toFile ( imagePath ) ;
// console.log(image);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
// console.log("====================================");
// console.log("Complete!!!");
// console.log("====================================");
} catch ( /** @type {any} */ error ) {
serverError ( {
component : "functions/backend/fsWriteImageToDisk" ,
message : error . message
} ) ;
}
} ; /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
/***/ } ) ,
/***/ 9662 :
/***/ ( ( _ _unused _webpack _module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) => {
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
/* harmony export */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
/* harmony export */ "default" : ( ) => ( /* binding */ handler )
/* harmony export */ } ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _0 _ _ = _ _webpack _require _ _ ( 2224 ) ;
/* harmony import */ var _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _0 _ _ ) ;
/* harmony import */ var _package _shared _functions _backend _encrypt _ _WEBPACK _IMPORTED _MODULE _1 _ _ = _ _webpack _require _ _ ( 7547 ) ;
/* harmony import */ var _package _shared _functions _backend _encrypt _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _functions _backend _encrypt _ _WEBPACK _IMPORTED _MODULE _1 _ _ ) ;
/* harmony import */ var _functions _backend _fsWriteImageToDisk _ _WEBPACK _IMPORTED _MODULE _2 _ _ = _ _webpack _require _ _ ( 4142 ) ;
/* harmony import */ var _functions _backend _fsWriteImageToDisk _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _fsWriteImageToDisk _ _WEBPACK _IMPORTED _MODULE _2 _ _ ) ;
/* harmony import */ var _functions _backend _handleNodemailer _ _WEBPACK _IMPORTED _MODULE _3 _ _ = _ _webpack _require _ _ ( 6926 ) ;
/* harmony import */ var _functions _backend _handleNodemailer _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _handleNodemailer _ _WEBPACK _IMPORTED _MODULE _3 _ _ ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _4 _ _ = _ _webpack _require _ _ ( 2163 ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _4 _ _ ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _5 _ _ = _ _webpack _require _ _ ( 6825 ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _5 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _5 _ _ ) ;
/* harmony import */ var path _ _WEBPACK _IMPORTED _MODULE _6 _ _ = _ _webpack _require _ _ ( 1017 ) ;
/* harmony import */ var path _ _WEBPACK _IMPORTED _MODULE _6 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( path _ _WEBPACK _IMPORTED _MODULE _6 _ _ ) ;
/* harmony import */ var child _process _ _WEBPACK _IMPORTED _MODULE _7 _ _ = _ _webpack _require _ _ ( 2081 ) ;
/* harmony import */ var child _process _ _WEBPACK _IMPORTED _MODULE _7 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( child _process _ _WEBPACK _IMPORTED _MODULE _7 _ _ ) ;
/* harmony import */ var _package _shared _functions _backend _db _updateDbEntry _ _WEBPACK _IMPORTED _MODULE _8 _ _ = _ _webpack _require _ _ ( 5886 ) ;
/* harmony import */ var _package _shared _functions _backend _db _updateDbEntry _ _WEBPACK _IMPORTED _MODULE _8 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _functions _backend _db _updateDbEntry _ _WEBPACK _IMPORTED _MODULE _8 _ _ ) ;
// @ts-check
const fs = _ _webpack _require _ _ ( 7147 ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ / * *
* API handler
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* @ type { import ( "next" ) . NextApiHandler }
* / a s y n c f u n c t i o n h a n d l e r ( r e q , r e s ) {
/ * *
* Check method
*
* @ description Check request method and return if invalid
* / i f ( r e q . m e t h o d ! = = " P O S T " ) r e t u r n r e s . j s o n ( {
user : null ,
msg : "Registration Failed!"
} ) ;
/ * *
* User auth
*
* @ description Authenticate user
* / c o n s t u s e r = a w a i t _ f u n c t i o n s _ b a c k e n d _ u s e r A u t h _ _ W E B P A C K _ I M P O R T E D _ M O D U L E _ 5 _ _ _ d e f a u l t ( ) ( r e q , r e s , t r u e ) ;
if ( ! user ) {
return res . json ( {
success : false ,
msg : "Unauthorized"
} ) ;
}
/ * *
* Validate Form
*
* @ description Check if request body is valid
* / c o n s t s a n i t i z e d R e q B o d y = r e q . b o d y ;
const { first _name , last _name , image } = sanitizedReqBody ;
/ * *
* Validate Form
*
* @ description Check if request body is valid
* / t r y {
////////////////////////////////////////
const existingImage = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default ( ) ( ` SELECT image FROM users WHERE id=' ${ user . id } ' ` ) ;
let isImageExisting = existingImage [ 0 ] . image === image ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
const STATIC _ROOT = process . env . DSQL _STATIC _SERVER _DIR ;
if ( ! STATIC _ROOT ) {
console . log ( "Static File ENV not Found!" ) ;
throw new Error ( "No Static Path!" ) ;
}
/ * *
* Create new user folder and file
*
* @ description Create new user folder and file
* / l e t i m a g e P a t h = p a t h _ _ W E B P A C K _ I M P O R T E D _ M O D U L E _ 6 _ _ _ d e f a u l t ( ) . j o i n ( S T A T I C _ R O O T , ` i m a g e s / u s e r - i m a g e s / u s e r - $ { u s e r . i d } / u s e r - $ { u s e r . i d } - p r o f i l e . j p g ` ) ;
let imageThumbnailPath = path _ _WEBPACK _IMPORTED _MODULE _6 _ _ _default ( ) . join ( STATIC _ROOT , ` images/user-images/user- ${ user . id } /user- ${ user . id } -profile-thumbnail.jpg ` ) ;
if ( ! isImageExisting ) {
let writeImage = await _functions _backend _fsWriteImageToDisk _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default ( ) ( {
imageSourceUrl : typeof image === "string" ? image : image . imageBase64 ,
imageWritePath : imagePath ,
sourceType : typeof image === "string" ? "url" : "base64"
} ) ;
let writeImageThumbnail = await _functions _backend _fsWriteImageToDisk _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default ( ) ( {
imageSourceUrl : typeof image === "string" ? image : image . imageBase64 ,
imageWritePath : imageThumbnailPath ,
maxSize : 250 ,
sourceType : typeof image === "string" ? "url" : "base64"
} ) ;
( 0 , child _process _ _WEBPACK _IMPORTED _MODULE _7 _ _ . execSync ) ( ` chmod 644 ${ imagePath } ${ imageThumbnailPath } ` ) ;
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
let imageUrl = imagePath . replace ( STATIC _ROOT , process . env . DSQL _STATIC _HOST || "" ) ;
let imageThumbnailUrl = imageThumbnailPath . replace ( STATIC _ROOT , process . env . DSQL _STATIC _HOST || "" ) ;
const updatedUser = await _package _shared _functions _backend _db _updateDbEntry _ _WEBPACK _IMPORTED _MODULE _8 _ _ _default ( ) ( {
dbFullName : "datasquirel" ,
tableName : "users" ,
identifierColumnName : "id" ,
identifierValue : user . id ,
data : {
first _name ,
last _name ,
image : imageUrl ,
image _thumbnail : imageThumbnailUrl
}
} ) ;
const updatedUserUser = await _package _shared _functions _backend _db _updateDbEntry _ _WEBPACK _IMPORTED _MODULE _8 _ _ _default ( ) ( {
dbFullName : "datasquirel" ,
tableName : "user_users" ,
identifierColumnName : "invited_user_id" ,
identifierValue : user . id ,
data : {
first _name ,
last _name ,
image : imageUrl ,
image _thumbnail : imageThumbnailUrl
}
} ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
res . json ( {
user : true
} ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} catch ( /** @type {any} */ error ) {
_functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default ( ) ( {
component : "/api/updateUser/main-catch-error" ,
message : error . message ,
user : user
} ) ;
res . json ( {
user : null
} ) ;
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
/***/ } )
} ;
;
// load runtime
var _ _webpack _require _ _ = require ( "../../webpack-api-runtime.js" ) ;
_ _webpack _require _ _ . C ( exports ) ;
var _ _webpack _exec _ _ = ( moduleId ) => ( _ _webpack _require _ _ ( _ _webpack _require _ _ . s = moduleId ) )
2024-11-05 14:18:40 +00:00
var _ _webpack _exports _ _ = _ _webpack _require _ _ . X ( 0 , [ 2224 , 2163 , 6825 , 3017 , 3403 , 7547 , 5886 , 6926 ] , ( ) => ( _ _webpack _exec _ _ ( 9662 ) ) ) ;
2024-11-05 11:12:42 +00:00
module . exports = _ _webpack _exports _ _ ;
} ) ( ) ;