diff --git a/src/events/gm/sprite/Remove.ts b/src/events/gm/sprite/Remove.ts index 190d891..31926f0 100644 --- a/src/events/gm/sprite/Remove.ts +++ b/src/events/gm/sprite/Remove.ts @@ -20,26 +20,26 @@ export default function (socket: TSocket, io: Server) { } try { + // get root path + const public_folder = path.join(process.cwd(), 'public', 'sprites') + + // remove the sprite folder from the disk + const finalFilePath = path.join(public_folder, data.id) + + // check if the folder exists + if (fs.existsSync(finalFilePath)) { + // then remove + fs.rmdirSync(finalFilePath) + } + await prisma.sprite.delete({ where: { id: data.id } }) - // get root path - const public_folder = path.join(process.cwd(), 'public', 'sprites') + callback(true) - // remove the tile from the disk - const finalFilePath = path.join(public_folder, data.id + '.png') - fs.unlink(finalFilePath, (err) => { - if (err) { - console.log(err) - callback(false) - return - } - - callback(true) - }) } catch (e) { console.log(e) callback(false)