-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Upload files to Azure blob storage account instead of cloudinary #476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d3f98db
40c2192
bf954e5
8ff361a
c57fbd8
e9d9fb3
d3f7a70
be70ee3
c382768
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,6 +172,10 @@ export const insertCloudinaryImage = async (eventId: number, values: typeof clou | |
| await db.insert(cloudinaryImage).values(values); | ||
| await db.insert(eventCloudinaryImages).values({ eventId, cloudId: values.cloudId }); | ||
| }; | ||
| export const insertAzureBlob = async (eventId: number, values: (typeof cloudinaryImage.$inferInsert)[]) => { | ||
| await db.insert(cloudinaryImage).values(values); | ||
| await db.insert(eventCloudinaryImages).values(values.map((file) => ({ eventId, cloudId: file.cloudId }))); | ||
| }; | ||
|
|
||
| export const getEventCloudinaryImages = async (eventId: number) => { | ||
| return await db | ||
|
|
@@ -180,15 +184,16 @@ export const getEventCloudinaryImages = async (eventId: number) => { | |
| cloudUrl: cloudinaryImage.cloudUrl, | ||
| width: cloudinaryImage.width, | ||
| height: cloudinaryImage.height, | ||
| type: cloudinaryImage.type, | ||
| }) | ||
| .from(eventCloudinaryImages) | ||
| .innerJoin(cloudinaryImage, eq(cloudinaryImage.cloudId, eventCloudinaryImages.cloudId)) | ||
| .orderBy(desc(sql`${eventCloudinaryImages}.rowid`)) | ||
| .where(eq(eventCloudinaryImages.eventId, eventId)); | ||
| .where(and(eq(eventCloudinaryImages.eventId, eventId), eq(cloudinaryImage.isDeleted, false))); | ||
| }; | ||
|
|
||
| export const deleteEventCloudinaryImage = async (cloudId: string) => { | ||
| await db.delete(cloudinaryImage).where(eq(cloudinaryImage.cloudId, cloudId)); | ||
| await db.update(cloudinaryImage).set({ isDeleted: true }).where(eq(cloudinaryImage.cloudId, cloudId)); | ||
| }; | ||
|
Comment on lines
195
to
197
|
||
|
|
||
| export const getNumberOfImages = async (eventId: number) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| import { eq } from "drizzle-orm"; | ||
|
|
||
| import { db } from "db/config.server"; | ||
| import { reportFile } from "db/schema"; | ||
| import { oldReportFiles, reportFiles, cloudinaryImage } from "db/schema"; | ||
|
|
||
| export const insertReportFile = async (values: Omit<typeof reportFile.$inferInsert, "id">) => { | ||
| return await db.insert(reportFile).values(values).returning(); | ||
| export const insertReportFile = async (reportId: string, file: Omit<typeof cloudinaryImage.$inferInsert, "id">) => { | ||
| await db.insert(cloudinaryImage).values(file).returning(); | ||
| await db.insert(reportFiles).values({ fileId: file.cloudId, reportId }); | ||
| }; | ||
|
|
||
| export const getReportFile = async (fileId: string) => { | ||
| const [result] = await db.select().from(reportFile).where(eq(reportFile.id, fileId)); | ||
| const [result] = await db.select().from(oldReportFiles).where(eq(oldReportFiles.id, fileId)); | ||
| return result; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,20 +9,6 @@ cloudinary.v2.config({ | |
| api_secret: process.env.CLOUDINARY_API_SECRET, | ||
| }); | ||
|
|
||
| export const uploadImage = (data: string, folder: string) => { | ||
| return new Promise<UploadApiResponse>((resolve, reject) => { | ||
| void cloudinary.v2.uploader.upload(data, { folder }, (error, result) => { | ||
| if (error) { | ||
| console.error(error); | ||
| reject(error as Error); | ||
| } | ||
| if (result) { | ||
| resolve(result); | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| export const generateZip = (folderName: string, zipName: string) => { | ||
| const zipUrl = cloudinary.v2.utils.download_zip_url({ | ||
| resource_type: "all", | ||
|
|
@@ -33,18 +19,6 @@ export const generateZip = (folderName: string, zipName: string) => { | |
| return zipUrl; | ||
| }; | ||
|
|
||
|
Comment on lines
19
to
21
|
||
| export const deleteImage = (publicId: string) => { | ||
| return new Promise((resolve, reject) => { | ||
| void cloudinary.v2.uploader.destroy(publicId, (error, result) => { | ||
| if (error) { | ||
| reject(error as Error); | ||
| } else { | ||
| resolve(result); | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| export function uploadImageToCloudinary(data: ArrayBuffer, folder: string) { | ||
| const buffer = Buffer.from(data); | ||
| const uploadPromise = new Promise<UploadApiResponse>((resolve, reject) => { | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The insertAzureBlob function does not handle potential database constraint violations or conflicts. If a cloudId already exists in the database (from a previous upload or duplicate UUID), the insert will fail without proper error handling. Consider using an "INSERT OR IGNORE" or "INSERT OR REPLACE" strategy, or adding explicit error handling for duplicate key violations.