2024-11-05 11:12:42 +00:00
"use strict" ;
( ( ) => {
var exports = { } ;
exports . id = 1659 ;
exports . ids = [ 1659 ] ;
exports . modules = {
/***/ 2261 :
/***/ ( ( module ) => {
module . exports = require ( "serverless-mysql" ) ;
/***/ } ) ,
/***/ 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" ) ;
/***/ } ) ,
/***/ 7918 :
/***/ ( ( _ _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 _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ = _ _webpack _require _ _ ( 2163 ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ = _ _webpack _require _ _ ( 6825 ) ;
/* harmony import */ var _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _userAuth _ _WEBPACK _IMPORTED _MODULE _2 _ _ ) ;
// @ts-check
/ * *
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* Imports
* === === === === === === === === === === === === === === === === === === === === === === === === === ===
* / c o n s t f s = _ _ w e b p a c k _ r e q u i r e _ _ ( 7 1 4 7 ) ;
const path = _ _webpack _require _ _ ( 1017 ) ;
const { execSync } = _ _webpack _require _ _ ( 2081 ) ;
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ / * *
* 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 ! = = " G E T " ) r e t u r n r e s . j s o n ( {
msg : "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 _ 2 _ _ _ d e f a u l t ( ) ( r e q , r e s ) ;
if ( ! user ) {
return res . json ( {
success : false ,
msg : "Unauthorized"
} ) ;
}
/ * *
* Send Response
*
* @ description Send a boolean response
* / t r y {
/ * *
* Create new user folder and file
*
* @ description Create new user folder and file
* / c o n s t i s P r o d u c t i o n = " p r o d u c t i o n " . m a t c h ( / p r o d u c t i o n / ) ;
/ * *
* Create new user folder and file
*
* @ description Create new user folder and file
* / c o n s t d i s k U s a g e D b = a w a i t _ p a c k a g e _ s h a r e d _ u t i l s _ b a c k e n d _ g l o b a l _ d b _ D B _ H A N D L E R _ _ W E B P A C K _ I M P O R T E D _ M O D U L E _ 0 _ _ _ d e f a u l t ( ) ( `
SELECT table _schema ,
SUM ( ( data _length + index _length ) / 1024 / 1024 ) AS "mb" from
information _schema . tables
where table _schema like ?
group by table _schema
` , [
` datasquirel_user_ ${ user . id } % `
] ) ;
const totalDbDiskUsageInMb = diskUsageDb . reduce ( ( /** @type {any} */ prev , /** @type {any} */ current , /** @type {Number} */ currentIndex ) => {
if ( prev ? . mb ) {
return prev . mb + current . mb ;
} else {
return prev + current . mb ;
}
} , 0 ) ;
/ * *
* Create new user folder and file
*
* @ description Create new user folder and file
* / l e t t o t a l F i l e U s a g e I n M b = 0 ;
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!" ) ;
}
if ( ! STATIC _ROOT && ! fs . existsSync ( STATIC _ROOT ) ) {
fs . mkdirSync ( STATIC _ROOT , {
recursive : true
} ) ;
}
const USER _STATIC _DIR = path . join ( STATIC _ROOT , ` images/user-images/user- ${ user . id } ` ) ;
if ( ! fs . existsSync ( USER _STATIC _DIR ) ) {
fs . mkdirSync ( USER _STATIC _DIR , {
recursive : true
} ) ;
}
const userMediaFilePath = path . join ( STATIC _ROOT , ` images/user-images/user- ${ user . id } ` ) ;
const userVideosPath = path . join ( STATIC _ROOT , ` videos/user-videos/user- ${ user . id } ` ) ;
if ( ! fs . existsSync ( userVideosPath ) ) {
fs . mkdirSync ( userVideosPath , {
recursive : true
} ) ;
}
async function readFolders ( /** @type {String} */ path ) {
try {
const userMediaFiles = fs . readdirSync ( path ) ;
for ( let i = 0 ; i < userMediaFiles . length ; i ++ ) {
const file = userMediaFiles [ i ] ;
const fileFullPath = path + "/" + file ;
if ( ! file . match ( /\..{3,4}$/ ) ) {
await readFolders ( fileFullPath ) ;
continue ;
}
if ( fs . existsSync ( fileFullPath ) ) {
const fileSize = fs . statSync ( fileFullPath ) ;
totalFileUsageInMb += fileSize . size / 1024 / 1024 ;
} else {
const isProduction = "production" . match ( /production/ ) ;
if ( ! STATIC _ROOT ) {
console . log ( "Static File ENV not Found!" ) ;
throw new Error ( "No Static Path!" ) ;
}
const userMediaUrl = fileFullPath . replace ( STATIC _ROOT , process . env . DSQL _STATIC _HOST || "" ) ;
const userMediaPath = fileFullPath . replace ( STATIC _ROOT , "" ) ;
const deleteMedia = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default ( ) ( ` DELETE FROM user_media WHERE media_path = ? OR media_thumbnail_path = ? OR media_url=? OR media_thumbnail_url=? ` , [
userMediaPath ,
userMediaPath ,
userMediaUrl ,
userMediaUrl ,
] ) ;
console . log ( ` MEDIA => ${ userMediaUrl } DELETED FROM DATABASE ` ) ;
}
}
} catch ( /** @type {any} */ error ) {
console . log ( "ERROR in getDiskUsage API route =>" , error . message ) ;
_functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default ( ) ( {
component : "/api/getDiskUsage/lines-93-101" ,
message : error . message
} ) ;
}
}
await readFolders ( userMediaFilePath ) ;
await readFolders ( userVideosPath ) ;
const totalUsageInMb = totalFileUsageInMb + totalDbDiskUsageInMb ;
res . json ( {
success : true ,
total : totalUsageInMb
} ) ;
////////////////////////////////////////
} catch ( /** @type {any} */ error ) {
////////////////////////////////////////
_functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default ( ) ( {
component : "/api/getDiskUsage/main-catch-error" ,
message : error . message ,
user : user
} ) ;
res . json ( {
success : false ,
msg : "Disk Usage Calculation Error!"
} ) ;
////////////////////////////////////////
}
}
/***/ } )
} ;
;
// 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 ] , ( ) => ( _ _webpack _exec _ _ ( 7918 ) ) ) ;
2024-11-05 11:12:42 +00:00
module . exports = _ _webpack _exports _ _ ;
} ) ( ) ;