diff --git a/.adonisrc.json b/.adonisrc.json index a960fa8..e25a497 100644 --- a/.adonisrc.json +++ b/.adonisrc.json @@ -27,7 +27,6 @@ "preloads": ["./routes/index", "./start/kernel", "./start/event", "./start/bouncer"], "providers": [ "./providers/AppProvider", - "./providers/CloudinaryProvider", "@adonisjs/core", "@adonisjs/lucid", "@adonisjs/auth", diff --git a/.env.example b/.env.example index 84c72fe..2dbe8bf 100644 --- a/.env.example +++ b/.env.example @@ -12,10 +12,6 @@ REDIS_CONNECTION=local REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_PASSWORD= -CLOUDINARY_CLOUD_NAME= -CLOUDINARY_API_KEY= -CLOUDINARY_API_SECRET= -CLOUDINARY_SECURE=true SMTP_HOST=localhost SMTP_PORT=587 SMTP_USERNAME= diff --git a/app/Repositories/ImageRepository.ts b/app/Repositories/ImageRepository.ts index 281bd1e..dc1ad1d 100644 --- a/app/Repositories/ImageRepository.ts +++ b/app/Repositories/ImageRepository.ts @@ -1,5 +1,4 @@ import { MultipartFileContract } from '@ioc:Adonis/Core/BodyParser'; -// import CloudinaryService from '@ioc:Adonis/Addons/Cloudinary'; import Drive from '@ioc:Adonis/Core/Drive'; import Image from 'App/Models/Image'; @@ -56,35 +55,4 @@ export default class ImageRepository { return null; } - - /** - * Create image in cloudinary cloud - * - * @param file File - * @param publicId Image public id - * @returns Created image - */ - // public async createInCloudinaryCloud(file: MultipartFileContract, publicId: string | undefined): Promise { - // const response = await CloudinaryService.upload(file, publicId); - // const image = await this.Image.create({ name: publicId, path: response.secure_url, ext: response.format }); - // return image; - // } - - /** - * Delete image from cloudinary cloud - * - * @param id Image id - * @returns Result or null - */ - // public async deleteFormCloudinaryCloud(id: number): Promise { - // const image = await this.Image.query().where('id', id).first(); - - // if (image) { - // await CloudinaryService.destroy(image.name); - // await image.delete(); - // return image; - // } - - // return null; - // } } diff --git a/app/Services/CloudinaryService.ts b/app/Services/CloudinaryService.ts deleted file mode 100644 index f65bbfe..0000000 --- a/app/Services/CloudinaryService.ts +++ /dev/null @@ -1,67 +0,0 @@ -import * as cloudinary from 'cloudinary'; -import { UploadApiResponse, UploadApiOptions, ResponseCallback, ResourceType, DeliveryType } from 'cloudinary'; -import { MultipartFileContract } from '@ioc:Adonis/Core/BodyParser'; -import { CloudinaryConfig, CloudinaryInterface } from '@ioc:Adonis/Addons/Cloudinary'; - -export default class CloudinaryService implements CloudinaryInterface { - private readonly config: CloudinaryConfig; - - private cloudinary: typeof cloudinary; - - constructor(config: CloudinaryConfig) { - /** - * Cloudinary config - */ - cloudinary.v2.config({ - api_key: config.apiKey, - api_secret: config.apiSecret, - cloud_name: config.cloudName, - secure: config.secure, - }); - - this.cloudinary = cloudinary; - this.config = config; - } - - public async upload( - file: MultipartFileContract, - publicId: string | undefined = undefined, - uploadOptions?: UploadApiOptions, - callback?: ResponseCallback - ): Promise { - const path = CloudinaryService.getPathFromFile(file); - const response = await this.cloudinary.v2.uploader.upload( - path, - { public_id: publicId, ...uploadOptions }, - callback - ); - - return response; - } - - public async destroy( - publicId: string, - options?: { - resource_type?: ResourceType; - type?: DeliveryType; - invalidate?: boolean; - } - ): Promise { - const response = await this.cloudinary.v2.uploader.destroy(publicId, options); - return response; - } - - public getConfig(): CloudinaryConfig { - return this.config; - } - - public static getPathFromFile(file: MultipartFileContract): string { - const path = file.tmpPath ?? file.filePath; - - if (!path) { - throw new Error('Cannot get file path from file'); - } - - return path; - } -} diff --git a/contracts/cloudinary.ts b/contracts/cloudinary.ts deleted file mode 100644 index 26ae909..0000000 --- a/contracts/cloudinary.ts +++ /dev/null @@ -1,42 +0,0 @@ -declare module '@ioc:Adonis/Addons/Cloudinary' { - import { - ResponseCallback, - TransformationOptions, - UploadApiOptions, - UploadApiResponse, - ResourceType, - DeliveryType, - } from 'cloudinary'; - import { MultipartFileContract } from '@ioc:Adonis/Core/BodyParser'; - - export interface CloudinaryConfig { - cloudName: string; - apiKey: string; - apiSecret: string; - secure: boolean; - [key: string]: TransformationOptions; - } - - export interface CloudinaryInterface { - upload( - file: MultipartFileContract, - publicId: string | undefined, - uploadOptions?: UploadApiOptions, - callback?: ResponseCallback - ): Promise; - - destroy( - publicId: string, - options?: { - resource_type?: ResourceType; - type?: DeliveryType; - invalidate?: boolean; - } - ): Promise; - - getConfig(): CloudinaryConfig; - } - - const CloudinaryService: CloudinaryInterface; - export default CloudinaryService; -} diff --git a/env.ts b/env.ts index fc14b74..aed92d2 100644 --- a/env.ts +++ b/env.ts @@ -36,8 +36,4 @@ export default Env.rules({ SMTP_PASSWORD: Env.schema.string(), MAILGUN_API_KEY: Env.schema.string(), MAILGUN_DOMAIN: Env.schema.string(), - CLOUDINARY_CLOUD_NAME: Env.schema.string(), - CLOUDINARY_API_KEY: Env.schema.string(), - CLOUDINARY_API_SECRET: Env.schema.string(), - CLOUDINARY_SECURE: Env.schema.boolean(), }); diff --git a/providers/CloudinaryProvider.ts b/providers/CloudinaryProvider.ts deleted file mode 100644 index 6508067..0000000 --- a/providers/CloudinaryProvider.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ApplicationContract } from '@ioc:Adonis/Core/Application'; -import CloudinaryService from 'App/Services/CloudinaryService'; - -export default class CloudinaryProvider { - constructor(protected app: ApplicationContract) {} - - public register() { - this.app.container.singleton('Adonis/Addons/Cloudinary', () => { - const config = this.app.container.resolveBinding('Adonis/Core/Config').get('cloudinary', {}); - - return new CloudinaryService(config); - }); - } -}