fix: use FileSize and ImageSize types

This commit is contained in:
Elliot DeNolf
2021-01-06 00:03:40 -05:00
parent f059d5b59a
commit 4d6871abc8
3 changed files with 15 additions and 12 deletions

View File

@@ -9,6 +9,7 @@ import fileExists from '../../uploads/fileExists';
import { BeforeOperationHook, Collection } from '../config/types';
import { Document, Where } from '../../types';
import { hasWhereAccessResult } from '../../auth/types';
import { FileSize } from '../../uploads/types';
export type Arguments = {
depth?: number
@@ -118,7 +119,7 @@ async function deleteQuery(incomingArgs: Arguments): Promise<Document> {
}
if (resultToDelete.sizes) {
Object.values(resultToDelete.sizes).forEach(async (size) => {
Object.values(resultToDelete.sizes).forEach(async (size: FileSize) => {
if (await fileExists(`${staticPath}/${size.filename}`)) {
fs.unlink(`${staticPath}/${size.filename}`, (err) => {
if (err) {

View File

@@ -4,9 +4,9 @@ import sanitize from 'sanitize-filename';
import getImageSize from './getImageSize';
import fileExists from './fileExists';
import { CollectionConfig } from '../collections/config/types';
import { FileSizes } from './types';
import { FileSizes, ImageSize } from './types';
function getOutputImage(sourceImage, size) {
function getOutputImage(sourceImage: string, size: ImageSize) {
const extension = sourceImage.split('.').pop();
const name = sanitize(sourceImage.substr(0, sourceImage.lastIndexOf('.')) || sourceImage);

View File

@@ -1,13 +1,15 @@
export type FileSize = {
filename: string;
filesize: number;
mimeType: string;
name: string;
width: number;
height: number;
crop: string;
}
export type FileSizes = {
[size: string]: {
filename: string;
filesize: number;
mimeType: string;
name: string;
width: number;
height: number;
crop: string;
}
[size: string]: FileSize
}
export type FileData = {