Skip to content

Commit

Permalink
Merge branch 'main' into feature/media-uploader
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesread authored Sep 23, 2024
2 parents 67ca693 + f62f287 commit d7ff7dd
Show file tree
Hide file tree
Showing 198 changed files with 1,382 additions and 2,474 deletions.
87 changes: 58 additions & 29 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
DATABASE_URL=""
REDIS_URL=""
UPLOAD_DIRECTORY=""
NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY=""
NEXT_PUBLIC_STORAGE_PROVIDER="local or cloudflare //default is local"
STORAGE_PROVIDER="local or cloudflare //default is local"
STRIPE_PUBLISHABLE_KEY=""
STRIPE_SECRET_KEY=""
STRIPE_SIGNING_KEY=""
JWT_SECRET=""
FRONTEND_URL=""
MAIN_URL=""
NEXT_PUBLIC_BACKEND_URL=""
BACKEND_INTERNAL_URL=""
# Configuration reference: http://docs.postiz.com/configuration/reference

# === Required Settings
DATABASE_URL="postgresql://postiz-user:postiz-password@localhost:5432/postiz-db-local"
REDIS_URL="redis://localhost:6379"
JWT_SECRET="random string for your JWT secret, make it long"
FRONTEND_URL="http://localhost:4200"
NEXT_PUBLIC_BACKEND_URL="http://localhost:3000"
BACKEND_INTERNAL_URL="http://localhost:3000"

## These are dummy values, you must create your own from Cloudflare.
## Remember to set your public internet IP address in the allow-list for the API token.
##
## Cloudflare is currently required to save things like social media avatars for accounts.
CLOUDFLARE_ACCOUNT_ID="QhcMSXQyPuMCRpSQcSYdEuTYgHeCXHbu"
CLOUDFLARE_ACCESS_KEY="dcfCMSuFEeCNfvByUureMZEfxWJmDqZe"
CLOUDFLARE_SECRET_ACCESS_KEY="zTTMXBmtyLPwHEdpACGHgDgzRTNpTJewiNriLnUS"
CLOUDFLARE_BUCKETNAME="postiz"
CLOUDFLARE_BUCKET_URL="https://QhcMSXQyPuMCRpSQcSYdEuTYgHeCXHbu.r2.cloudflarestorage.com/"
CLOUDFLARE_REGION="auto"


# === Common optional Settings

## This is a dummy key, you must create your own from Resend.
## If this variable exists, user activation is required.
## If it is commented out, users are activated automatically.
#RESEND_API_KEY="RzeTwHijvxvPUerScFcenUZUALuQJzSaGSMJ"
#EMAIL_FROM_ADDRESS=""
#EMAIL_FROM_NAME=""

# Where will social media icons be saved - local or cloudflare.
STORAGE_PROVIDER="local"

# Your upload directory path if you host your files locally, otherwise Cloudflare will be used.
#UPLOAD_DIRECTORY=""

# Your upload directory path if you host your files locally, otherwise Cloudflare will be used.
#NEXT_PUBLIC_UPLOAD_STATIC_DIRECTORY=""


# Social Media API Settings
X_API_KEY=""
X_API_SECRET=""
X_CLIENT=""
Expand All @@ -22,19 +50,8 @@ REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET=""
GITHUB_CLIENT_ID=""
GITHUB_CLIENT_SECRET=""
RESEND_API_KEY=""
BEEHIIVE_API_KEY=""
BEEHIIVE_PUBLICATION_ID=""
NX_ADD_PLUGINS=false
CLOUDFLARE_ACCOUNT_ID=""
CLOUDFLARE_ACCESS_KEY=""
CLOUDFLARE_SECRET_ACCESS_KEY=""
CLOUDFLARE_BUCKETNAME=""
CLOUDFLARE_BUCKET_URL=""
CLOUDFLARE_REGION=""
FEE_AMOUNT=0.05
OPENAI_API_KEY=""
NEXT_PUBLIC_DISCORD_SUPPORT=""
THREADS_APP_ID=""
THREADS_APP_SECRET=""
FACEBOOK_APP_ID=""
Expand All @@ -47,7 +64,19 @@ PINTEREST_CLIENT_ID=""
PINTEREST_CLIENT_SECRET=""
DRIBBBLE_CLIENT_ID=""
DRIBBBLE_CLIENT_SECRET=""
IS_GENERAL="true"
EMAIL_FROM_ADDRESS=""
EMAIL_FROM_NAME=""
NEXT_PUBLIC_POLOTNO="Polotno key for the gallery"

# Misc Settings
OPENAI_API_KEY=""
NEXT_PUBLIC_DISCORD_SUPPORT=""
NEXT_PUBLIC_POLOTNO=""

# Payment settings
FEE_AMOUNT=0.05
STRIPE_PUBLISHABLE_KEY=""
STRIPE_SECRET_KEY=""
STRIPE_SIGNING_KEY=""
STRIPE_SIGNING_KEY_CONNECT=""

