@ -175,12 +175,16 @@ app.post('/image', uploadMulter.single('image'), async (req, res) => {
const currentDate = new Date ( ) . toISOString ( ) ;
const currentDate = new Date ( ) . toISOString ( ) ;
const localFile = reqFile . path . startsWith ( uploadDir + '/' ) ? reqFile . path . substring ( uploadDir . length + 1 ) : reqFile . path ;
const localFile = reqFile . path . startsWith ( uploadDir + '/' ) ? reqFile . path . substring ( uploadDir . length + 1 ) : reqFile . path ;
const finalUrl = ` https:// ${ imageServer } / ${ fileName } ` ;
const finalUrl = ` https:// ${ imageServer } / ${ fileName } ` ;
const claimType = req . body . claimType ;
const handleId = req . body . handleId ;
await new Promise ( ( resolve , reject ) => {
await new Promise ( ( resolve , reject ) => {
db . run (
db . run (
'INSERT INTO image (time, did, local_file, size, final_file, url) VALUES (?, ?, ?, ?, ?, ?)' ,
'INSERT INTO image (time, did, claim_type, handle_id, local_file, size, final_file, url) VALUES (?, ?, ?, ?, ?, ?, ?, ?)' ,
[
[
currentDate ,
currentDate ,
issuerDid ,
issuerDid ,
claimType ,
handleId ,
localFile ,
localFile ,
reqFile . size ,
reqFile . size ,
fileName ,
fileName ,
@ -272,6 +276,7 @@ app.delete('/image/:url', async (req, res) => {
) ;
) ;
} ) ;
} ) ;
if ( ! thisUserImageFile ) {
if ( ! thisUserImageFile ) {
console . log ( 'No image entry found for user' , issuerDid , '& URL' , url , 'so returning 404.' ) ;
return res . status ( 404 ) . send ( JSON . stringify ( { success : false , message : 'No image entry found for user ' + issuerDid + ' & URL ' + url } ) ) ;
return res . status ( 404 ) . send ( JSON . stringify ( { success : false , message : 'No image entry found for user ' + issuerDid + ' & URL ' + url } ) ) ;
}
}
@ -282,7 +287,7 @@ app.delete('/image/:url', async (req, res) => {
[ url , issuerDid ] ,
[ url , issuerDid ] ,
( dbErr , row ) => {
( dbErr , row ) => {
if ( dbErr ) {
if ( dbErr ) {
console . error ( currentDate , 'Error getting image for user from database:' , dbErr )
console . error ( currentDate , 'Error getting image for other users from database:' , dbErr )
reject ( dbErr ) ;
reject ( dbErr ) ;
}
}
resolve ( row ? . did ) ;
resolve ( row ? . did ) ;