Skip to content

Commit

Permalink
feat(@tinacms/core): the MediaStore interface has a delete method
Browse files Browse the repository at this point in the history
  • Loading branch information
ncphillips committed Sep 16, 2020
1 parent 4db8382 commit 4c1cf5a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/@tinacms/core/src/media.ts
Expand Up @@ -74,6 +74,11 @@ export interface MediaStore {
*/
persist(files: MediaUploadOptions[]): Promise<Media[]>

/**
* Delete a media object from the store.
*/
delete(media: Media): Promise<void>

/**
* Given a `src` string it returns a url for previewing that content.
* This is helpful in cases where the file may not be available in production yet.
Expand Down Expand Up @@ -154,6 +159,24 @@ export class MediaManager implements MediaStore {
}
}

async delete(media: Media): Promise<void> {
try {
this.events.dispatch({ type: 'media:delete:start', media })
await this.store.delete(media)
this.events.dispatch({
type: 'media:delete:success',
media,
})
} catch (error) {
this.events.dispatch({
type: 'media:delete:failure',
media,
error,
})
throw error
}
}

previewSrc = async (
src: string,
fieldName: string,
Expand Down

0 comments on commit 4c1cf5a

Please sign in to comment.