# Developer Settings
NX_ADD_PLUGINS=false
IS_GENERAL="true" # required for now
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "🐛 Bug Report"
description: "Submit a bug report to help us improve,\nif you have a problem installing the app please join our https://discord.postiz.com instead for help."
title: "🐛 Bug Report: "
title: "Give your bug report a good title "
labels: ["type: bug"]
body:
- type: markdown
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 🚀 Feature
description: "Submit a proposal for a new feature"
title: "🚀 Feature: "
labels: [feature]
title: "Give your feature request a title"
labels: ["type: feature-request"]
body:
- type: markdown
attributes:
Expand Down
27 changes: 22 additions & 5 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ ENV NPM_CONFIG_UPDATE_NOTIFIER=false
ENV NEXT_TELEMETRY_DISABLED=1

RUN apk add --no-cache \
caddy \
bash=5.2.21-r0 \
supervisor=4.2.5-r4 \
make \
build-base
supervisor=4.2.5-r4

WORKDIR /app

EXPOSE 4200
EXPOSE 3000
EXPOSE 4200
EXPOSE 5000

COPY var/docker/entrypoint.sh /app/entrypoint.sh
COPY var/docker/supervisord.conf /etc/supervisord.conf
COPY var/docker/supervisord /app/supervisord_available_configs/
COPY .env.example /config/.env
COPY var/docker/Caddyfile /app/Caddyfile
COPY .env.example /config/postiz.env

VOLUME /config

Expand All @@ -38,12 +39,23 @@ ENTRYPOINT ["/app/entrypoint.sh"]
# Builder image
FROM base AS devcontainer

RUN apk add --no-cache \
pkgconfig \
gcc \
pixman-dev \
cairo-dev \
pango-dev \
make \
build-base

COPY nx.json tsconfig.base.json package.json package-lock.json /app/
COPY apps /app/apps/
COPY libraries /app/libraries/

RUN npm ci --no-fund && npx nx run-many --target=build --projects=frontend,backend,workers,cron

VOLUME /config

LABEL org.opencontainers.image.title="Postiz App (DevContainer)"

# Output image
Expand All @@ -52,7 +64,12 @@ FROM base AS dist
COPY --from=devcontainer /app/node_modules/ /app/node_modules/
COPY --from=devcontainer /app/dist/ /app/dist/

# Required for prisma
COPY --from=devcontainer /app/libraries/ /app/libraries/

COPY package.json nx.json /app/

VOLUME /config

## Labels at the bottom, because CI will eventually add dates, commit hashes, etc.
LABEL org.opencontainers.image.title="Postiz App (Production)"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<a href="https://x.com/intent/follow?screen_name=nevodavid" target="_blank">
<img alt="Follow me" src="https://github.com/user-attachments/assets/1562c93f-95c6-4307-8a85-e62003e26348" />
</a>
<br />

<a href="https://devfest.ai" target="_blank">
<img alt="DevFest" src="https://github.com/user-attachments/assets/cab9a4e5-e88e-4a28-be7d-28ed749e537a" width="850" />
</a>

<br /><br />
</p>

Expand Down Expand Up @@ -42,6 +48,7 @@
<img alt="Facebook" src="https://postiz.com/svgs/socials/Facebook.svg" width="32">
<img alt="Pinterest" src="https://postiz.com/svgs/socials/Pinterest.svg" width="32">
<img alt="Threads" src="https://postiz.com/svgs/socials/Threads.svg" width="32">
<img alt="X" src="https://postiz.com/svgs/socials/X.svg" width="32">
</div>

