mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-24 07:28:11 +02:00
Add Docker support and installation guide for easy server deployment
Includes a Dockerfile for building the application image and an INSTALLATION.md file detailing the setup process, prerequisites, and helpful commands for managing the application on a private server. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/ds3R7vP
This commit is contained in:
1 parent
bbad954935
commit
f881f668a6
89 files changed
+17095
No files matched your search
@@ -0,0 +1,213 @@
|
||||
import {
|
||||
users,
|
||||
socialPages,
|
||||
media,
|
||||
posts,
|
||||
scheduledPosts,
|
||||
aiGenerations,
|
||||
type User,
|
||||
type InsertUser,
|
||||
type SocialPage,
|
||||
type InsertSocialPage,
|
||||
type Media,
|
||||
type InsertMedia,
|
||||
type Post,
|
||||
type InsertPost,
|
||||
type ScheduledPost,
|
||||
type InsertScheduledPost,
|
||||
type AiGeneration,
|
||||
type InsertAiGeneration,
|
||||
} from "@shared/schema";
|
||||
import { db } from "./db";
|
||||
import { eq, and, gte, lte, desc, isNull } from "drizzle-orm";
|
||||
|
||||
export interface IStorage {
|
||||
// Users
|
||||
getUser(id: string): Promise<User | undefined>;
|
||||
getUserByUsername(username: string): Promise<User | undefined>;
|
||||
createUser(user: InsertUser): Promise<User>;
|
||||
|
||||
// Social Pages
|
||||
getSocialPages(userId: string): Promise<SocialPage[]>;
|
||||
getSocialPage(id: string): Promise<SocialPage | undefined>;
|
||||
createSocialPage(page: InsertSocialPage): Promise<SocialPage>;
|
||||
updateSocialPage(id: string, page: Partial<InsertSocialPage>): Promise<SocialPage>;
|
||||
deleteSocialPage(id: string): Promise<void>;
|
||||
|
||||
// Media
|
||||
getMedia(userId: string): Promise<Media[]>;
|
||||
getMediaById(id: string): Promise<Media | undefined>;
|
||||
createMedia(media: InsertMedia): Promise<Media>;
|
||||
deleteMedia(id: string): Promise<void>;
|
||||
|
||||
// Posts
|
||||
getPosts(userId: string): Promise<Post[]>;
|
||||
getPost(id: string): Promise<Post | undefined>;
|
||||
createPost(post: InsertPost): Promise<Post>;
|
||||
updatePost(id: string, post: Partial<InsertPost>): Promise<Post>;
|
||||
deletePost(id: string): Promise<void>;
|
||||
|
||||
// Scheduled Posts
|
||||
getScheduledPosts(userId: string, startDate?: Date, endDate?: Date): Promise<ScheduledPost[]>;
|
||||
getScheduledPost(id: string): Promise<ScheduledPost | undefined>;
|
||||
createScheduledPost(scheduledPost: InsertScheduledPost): Promise<ScheduledPost>;
|
||||
updateScheduledPost(id: string, scheduledPost: Partial<ScheduledPost>): Promise<ScheduledPost>;
|
||||
deleteScheduledPost(id: string): Promise<void>;
|
||||
getPendingScheduledPosts(): Promise<ScheduledPost[]>;
|
||||
|
||||
// AI Generations
|
||||
getAiGenerations(userId: string): Promise<AiGeneration[]>;
|
||||
createAiGeneration(generation: InsertAiGeneration): Promise<AiGeneration>;
|
||||
}
|
||||
|
||||
export class DatabaseStorage implements IStorage {
|
||||
// Users
|
||||
async getUser(id: string): Promise<User | undefined> {
|
||||
const [user] = await db.select().from(users).where(eq(users.id, id));
|
||||
return user || undefined;
|
||||
}
|
||||
|
||||
async getUserByUsername(username: string): Promise<User | undefined> {
|
||||
const [user] = await db.select().from(users).where(eq(users.username, username));
|
||||
return user || undefined;
|
||||
}
|
||||
|
||||
async createUser(insertUser: InsertUser): Promise<User> {
|
||||
const [user] = await db.insert(users).values(insertUser).returning();
|
||||
return user;
|
||||
}
|
||||
|
||||
// Social Pages
|
||||
async getSocialPages(userId: string): Promise<SocialPage[]> {
|
||||
return await db.select().from(socialPages).where(eq(socialPages.userId, userId));
|
||||
}
|
||||
|
||||
async getSocialPage(id: string): Promise<SocialPage | undefined> {
|
||||
const [page] = await db.select().from(socialPages).where(eq(socialPages.id, id));
|
||||
return page || undefined;
|
||||
}
|
||||
|
||||
async createSocialPage(page: InsertSocialPage): Promise<SocialPage> {
|
||||
const [newPage] = await db.insert(socialPages).values(page).returning();
|
||||
return newPage;
|
||||
}
|
||||
|
||||
async updateSocialPage(id: string, page: Partial<InsertSocialPage>): Promise<SocialPage> {
|
||||
const [updated] = await db.update(socialPages).set(page).where(eq(socialPages.id, id)).returning();
|
||||
return updated;
|
||||
}
|
||||
|
||||
async deleteSocialPage(id: string): Promise<void> {
|
||||
await db.delete(socialPages).where(eq(socialPages.id, id));
|
||||
}
|
||||
|
||||
// Media
|
||||
async getMedia(userId: string): Promise<Media[]> {
|
||||
return await db.select().from(media).where(eq(media.userId, userId)).orderBy(desc(media.createdAt));
|
||||
}
|
||||
|
||||
async getMediaById(id: string): Promise<Media | undefined> {
|
||||
const [mediaItem] = await db.select().from(media).where(eq(media.id, id));
|
||||
return mediaItem || undefined;
|
||||
}
|
||||
|
||||
async createMedia(mediaItem: InsertMedia): Promise<Media> {
|
||||
const [newMedia] = await db.insert(media).values(mediaItem).returning();
|
||||
return newMedia;
|
||||
}
|
||||
|
||||
async deleteMedia(id: string): Promise<void> {
|
||||
await db.delete(media).where(eq(media.id, id));
|
||||
}
|
||||
|
||||
// Posts
|
||||
async getPosts(userId: string): Promise<Post[]> {
|
||||
return await db.select().from(posts).where(eq(posts.userId, userId)).orderBy(desc(posts.createdAt));
|
||||
}
|
||||
|
||||
async getPost(id: string): Promise<Post | undefined> {
|
||||
const [post] = await db.select().from(posts).where(eq(posts.id, id));
|
||||
return post || undefined;
|
||||
}
|
||||
|
||||
async createPost(post: InsertPost): Promise<Post> {
|
||||
const [newPost] = await db.insert(posts).values(post).returning();
|
||||
return newPost;
|
||||
}
|
||||
|
||||
async updatePost(id: string, post: Partial<InsertPost>): Promise<Post> {
|
||||
const [updated] = await db.update(posts).set({ ...post, updatedAt: new Date() }).where(eq(posts.id, id)).returning();
|
||||
return updated;
|
||||
}
|
||||
|
||||
async deletePost(id: string): Promise<void> {
|
||||
await db.delete(posts).where(eq(posts.id, id));
|
||||
}
|
||||
|
||||
// Scheduled Posts
|
||||
async getScheduledPosts(userId: string, startDate?: Date, endDate?: Date): Promise<ScheduledPost[]> {
|
||||
let query = db
|
||||
.select()
|
||||
.from(scheduledPosts)
|
||||
.innerJoin(posts, eq(scheduledPosts.postId, posts.id))
|
||||
.where(eq(posts.userId, userId));
|
||||
|
||||
if (startDate && endDate) {
|
||||
const results = await query;
|
||||
return results
|
||||
.filter(r => {
|
||||
const scheduledAt = new Date(r.scheduled_posts.scheduledAt);
|
||||
return scheduledAt >= startDate && scheduledAt <= endDate;
|
||||
})
|
||||
.map(r => r.scheduled_posts);
|
||||
}
|
||||
|
||||
const results = await query;
|
||||
return results.map(r => r.scheduled_posts);
|
||||
}
|
||||
|
||||
async getScheduledPost(id: string): Promise<ScheduledPost | undefined> {
|
||||
const [scheduledPost] = await db.select().from(scheduledPosts).where(eq(scheduledPosts.id, id));
|
||||
return scheduledPost || undefined;
|
||||
}
|
||||
|
||||
async createScheduledPost(scheduledPost: InsertScheduledPost): Promise<ScheduledPost> {
|
||||
const [newScheduledPost] = await db.insert(scheduledPosts).values(scheduledPost).returning();
|
||||
return newScheduledPost;
|
||||
}
|
||||
|
||||
async updateScheduledPost(id: string, scheduledPost: Partial<ScheduledPost>): Promise<ScheduledPost> {
|
||||
const [updated] = await db.update(scheduledPosts).set(scheduledPost).where(eq(scheduledPosts.id, id)).returning();
|
||||
return updated;
|
||||
}
|
||||
|
||||
async deleteScheduledPost(id: string): Promise<void> {
|
||||
await db.delete(scheduledPosts).where(eq(scheduledPosts.id, id));
|
||||
}
|
||||
|
||||
async getPendingScheduledPosts(): Promise<ScheduledPost[]> {
|
||||
const now = new Date();
|
||||
const results = await db
|
||||
.select()
|
||||
.from(scheduledPosts)
|
||||
.where(
|
||||
and(
|
||||
isNull(scheduledPosts.publishedAt),
|
||||
lte(scheduledPosts.scheduledAt, now)
|
||||
)
|
||||
);
|
||||
return results;
|
||||
}
|
||||
|
||||
// AI Generations
|
||||
async getAiGenerations(userId: string): Promise<AiGeneration[]> {
|
||||
return await db.select().from(aiGenerations).where(eq(aiGenerations.userId, userId)).orderBy(desc(aiGenerations.createdAt));
|
||||
}
|
||||
|
||||
async createAiGeneration(generation: InsertAiGeneration): Promise<AiGeneration> {
|
||||
const [newGeneration] = await db.insert(aiGenerations).values(generation).returning();
|
||||
return newGeneration;
|
||||
}
|
||||
}
|
||||
|
||||
export const storage = new DatabaseStorage();
|
||||
Reference in new issue
Block a user