diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index d71d94a4164..93981a76b7c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -23,11 +23,12 @@ public MediaFieldQueryObjectType() { return Array.Empty(); } + return x.Page(x.Source.Paths); }); Field, IEnumerable>("fileNames") - .Description("the media fileNames") + .Description("the media file names") .PagingArguments() .Resolve(x => { @@ -50,9 +51,40 @@ public MediaFieldQueryObjectType() } var paths = x.Page(x.Source.Paths); var mediaFileStore = x.RequestServices.GetService(); + return paths.Select(p => mediaFileStore.MapPathToPublicUrl(p)); }); + Field, IEnumerable>("files") + .Description("the files of the media items") + .PagingArguments() + .Resolve(x => + { + if (x.Source?.Paths is null) + { + return []; + } + + var paths = x.Page(x.Source.Paths).ToArray(); + var mediaFileStore = x.RequestServices.GetService(); + var urls = paths.Select(p => mediaFileStore.MapPathToPublicUrl(p)).ToArray(); + var fileNames = x.Page(x.Source?.GetAttachedFileNames()).ToArray(); + var items = new List(); + var mediaTexts = x.Source?.MediaTexts ?? []; + for (int i = 0; i < paths.Length; i++) + { + items.Add(new MediaFileItem + { + Path = paths[i], + FileName = fileNames.Length > i ? fileNames[i] : string.Empty, + Url = urls.Length > i ? urls[i] : string.Empty, + MediaText = mediaTexts.Length > i ? mediaTexts[i] : string.Empty, + }); + } + + return items; + }); + Field, IEnumerable>("mediatexts") .Description("the media texts") .PagingArguments() @@ -66,4 +98,23 @@ public MediaFieldQueryObjectType() }); } } + + public sealed class MediaFileItemType : ObjectGraphType + { + public MediaFileItemType() + { + Field("fileName").Description("the file name of the media file item").Resolve(x => x.Source.FileName); + Field("path").Description("the path of the media file item").Resolve(x => x.Source.Path); + Field("url").Description("the url name of the media file item").Resolve(x => x.Source.Url); + Field("mediaText").Description("the media text of the file item").Resolve(x => x.Source.MediaText); + } + } + + public sealed class MediaFileItem + { + public string FileName { get; set; } + public string Path { get; set; } + public string Url { get; set; } + public string MediaText { get; set; } + } }