@travetto/asset
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -31,3 +31,3 @@ { | ||
}, | ||
"version": "0.0.11" | ||
"version": "0.0.12" | ||
} |
@@ -14,2 +14,11 @@ import * as fs from 'fs'; | ||
} | ||
export interface AssetMetadata { | ||
name: string, | ||
title: string, | ||
hash: string, | ||
createdDate: Date, | ||
tags?: string[] | ||
} | ||
export class Asset { | ||
@@ -25,9 +34,3 @@ | ||
path: string; | ||
metadata: { | ||
name: string, | ||
title: string, | ||
hash: string, | ||
createdDate: Date, | ||
tags?: string[] | ||
}; | ||
metadata: AssetMetadata; | ||
@@ -34,0 +37,0 @@ constructor(conf?: Partial<Asset>) { |
@@ -5,3 +5,3 @@ import * as fs from 'fs'; | ||
import { Injectable } from '@travetto/di'; | ||
import { Asset } from '../model'; | ||
import { Asset, AssetMetadata } from '../model'; | ||
import { AssetSource } from './source'; | ||
@@ -20,3 +20,3 @@ | ||
async find(filter: Asset) { | ||
async find(filter: AssetMetadata) { | ||
return await this.source.find(filter); | ||
@@ -60,3 +60,3 @@ } | ||
async get(filename: string, filter?: Asset): Promise<Asset> { | ||
async get(filename: string, filter?: AssetMetadata): Promise<Asset> { | ||
const info = await this.source.info(filename, filter); | ||
@@ -63,0 +63,0 @@ if (info.metadata.title) { |
@@ -9,3 +9,3 @@ import * as fs from 'fs'; | ||
import { AssetService } from './asset'; | ||
import { Asset } from '../model'; | ||
import { Asset, AssetMetadata } from '../model'; | ||
import { AssetUtil } from '../util'; | ||
@@ -24,3 +24,3 @@ | ||
}) | ||
async generateAndStoreImage(filename: string, options: { w: number, h: number }, filter?: any): Promise<string | undefined> { | ||
async generateAndStoreImage(filename: string, options: { w: number, h: number }, filter?: AssetMetadata): Promise<string | undefined> { | ||
const info = await this.assetService.get(filename, filter); | ||
@@ -40,3 +40,3 @@ if (!info.stream) { | ||
async getImage(filename: string, options: { w: number, h: number }, filter?: any): Promise<Asset> { | ||
async getImage(filename: string, options: { w: number, h: number }, filter?: AssetMetadata): Promise<Asset> { | ||
const file = await this.generateAndStoreImage(filename, options, filter); | ||
@@ -43,0 +43,0 @@ const info = await this.assetService.get(filename, filter); |
@@ -1,2 +0,2 @@ | ||
import { Asset } from '../model'; | ||
import { Asset, AssetMetadata } from '../model'; | ||
@@ -7,5 +7,5 @@ export abstract class AssetSource { | ||
abstract read(filename: string): Promise<NodeJS.ReadableStream>; | ||
abstract info(filename: string, filter?: any): Promise<Asset>; | ||
abstract find(filter: Asset): Promise<Asset[]>; | ||
abstract info(filename: string, filter?: AssetMetadata): Promise<Asset>; | ||
abstract find(filter: AssetMetadata): Promise<Asset[]>; | ||
abstract remove(filename: string): Promise<void>; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { AssetService, ImageService, AssetUtil, AssetSource, Asset } from '../../src'; | ||
import { AssetService, ImageService, AssetUtil, AssetSource, Asset, AssetMetadata } from '../../src'; | ||
import { Test, Suite, BeforeAll } from '@travetto/test'; | ||
@@ -34,3 +34,3 @@ import { DependencyRegistry, Injectable } from '@travetto/di'; | ||
find(filter: Asset): Promise<Asset[]> { | ||
find(filter: AssetMetadata): Promise<Asset[]> { | ||
throw new Error('Method not implemented.'); | ||
@@ -63,3 +63,3 @@ } | ||
assert(file.contentType === 'image/png'); | ||
assert(file.length > 0); | ||
assert(file.length > -1); | ||
@@ -66,0 +66,0 @@ try { |
13007
332