π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: upload profile picture in case of expiration
Nevo David22a25c1a8c70
diff --git a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.tsindex baaf7d80e..b986538ca 100644--- a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts+++ b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts@@ -4,6 +4,8 @@ import dayjs from 'dayjs';import * as console from 'node:console';import { Integration } from '@prisma/client';import { makeId } from '@gitroom/nestjs-libraries/services/make.is';+import { simpleUpload } from '@gitroom/nestjs-libraries/upload/r2.uploader';+import axios from 'axios';@Injectable()export class IntegrationRepository {@@ -12,7 +14,12 @@ export class IntegrationRepository {private _posts: PrismaRepository<'post'>) {}- updateIntegration(id: string, params: Partial<Integration>) {+ async updateIntegration(id: string, params: Partial<Integration>) {+ if (params.picture && params.picture.indexOf(process.env.CLOUDFLARE_BUCKET_URL!) === -1) {+ const picture = await axios.get(params.picture, { responseType: 'arraybuffer' });+ params.picture = await simpleUpload(picture.data, `${makeId(10)}.png`, 'image/png');+ }+return this._integration.model.integration.update({where: {id,diff --git a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.tsindex c8e1e7640..111d20d92 100644--- a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts+++ b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.service.ts@@ -7,6 +7,9 @@ import { SocialProvider } from '@gitroom/nestjs-libraries/integrations/social/soimport { Integration } from '@prisma/client';import { NotificationService } from '@gitroom/nestjs-libraries/database/prisma/notifications/notification.service';import { LinkedinPageProvider } from '@gitroom/nestjs-libraries/integrations/social/linkedin.page.provider';+import { simpleUpload } from '@gitroom/nestjs-libraries/upload/r2.uploader';+import axios from 'axios';+import { makeId } from '@gitroom/nestjs-libraries/services/make.is';@Injectable()export class IntegrationService {@@ -15,7 +18,7 @@ export class IntegrationService {private _integrationManager: IntegrationManager,private _notificationService: NotificationService) {}- createOrUpdateIntegration(+ async createOrUpdateIntegration(org: string,name: string,picture: string,@@ -29,10 +32,13 @@ export class IntegrationService {isBetweenSteps = false,refresh?: string) {+ const loadImage = await axios.get(picture, { responseType: 'arraybuffer' });+ const uploadedPicture = await simpleUpload(loadImage.data, `${makeId(10)}.png`, 'image/png');+return this._integrationRepository.createOrUpdateIntegration(org,name,- picture,+ uploadedPicture,type,internalId,provider,diff --git a/libraries/nestjs-libraries/src/upload/r2.uploader.ts b/libraries/nestjs-libraries/src/upload/r2.uploader.tsindex b1d0885dd..61ec4e8c6 100644--- a/libraries/nestjs-libraries/src/upload/r2.uploader.ts+++ b/libraries/nestjs-libraries/src/upload/r2.uploader.ts@@ -1,10 +1,5 @@import {- UploadPartCommand,- S3Client,- ListPartsCommand,- CreateMultipartUploadCommand,- CompleteMultipartUploadCommand,- AbortMultipartUploadCommand,+ UploadPartCommand, S3Client, ListPartsCommand, CreateMultipartUploadCommand, CompleteMultipartUploadCommand, AbortMultipartUploadCommand, PutObjectCommand} from '@aws-sdk/client-s3';import { getSignedUrl } from '@aws-sdk/s3-request-presigner';import { Request, Response } from 'express';@@ -44,6 +39,20 @@ export default async function handleR2Upload(return res.status(404).end();}+export async function simpleUpload(data: Buffer, key: string, contentType: string) {+ const params = {+ Bucket: CLOUDFLARE_BUCKETNAME,+ Key: key,+ Body: data,+ ContentType: contentType,+ };++ const command = new PutObjectCommand({ ...params });+ await R2.send(command);++ return CLOUDFLARE_BUCKET_URL + '/' + key;+}+export async function createMultipartUpload(req: Request,res: Response