Skip to content
Snippets Groups Projects
Commit d9a424c5 authored by davidkarelh's avatar davidkarelh
Browse files

Add delete azure blob file

parent 812760ad
Tags
2 merge requests!30Sprint 5,!29Add delete azure blob file
This diff is collapsed.
{
"dependencies": {
"@azure/storage-blob": "^12.14.0",
"@prisma/client": "^4.9.0",
"@types/request": "^2.48.8",
"cors": "^2.8.5",
......
import { PrismaClient } from '@prisma/client'
import * as fs from 'fs'
import { MulterOutFile } from 'multer-azure-blob-storage'
import deleteAzureBlob from '../utils/delete-image'
const prisma = new PrismaClient()
export const getFields = async (req: any, res: any) => {
......@@ -182,6 +183,8 @@ export const updateFieldWithFile = async (req: any, res: any) => {
} else {
if (env !== 'prod') {
fs.unlink(`images/${field.thumbnail}`, (err) => {});
} else {
await deleteAzureBlob(`images/${field.thumbnail}`);
}
}
} catch (error) {
......@@ -242,6 +245,8 @@ export const deleteField = async (req: any, res: any) => {
} else {
if (env !== 'prod') {
fs.unlink(`images/${field.thumbnail}`, (err) => {});
} else {
await deleteAzureBlob(`images/${field.thumbnail}`);
}
}
......
import { PrismaClient } from '@prisma/client'
import * as fs from 'fs'
import { MulterOutFile } from 'multer-azure-blob-storage'
import deleteAzureBlob from '../utils/delete-image'
const prisma = new PrismaClient()
......@@ -144,6 +145,8 @@ export const editTournamentWithFile = async (req: any, res: any) => {
} else {
if (env !== 'prod') {
fs.unlink(`images/${tournament.thumbnail}`, () => {})
} else {
await deleteAzureBlob(`images/${tournament.thumbnail}`);
}
}
} catch (error) {
......@@ -207,6 +210,8 @@ export const deleteTournament = async (req: any, res: any) => {
} else {
if (env !== 'prod') {
fs.unlink(`images/${tournament.thumbnail}`, () => {})
} else {
await deleteAzureBlob(`images/${tournament.thumbnail}`);
}
}
} catch (error) {
......
import { BlobServiceClient } from "@azure/storage-blob";
const connectionString = process.env.AZURE_STORAGE_CONNECTION_STRING as string;
const containerName = `beast-app-container`;
async function deleteAzureBlob(blobName: string) {
const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobClient = containerClient.getBlobClient(blobName);
await blobClient.deleteIfExists();
}
export default deleteAzureBlob;
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment