removed cloudinary service

This commit is contained in:
Sergey Yarkov 2021-11-22 22:41:46 +03:00
parent 10f72f3090
commit 46263fa341
7 changed files with 0 additions and 164 deletions

View File

@ -27,7 +27,6 @@
"preloads": ["./routes/index", "./start/kernel", "./start/event", "./start/bouncer"],
"providers": [
"./providers/AppProvider",
"./providers/CloudinaryProvider",
"@adonisjs/core",
"@adonisjs/lucid",
"@adonisjs/auth",

View File

@ -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=<username>

View File

@ -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<Image> {
// 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<Image | null> {
// const image = await this.Image.query().where('id', id).first();
// if (image) {
// await CloudinaryService.destroy(image.name);
// await image.delete();
// return image;
// }
// return null;
// }
}

View File

@ -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<UploadApiResponse> {
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<any> {
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;
}
}

View File

@ -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<UploadApiResponse>;
destroy(
publicId: string,
options?: {
resource_type?: ResourceType;
type?: DeliveryType;
invalidate?: boolean;
}
): Promise<any>;
getConfig(): CloudinaryConfig;
}
const CloudinaryService: CloudinaryInterface;
export default CloudinaryService;
}

4
env.ts
View File

@ -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(),
});

View File

@ -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);
});
}
}