adonis-responsive-attachment
Advanced tools
Comparing version 1.5.5 to 1.5.6
@@ -5,4 +5,6 @@ /// <reference types="@adonisjs/drive/build/adonis-typings" /> | ||
/// <reference types="node" /> | ||
/// <reference types="@adonisjs/logger/build/adonis-typings/logger" /> | ||
declare module '@ioc:Adonis/Addons/ResponsiveAttachment' { | ||
import { ColumnOptions } from '@ioc:Adonis/Lucid/Orm'; | ||
import { LoggerContract } from '@ioc:Adonis/Core/Logger'; | ||
import { MultipartFileContract } from '@ioc:Adonis/Core/BodyParser'; | ||
@@ -138,3 +140,3 @@ import { DisksList, ContentHeaders, DriverContract, DriveManagerContract } from '@ioc:Adonis/Core/Drive'; | ||
*/ | ||
toJSON(): (AttachmentAttributes & (UrlRecords | undefined)) | null; | ||
toJSON(): (AttachmentAttributes & (UrlRecords | null)) | null; | ||
} | ||
@@ -157,2 +159,4 @@ /** | ||
setDrive(drive: DriveManagerContract): void; | ||
setLogger(logger: LoggerContract): void; | ||
getLogger(): LoggerContract; | ||
} | ||
@@ -159,0 +163,0 @@ const responsiveAttachment: ResponsiveAttachmentDecorator; |
@@ -26,4 +26,5 @@ "use strict"; | ||
boot() { | ||
this.application.container.withBindings(['Adonis/Addons/ResponsiveAttachment', 'Adonis/Core/Drive'], (ResponsiveAttachmentAddon, Drive) => { | ||
this.application.container.withBindings(['Adonis/Addons/ResponsiveAttachment', 'Adonis/Core/Drive', 'Adonis/Core/Logger'], (ResponsiveAttachmentAddon, Drive, Logger) => { | ||
ResponsiveAttachmentAddon.ResponsiveAttachment.setDrive(Drive); | ||
ResponsiveAttachmentAddon.ResponsiveAttachment.setLogger(Logger); | ||
}); | ||
@@ -30,0 +31,0 @@ } |
@@ -154,3 +154,8 @@ "use strict"; | ||
modelInstance[attachmentField.property].setOptions(attachmentField.options); | ||
return modelInstance[attachmentField.property].computeUrls(); | ||
return modelInstance[attachmentField.property] | ||
.computeUrls() | ||
.catch((error) => { | ||
const logger = modelInstance[attachmentField.property].loggerInstance; | ||
logger.error('Adonis Responsive Attachment error: %o', error); | ||
}); | ||
} | ||
@@ -157,0 +162,0 @@ })); |
/// <reference path="../../adonis-typings/index.d.ts" /> | ||
/// <reference types="@adonisjs/drive/build/adonis-typings" /> | ||
/// <reference types="@adonisjs/logger/build/adonis-typings/logger" /> | ||
/// <reference types="@adonisjs/bodyparser/build/adonis-typings" /> | ||
/// <reference types="node" /> | ||
import { LoggerContract } from '@ioc:Adonis/Core/Logger'; | ||
import type { MultipartFileContract } from '@ioc:Adonis/Core/BodyParser'; | ||
@@ -16,2 +18,3 @@ import { DriveManagerContract, ContentHeaders } from '@ioc:Adonis/Core/Drive'; | ||
private static drive; | ||
private static logger; | ||
/** | ||
@@ -26,2 +29,10 @@ * Reference to the drive | ||
/** | ||
* Set the logger instance | ||
*/ | ||
static setLogger(logger: LoggerContract): void; | ||
/** | ||
* Reference to the logger instance | ||
*/ | ||
static getLogger(): LoggerContract; | ||
/** | ||
* Create attachment instance from the bodyparser | ||
@@ -129,2 +140,6 @@ * file | ||
/** | ||
* Returns disk instance | ||
*/ | ||
private get loggerInstance(); | ||
/** | ||
* Define persistance options | ||
@@ -131,0 +146,0 @@ */ |
@@ -41,2 +41,14 @@ "use strict"; | ||
/** | ||
* Set the logger instance | ||
*/ | ||
static setLogger(logger) { | ||
this.logger = logger; | ||
} | ||
/** | ||
* Reference to the logger instance | ||
*/ | ||
static getLogger() { | ||
return this.logger; | ||
} | ||
/** | ||
* Create attachment instance from the bodyparser | ||
@@ -162,2 +174,8 @@ * file | ||
/** | ||
* Returns disk instance | ||
*/ | ||
get loggerInstance() { | ||
return this.constructor.getLogger(); | ||
} | ||
/** | ||
* Define persistance options | ||
@@ -304,3 +322,5 @@ */ | ||
*/ | ||
await this.computeUrls(); | ||
await this.computeUrls().catch((error) => { | ||
this.loggerInstance.error('Adonis Responsive Attachment error: %o', error); | ||
}); | ||
return this; | ||
@@ -353,16 +373,21 @@ } | ||
if (typeof this.options?.preComputeUrls === 'function') { | ||
const urls = await this.options.preComputeUrls(disk, this); | ||
this.url = urls.url; | ||
if (!this.urls) | ||
this.urls = {}; | ||
if (!this.urls.breakpoints) | ||
this.urls.breakpoints = {}; | ||
for (const key in urls.breakpoints) { | ||
if (Object.prototype.hasOwnProperty.call(urls.breakpoints, key)) { | ||
if (!this.urls.breakpoints[key]) | ||
this.urls.breakpoints[key] = { url: '' }; | ||
this.urls.breakpoints[key].url = urls.breakpoints[key].url; | ||
const urls = await this.options.preComputeUrls(disk, this).catch((error) => { | ||
this.loggerInstance.error('Adonis Responsive Attachment error: %o', error); | ||
return null; | ||
}); | ||
if (urls) { | ||
this.url = urls.url; | ||
if (!this.urls) | ||
this.urls = {}; | ||
if (!this.urls.breakpoints) | ||
this.urls.breakpoints = {}; | ||
for (const key in urls.breakpoints) { | ||
if (Object.prototype.hasOwnProperty.call(urls.breakpoints, key)) { | ||
if (!this.urls.breakpoints[key]) | ||
this.urls.breakpoints[key] = { url: '' }; | ||
this.urls.breakpoints[key].url = urls.breakpoints[key].url; | ||
} | ||
} | ||
return this.urls; | ||
} | ||
return this.urls; | ||
} | ||
@@ -388,3 +413,10 @@ /** | ||
const name = value; | ||
const imageVisibility = await disk.getVisibility(name); | ||
let imageVisibility; | ||
try { | ||
imageVisibility = await disk.getVisibility(name); | ||
} | ||
catch (error) { | ||
this.loggerInstance.error('Adonis Responsive Attachment error: %s', error); | ||
continue; | ||
} | ||
if (imageVisibility === 'private') { | ||
@@ -430,3 +462,6 @@ url = await disk.getSignedUrl(name, signedUrlOptions || undefined); | ||
async getUrls(signingOptions) { | ||
return this.computeUrls({ ...signingOptions }); | ||
return this.computeUrls({ ...signingOptions }).catch((error) => { | ||
this.loggerInstance.error('Adonis Responsive Attachment error: %o', error); | ||
return undefined; | ||
}); | ||
} | ||
@@ -433,0 +468,0 @@ /** |
{ | ||
"name": "adonis-responsive-attachment", | ||
"version": "1.5.5", | ||
"version": "1.5.6", | ||
"description": "Generate and persist optimised and responsive breakpoint images on the fly in your AdonisJS application.", | ||
@@ -5,0 +5,0 @@ "main": "build/providers/ResponsiveAttachmentProvider.js", |
88441
1528