From 9461e35028494fdcc2a80f87df2bb43824c1923b Mon Sep 17 00:00:00 2001 From: Emil Wangaa Date: Mon, 13 Feb 2017 09:54:50 +0100 Subject: [PATCH] Adds endpoint for searching media for the mediapicker --- src/Umbraco.Web/Editors/EntityController.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index 104c451273..485512cefb 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -81,6 +81,26 @@ namespace Umbraco.Web.Editors return ExamineSearch(query, type, searchFrom); } + /// + /// Searches media and returns a list of ContentItemBasic based on the IMedia + /// + /// + /// + /// + [HttpGet] + public IEnumerable> SearchMedia(string query, string searchFrom = null) + { + if (string.IsNullOrEmpty(query)) + return Enumerable.Empty>(); + + // limiting the examine results to 50 to avoid killing the GetByIds lookup + var searchResult = ExamineSearch(query, UmbracoEntityTypes.Media, searchFrom).Take(50); + var mediaItems = Services.MediaService.GetByIds(searchResult.Select(x => Convert.ToInt32(x.Id))) + .Select(Mapper.Map>); + + return mediaItems; + } + /// /// Searches for all content that the user is allowed to see (based on their allowed sections) ///