π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: replace
Nevo David914b29f00163
diff --git a/libraries/nestjs-libraries/src/database/prisma/media/media.service.ts b/libraries/nestjs-libraries/src/database/prisma/media/media.service.tsindex 307f70c64..1d3106734 100644--- a/libraries/nestjs-libraries/src/database/prisma/media/media.service.ts+++ b/libraries/nestjs-libraries/src/database/prisma/media/media.service.ts@@ -170,11 +170,12 @@ export class MediaService {return media;}- // The normalized file sits next to the original under a derived key, so the- // polling side needs nothing but the media record to know where it landed+ // The normalized file overwrites the original in place; only a container+ // change (mov -> mp4, jpeg -> jpg) lands under a new key. Either way the+ // polling side needs nothing but the media record to know where it isprivate normalizedName(name: string) {const ext = extname(name).toLowerCase();- return `${name.slice(0, -ext.length)}-n.${PROCESSABLE[ext].ext}`;+ return `${name.slice(0, -ext.length)}.${PROCESSABLE[ext].ext}`;}// Returns the processor job id; when this process has nothing to run the@@ -278,6 +279,16 @@ export class MediaService {path: media.path.slice(0, media.path.lastIndexOf('/') + 1) + outputName,fileSize: result.output?.bytes,});++ // a same-key output already replaced the original; a stray object after a+ // container change is harmless, so a failed delete never fails the media+ if (outputName !== media.name) {+ try {+ await this.storage.removeFile(media.name);+ } catch (err) {+ console.error(`Could not remove original media ${media.name}:`, err);+ }+ }return true;}diff --git a/libraries/nestjs-libraries/src/upload/cloudflare.storage.ts b/libraries/nestjs-libraries/src/upload/cloudflare.storage.tsindex e26d10079..748807f9a 100644--- a/libraries/nestjs-libraries/src/upload/cloudflare.storage.ts+++ b/libraries/nestjs-libraries/src/upload/cloudflare.storage.ts@@ -1,4 +1,9 @@-import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';+import {+ S3Client,+ PutObjectCommand,+ GetObjectCommand,+ DeleteObjectCommand,+} from '@aws-sdk/client-s3';import { getSignedUrl } from '@aws-sdk/s3-request-presigner';import 'multer';import { makeId } from '@gitroom/nestjs-libraries/services/make.is';@@ -175,14 +180,19 @@ class CloudflareStorage implements IUploadProvider {);}- // Implement the removeFile method from IUploadProvider+ // Accepts either the public URL or the bare keyasync removeFile(filePath: string): Promise<void> {- // const fileName = filePath.split('/').pop(); // Extract the filename from the path- // const command = new DeleteObjectCommand({- // Bucket: this._bucketName,- // Key: fileName,- // });- // await this._client.send(command);+ const fileName = filePath.split('/').pop();+ if (!fileName) {+ return;+ }++ await this._client.send(+ new DeleteObjectCommand({+ Bucket: this._bucketName,+ Key: fileName,+ })+ );}}