mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-12 01:36:54 +02:00
fix: prevent ENOENT on scheduled reel publishing when local file deleted early
- facebook.ts: use resolvePublicUrl + getMediaBuffer for reels so missing local files fall back to HTTP fetch. - scheduler.ts: only delete local video files after the last pending scheduled post for that postId is published. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
37aba33425
commit
d763be6322
2 files changed
+12
-8
No files matched your search
@@ -72,11 +72,9 @@ export class FacebookService {
|
||||
throw new Error('Reels require a video media');
|
||||
}
|
||||
|
||||
// Upload video bytes directly — Facebook cannot fetch local/Docker URLs
|
||||
const localPath = videoMedia.originalUrl.startsWith('/')
|
||||
? path.join(process.cwd(), videoMedia.originalUrl)
|
||||
: videoMedia.originalUrl;
|
||||
const nodeBuffer = await fs.promises.readFile(localPath);
|
||||
// Use public URL so getMediaBuffer can fetch via HTTP if local file is missing
|
||||
const publicUrl = resolvePublicUrl(videoMedia.originalUrl);
|
||||
const nodeBuffer = await this.getMediaBuffer(publicUrl);
|
||||
return await this.publishVideoFromBuffer(page, nodeBuffer, post.content);
|
||||
} else {
|
||||
// Default to feed
|
||||
|
||||
@@ -125,12 +125,18 @@ export class SchedulerService {
|
||||
status: "published",
|
||||
});
|
||||
|
||||
// Delete local video files immediately after successful publishing
|
||||
// Delete local video files only when no other unpublished scheduled posts reference them
|
||||
for (const mediaItem of mediaList) {
|
||||
if (mediaItem.type === 'video' && mediaItem.cloudinaryPublicId) {
|
||||
try {
|
||||
await storageService.deleteMedia(mediaItem.cloudinaryPublicId, mediaItem.userId, 'video');
|
||||
console.log(`[Scheduler] Deleted local video file for media ${mediaItem.id}`);
|
||||
const remainingScheduled = await storage.getScheduledPostsByPost(post.id);
|
||||
const hasPending = remainingScheduled.some(sp => !sp.publishedAt);
|
||||
if (!hasPending) {
|
||||
await storageService.deleteMedia(mediaItem.cloudinaryPublicId, mediaItem.userId, 'video');
|
||||
console.log(`[Scheduler] Deleted local video file for media ${mediaItem.id}`);
|
||||
} else {
|
||||
console.log(`[Scheduler] Kept local video file for media ${mediaItem.id} (pending scheduled posts still exist)`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(`[Scheduler] Failed to delete local video file for media ${mediaItem.id}:`, err);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user