<p align="center">
Expand Down
3 changes: 2 additions & 1 deletion apps/backend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "backend:build"
"buildTarget": "backend:build",
"inspect": false
},
"configurations": {
"development": {
Expand Down
75 changes: 2 additions & 73 deletions apps/backend/src/api/routes/analytics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { IntegrationService } from '@gitroom/nestjs-libraries/database/prisma/in
import { IntegrationManager } from '@gitroom/nestjs-libraries/integrations/integration.manager';
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
import { RefreshToken } from '@gitroom/nestjs-libraries/integrations/social.abstract';
import { timer } from '@gitroom/helpers/utils/timer';

@ApiTags('Analytics')
@Controller('/analytics')
Expand Down Expand Up @@ -61,78 +62,6 @@ export class AnalyticsController {
@Param('integration') integration: string,
@Query('date') date: string
) {
const getIntegration = await this._integrationService.getIntegrationById(
org.id,
integration
);

if (!getIntegration) {
throw new Error('Invalid integration');
}

if (getIntegration.type !== 'social') {
return {};
}

const integrationProvider = this._integrationManager.getSocialIntegration(
getIntegration.providerIdentifier
);

if (dayjs(getIntegration?.tokenExpiration).isBefore(dayjs())) {
const { accessToken, expiresIn, refreshToken } =
await integrationProvider.refreshToken(getIntegration.refreshToken!);

if (accessToken) {
await this._integrationService.createOrUpdateIntegration(
getIntegration.organizationId,
getIntegration.name,
getIntegration.picture!,
'social',
getIntegration.internalId,
getIntegration.providerIdentifier,
accessToken,
refreshToken,
expiresIn
);

getIntegration.token = accessToken;
}
}

const getIntegrationData = await ioRedis.get(
`integration:${org.id}:${integration}:${date}`
);
if (getIntegrationData) {
return JSON.parse(getIntegrationData);
}

if (integrationProvider.analytics) {
try {
const loadAnalytics = await integrationProvider.analytics(
getIntegration.internalId,
getIntegration.token,
+date
);
await ioRedis.set(
`integration:${org.id}:${integration}:${date}`,
JSON.stringify(loadAnalytics),
'EX',
!process.env.NODE_ENV || process.env.NODE_ENV === 'development'
? 1
: 3600
);
return loadAnalytics;
} catch (e) {
if (e instanceof RefreshToken) {
await this._integrationService.disconnectChannel(
org.id,
getIntegration
);
return [];
}
}
}

return [];
return this._integrationService.checkAnalytics(org, integration, date);
}
}
13 changes: 12 additions & 1 deletion apps/backend/src/api/routes/integrations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ApiTags } from '@nestjs/swagger';
import { GetUserFromRequest } from '@gitroom/nestjs-libraries/user/user.from.request';
import { NotEnoughScopesFilter } from '@gitroom/nestjs-libraries/integrations/integration.missing.scopes';
import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service';
import { IntegrationTimeDto } from '@gitroom/nestjs-libraries/dtos/integrations/integration.time.dto';

@ApiTags('Integrations')
@Controller('/integrations')
Expand Down Expand Up @@ -55,6 +56,7 @@ export class IntegrationsController {
inBetweenSteps: p.inBetweenSteps,
refreshNeeded: p.refreshNeeded,
type: p.type,
time: JSON.parse(p.postingTimes)
})),
};
}
Expand Down Expand Up @@ -97,6 +99,14 @@ export class IntegrationsController {
return { url };
}

@Post('/:id/time')
async setTime(
@GetOrgFromRequest() org: Organization,
@Param('id') id: string,
@Body() body: IntegrationTimeDto
) {
return this._integrationService.setTimes(org.id, id, body);
}
@Post('/function')
async functionIntegration(
@GetOrgFromRequest() org: Organization,
Expand Down Expand Up @@ -238,7 +248,8 @@ export class IntegrationsController {
expiresIn,
username,
integrationProvider.isBetweenSteps,
body.refresh
body.refresh,
+body.timezone
);
}

Expand Down
2 changes: 0 additions & 2 deletions apps/backend/src/api/routes/posts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { GetOrgFromRequest } from '@gitroom/nestjs-libraries/user/org.from.reque
import { Organization, User } from '@prisma/client';
import { CreatePostDto } from '@gitroom/nestjs-libraries/dtos/posts/create.post.dto';
import { GetPostsDto } from '@gitroom/nestjs-libraries/dtos/posts/get.posts.dto';
import { CommentsService } from '@gitroom/nestjs-libraries/database/prisma/comments/comments.service';
import { StarsService } from '@gitroom/nestjs-libraries/database/prisma/stars/stars.service';
import { CheckPolicies } from '@gitroom/backend/services/auth/permissions/permissions.ability';
import {
Expand All @@ -30,7 +29,6 @@ import { CreateGeneratedPostsDto } from '@gitroom/nestjs-libraries/dtos/generato
export class PostsController {
constructor(
private _postsService: PostsService,
private _commentsService: CommentsService,
private _starsService: StarsService,
private _messagesService: MessagesService
) {}
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/api/routes/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class UsersController {
// @ts-ignore
totalChannels: organization?.subscription?.totalChannels || pricing.FREE.channel,
// @ts-ignore
tier: organization?.subscription?.subscriptionTier || 'FREE',
tier: organization?.subscription?.subscriptionTier || (!process.env.STRIPE_PUBLISHABLE_KEY ? 'ULTIMATE' : 'FREE'),
// @ts-ignore
role: organization?.users[0]?.role,
// @ts-ignore
Expand Down
10 changes: 8 additions & 2 deletions apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ async function bootstrap() {
loadSwagger(app);

const port = process.env.PORT || 3000;
await app.listen(port);
Logger.log(`🚀 Application is running on: http://localhost:${port}`);

try {
await app.listen(port);

Logger.log(`🚀 Backend is running on: http://localhost:${port}`);
} catch (e) {
Logger.error(`Backend failed to start on port ${port}`, e);
}
}

bootstrap();
1 change: 1 addition & 0 deletions apps/commands/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"defaultConfiguration": "development",
"options": {
"buildTarget": "commands:build",
"inspect": false,
"command": "cd dist/apps/commands && node main.js"
},
"configurations": {
Expand Down
Loading

0 comments on commit d7ff7dd

Please sign in to comment.