2024-11-05 11:12:42 +00:00
"use strict" ;
( ( ) => {
var exports = { } ;
exports . id = 1620 ;
exports . ids = [ 1620 ] ;
exports . modules = {
/***/ 2261 :
/***/ ( ( module ) => {
module . exports = require ( "serverless-mysql" ) ;
/***/ } ) ,
/***/ 4300 :
/***/ ( ( module ) => {
module . exports = require ( "buffer" ) ;
/***/ } ) ,
/***/ 6113 :
/***/ ( ( module ) => {
module . exports = require ( "crypto" ) ;
/***/ } ) ,
/***/ 7147 :
/***/ ( ( module ) => {
module . exports = require ( "fs" ) ;
/***/ } ) ,
/***/ 1017 :
/***/ ( ( module ) => {
module . exports = require ( "path" ) ;
2024-11-05 14:18:40 +00:00
/***/ } ) ,
/***/ 5425 :
/***/ ( ( module , _ _unused _webpack _exports , _ _webpack _require _ _ ) => {
// @ts-check
const { scryptSync , createDecipheriv } = _ _webpack _require _ _ ( 6113 ) ;
const { Buffer } = _ _webpack _require _ _ ( 4300 ) ;
/ * *
* @ param { string } encryptedString
* @ returns { string | null }
* / c o n s t d e c r y p t = ( e n c r y p t e d S t r i n g ) = > {
const algorithm = "aes-192-cbc" ;
const password = process . env . DSQL _ENCRYPTION _PASSWORD || "" ;
const salt = process . env . DSQL _ENCRYPTION _SALT || "" ;
let key = scryptSync ( password , salt , 24 ) ;
let iv = Buffer . alloc ( 16 , 0 ) ;
// @ts-ignore
const decipher = createDecipheriv ( algorithm , key , iv ) ;
try {
let decrypted = decipher . update ( encryptedString , "hex" , "utf8" ) ;
decrypted += decipher . final ( "utf8" ) ;
return decrypted ;
} catch ( error ) {
return null ;
}
} ;
module . exports = decrypt ;
2024-11-05 11:12:42 +00:00
/***/ } ) ,
/***/ 2201 :
/***/ ( ( _ _unused _webpack _module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) => {
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
/* harmony export */ _ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
/* harmony export */ "config" : ( ) => ( /* binding */ config ) ,
/* 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 _db _deleteDbEntry _ _WEBPACK _IMPORTED _MODULE _1 _ _ = _ _webpack _require _ _ ( 6147 ) ;
/* harmony import */ var _package _shared _functions _backend _db _deleteDbEntry _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _functions _backend _db _deleteDbEntry _ _WEBPACK _IMPORTED _MODULE _1 _ _ ) ;
/* harmony import */ var _package _shared _functions _backend _decrypt _ _WEBPACK _IMPORTED _MODULE _2 _ _ = _ _webpack _require _ _ ( 5425 ) ;
/* harmony import */ var _package _shared _functions _backend _decrypt _ _WEBPACK _IMPORTED _MODULE _2 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _functions _backend _decrypt _ _WEBPACK _IMPORTED _MODULE _2 _ _ ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _3 _ _ = _ _webpack _require _ _ ( 2163 ) ;
/* harmony import */ var _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _3 _ _ ) ;
/* harmony import */ var _package _shared _functions _backend _api _cred _ _WEBPACK _IMPORTED _MODULE _4 _ _ = _ _webpack _require _ _ ( 1007 ) ;
/* harmony import */ var _package _shared _functions _backend _api _cred _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( _package _shared _functions _backend _api _cred _ _WEBPACK _IMPORTED _MODULE _4 _ _ ) ;
// @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 config = {
api : {
bodyParser : {
sizeLimit : "50mb"
}
}
} ;
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** @type {import("next").NextApiHandler} */ async function handler ( req , res ) {
/ * *
* 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 ( {
msg : "Failed!"
} ) ;
/ * *
* Send Response
*
* @ description Send a boolean response
* / l e t r e s u l t s ;
try {
const authorization = req . headers . authorization ;
if ( ! authorization ) {
return res . json ( {
success : false ,
msg : "Unauthorized"
} ) ;
}
const apiCred = _package _shared _functions _backend _api _cred _ _WEBPACK _IMPORTED _MODULE _4 _ _ _default ( ) ( {
key : authorization
} ) ;
if ( ! apiCred ? . user _id ) {
throw new Error ( "Api Credentials invalid!" ) ;
}
const { user _id , full _access } = apiCred ;
if ( ! full _access ) return res . json ( {
success : false ,
msg : "Unauthorized"
} ) ;
/ * *
* User auth
*
* @ description Authenticate user
* / l e t { u r l } = r e q . b o d y ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
const existingMedia = await _package _shared _utils _backend _global _db _DB _HANDLER _ _WEBPACK _IMPORTED _MODULE _0 _ _ _default ( ) ( ` SELECT * FROM user_media WHERE media_url = ? ` , [
url
] ) ;
if ( ! existingMedia ? . length ) {
return res . json ( {
success : false ,
msg : "Media not found!"
} ) ;
}
const { id , folder , media _url , media _thumbnail _url , media _type } = existingMedia [ 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!" ) ;
}
/ * *
*
* @ param { string | null | undefined } path
* @ returns { string }
* / c o n s t f o r m P a t h = ( p a t h ) = > {
if ( ! path ) return "" ;
if ( path ? . match ( /\.\./ ) ) return "" ;
if ( path ? . match ( /^\@/ ) ) {
2024-11-05 14:18:40 +00:00
return path . replace ( /@\/media\// , ` ${ process . env . DSQL _USER _DB _SCHEMA _PATH } /user- ${ user _id } /media/ ` ) ;
2024-11-05 11:12:42 +00:00
}
return path . replace ( process . env . DSQL _STATIC _HOST || "" , STATIC _ROOT ) ;
} ;
const deletePath = formPath ( media _url ) ;
const deleteThumbnailPath = formPath ( media _thumbnail _url ) ;
if ( ! deletePath ? . match ( /./ ) ) {
return res . json ( {
success : false ,
msg : "Invalid path!"
} ) ;
}
try {
fs . unlinkSync ( deletePath ) ;
fs . unlinkSync ( deleteThumbnailPath ) ;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
const removeDuplicateMedia = await _package _shared _functions _backend _db _deleteDbEntry _ _WEBPACK _IMPORTED _MODULE _1 _ _ _default ( ) ( {
dbFullName : "datasquirel" ,
tableName : "user_media" ,
identifierColumnName : "id" ,
identifierValue : id
} ) ;
////////////////////////////////////////
res . json ( {
success : true ,
payload : {
url
}
} ) ;
} catch ( /** @type {any} */ error ) {
console . log ( "File delete error:" , error . message ) ;
////////////////////////////////////////
res . json ( {
success : false ,
payload : {
url
} ,
error : error . message
} ) ;
}
////////////////////////////////////////
} catch ( /** @type {any} */ error1 ) {
////////////////////////////////////////
console . log ( "File write error:" , error1 ) ;
_functions _backend _serverError _ _WEBPACK _IMPORTED _MODULE _3 _ _ _default ( ) ( {
component : "/api/query/delete-file/main-catch-error" ,
message : error1 . message
} ) ;
res . json ( {
success : false ,
msg : "Delete File Error!" ,
error : error1 . message
} ) ;
////////////////////////////////////////
}
}
/***/ } )
} ;
;
// 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 , 3403 , 1007 , 6147 ] , ( ) => ( _ _webpack _exec _ _ ( 2201 ) ) ) ;
2024-11-05 11:12:42 +00:00
module . exports = _ _webpack _exports _ _ ;
} ) ( ) ;