Skip to content

Commit

Permalink
Merge branch 'main' into configuration-checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesread authored Sep 25, 2024
2 parents fd279c0 + 9d985b5 commit 398087b
Show file tree
Hide file tree
Showing 202 changed files with 1,467 additions and 5,454 deletions.
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
62 changes: 49 additions & 13 deletions .github/workflows/build-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,27 @@ on:
- '*'

jobs:
build-containers:
build-containers-common:
runs-on: ubuntu-latest
outputs:
containerver: ${{ steps.getcontainerver.outputs.containerver }}
steps:
- name: Get Container Version
id: getcontainerver
run: |
echo "containerver=$(date +'%s')" >> "$GITHUB_OUTPUT"
build-containers:
needs: build-containers-common
strategy:
matrix:
include:
- runnertags: ubuntu-latest
arch: amd64
- runnertags: [self-hosted, ARM64]
arch: arm64

runs-on: ${{ matrix.runnertags }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -26,24 +45,41 @@ jobs:
- name: docker build
run: ./var/docker/docker-build.sh

- name: Get date
run: |
echo "DATE=$(date +'%s')" >> "$GITHUB_ENV"
- name: Print post-build debug info
run: |
docker images
- name: docker tag
env:
CONTAINERVER: ${{ needs.build-containers-common.outputs.containerver }}
run: |
docker tag localhost/postiz ghcr.io/gitroomhq/postiz-app:${{ env.DATE }}
docker push ghcr.io/gitroomhq/postiz-app:${{ env.DATE }}
docker tag ghcr.io/gitroomhq/postiz-app:${{ env.DATE }} ghcr.io/gitroomhq/postiz-app:latest
docker push ghcr.io/gitroomhq/postiz-app:latest
docker tag localhost/postiz ghcr.io/gitroomhq/postiz-app:${{ matrix.arch }}-${{ env.CONTAINERVER }}
docker push ghcr.io/gitroomhq/postiz-app:${{ matrix.arch }}-${{ env.CONTAINERVER }}
docker tag localhost/postiz-devcontainer ghcr.io/gitroomhq/postiz-devcontainer:${{ env.DATE }}
docker push ghcr.io/gitroomhq/postiz-devcontainer:${{ env.DATE }}
docker tag localhost/postiz-devcontainer ghcr.io/gitroomhq/postiz-devcontainer:${{ env.CONTAINERVER }}
docker push ghcr.io/gitroomhq/postiz-devcontainer:${{ env.CONTAINERVER }}
docker tag ghcr.io/gitroomhq/postiz-devcontainer:${{ env.DATE }} ghcr.io/gitroomhq/postiz-devcontainer:latest
docker tag ghcr.io/gitroomhq/postiz-devcontainer:${{ env.CONTAINERVER }} ghcr.io/gitroomhq/postiz-devcontainer:latest
docker push ghcr.io/gitroomhq/postiz-devcontainer:latest
build-container-manifest:
needs: [build-containers, build-containers-common]
runs-on: ubuntu-latest
steps:
- name: Login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Create Docker Manifest
env:
CONTAINERVER: ${{ needs.build-containers-common.outputs.containerver }}
run: |
docker manifest create \
ghcr.io/gitroomhq/postiz-app:latest \
ghcr.io/gitroomhq/postiz-app:amd64-${{ env.CONTAINERVER }} \
ghcr.io/gitroomhq/postiz-app:arm64-${{ env.CONTAINERVER }}
docker manifest push ghcr.io/gitroomhq/postiz-app:latest
8 changes: 7 additions & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ 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

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 var/docker/Caddyfile /app/Caddyfile
COPY .env.example /config/postiz.env

VOLUME /config
Expand Down Expand Up @@ -61,6 +64,9 @@ 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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,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/src/api/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { PermissionsService } from '@gitroom/backend/services/auth/permissions/p
import { IntegrationsController } from '@gitroom/backend/api/routes/integrations.controller';
import { IntegrationManager } from '@gitroom/nestjs-libraries/integrations/integration.manager';
import { SettingsController } from '@gitroom/backend/api/routes/settings.controller';
import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service';
import { PostsController } from '@gitroom/backend/api/routes/posts.controller';
import { MediaController } from '@gitroom/backend/api/routes/media.controller';
import { UploadModule } from '@gitroom/nestjs-libraries/upload/upload.module';
Expand All @@ -27,6 +26,7 @@ import { CodesService } from '@gitroom/nestjs-libraries/services/codes.service';
import { CopilotController } from '@gitroom/backend/api/routes/copilot.controller';
import { AgenciesController } from '@gitroom/backend/api/routes/agencies.controller';
import { PublicController } from '@gitroom/backend/api/routes/public.controller';
import { RootController } from '@gitroom/backend/api/routes/root.controller';

const authenticatedController = [
UsersController,
Expand Down Expand Up @@ -60,6 +60,7 @@ const authenticatedController = [
: []),
],
controllers: [
RootController,
StripeController,
AuthController,
PublicController,
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);
}
}
4 changes: 3 additions & 1 deletion apps/backend/src/api/routes/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class AuthController {
getOrgFromCookie
);

if (body.provider === 'LOCAL') {
const activationRequired = body.provider === 'LOCAL' && !!process.env.RESEND_API_KEY;

if (activationRequired) {
response.header('activate', 'true');
response.status(200).json({ activate: true });
return;
Expand Down
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
8 changes: 8 additions & 0 deletions apps/backend/src/api/routes/root.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Controller, Get } from '@nestjs/common';
@Controller('/')
export class RootController {
@Get('/')
getRoot(): string {
return 'App is running!';
}
}
19 changes: 7 additions & 12 deletions apps/backend/src/api/routes/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
AuthorizationActions,
Sections,
} from '@gitroom/backend/services/auth/permissions/permissions.service';
import { removeSubdomain } from '@gitroom/helpers/subdomain/subdomain.management';
import { getCookieUrlFromDomain } from '@gitroom/helpers/subdomain/subdomain.management';
import { pricing } from '@gitroom/nestjs-libraries/database/prisma/subscriptions/pricing';
import { ApiTags } from '@nestjs/swagger';
import { UsersService } from '@gitroom/nestjs-libraries/database/prisma/users/users.service';
Expand Down 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 Expand Up @@ -92,8 +92,7 @@ export class UsersController {
}

response.cookie('impersonate', id, {
domain:
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
secure: true,
httpOnly: true,
sameSite: 'none',
Expand Down Expand Up @@ -163,8 +162,7 @@ export class UsersController {
@Res({ passthrough: true }) response: Response
) {
response.cookie('showorg', id, {
domain:
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
secure: true,
httpOnly: true,
sameSite: 'none',
Expand All @@ -177,8 +175,7 @@ export class UsersController {
@Post('/logout')
logout(@Res({ passthrough: true }) response: Response) {
response.cookie('auth', '', {
domain:
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
secure: true,
httpOnly: true,
maxAge: -1,
Expand All @@ -187,8 +184,7 @@ export class UsersController {
});

response.cookie('showorg', '', {
domain:
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
secure: true,
httpOnly: true,
maxAge: -1,
Expand All @@ -197,8 +193,7 @@ export class UsersController {
});

response.cookie('impersonate', '', {
domain:
'.' + new URL(removeSubdomain(process.env.FRONTEND_URL!)).hostname,
domain: getCookieUrlFromDomain(process.env.FRONTEND_URL!),
secure: true,
httpOnly: true,
maxAge: -1,
Expand Down
Loading

0 comments on commit 398087b

Please sign in to comment.