diff --git a/zero.Api/Endpoints/Media/Maps/MediaSourceResult.cs b/zero.Api/Endpoints/Media/Maps/MediaSourceResult.cs new file mode 100644 index 00000000..755ff85e --- /dev/null +++ b/zero.Api/Endpoints/Media/Maps/MediaSourceResult.cs @@ -0,0 +1,6 @@ +namespace zero.Api.Endpoints.Media; + +public class MediaSourceResult +{ + public string Path { get; set; } +} \ No newline at end of file diff --git a/zero.Api/Endpoints/Media/MediaController.cs b/zero.Api/Endpoints/Media/MediaController.cs index 2e999c00..2a4378f2 100644 --- a/zero.Api/Endpoints/Media/MediaController.cs +++ b/zero.Api/Endpoints/Media/MediaController.cs @@ -269,6 +269,24 @@ public class MediaController : ZeroApiTreeEntityStoreController> Get(string id, string changeVector = null) => await GetModel(id, changeVector); + [HttpGet("{id}/source")] + [ZeroAuthorize(MediaPermissions.Read)] + public virtual async Task> GetSource(string id) + { + string path = await Media.GetPublicFilePath(id); + + if (path.IsNullOrEmpty()) + { + return NotFound(); + } + + return new MediaSourceResult() + { + Path = path + }; + } + + [HttpGet("{id}/hierarchy")] [ZeroAuthorize(MediaPermissions.Read)] public virtual async Task> GetHierarchy(string id) => await Store.GetHierarchy(NormalizeParentId(id)); diff --git a/zero.Backoffice.UI/app/components/ui-dropdown-button.vue b/zero.Backoffice.UI/app/components/ui-dropdown-button.vue index 335ef666..037f208f 100644 --- a/zero.Backoffice.UI/app/components/ui-dropdown-button.vue +++ b/zero.Backoffice.UI/app/components/ui-dropdown-button.vue @@ -105,13 +105,15 @@ this.dropdown.hide(); } + let self = this; + this.$emit('click', this.value, { dropdown: this.dropdown, hide() { - if (this.dropdown) + if (self.dropdown) { - this.dropdown.hide(); + self.dropdown.hide(); } instance.$emit('hide'); }, diff --git a/zero.Backoffice.UI/app/modules/media/api.ts b/zero.Backoffice.UI/app/modules/media/api.ts index 2459a995..fd4e51d6 100644 --- a/zero.Backoffice.UI/app/modules/media/api.ts +++ b/zero.Backoffice.UI/app/modules/media/api.ts @@ -7,6 +7,8 @@ const files = { getById: (id: string, changeVector?: string, config?: ApiRequestConfig) => get('media/' + id, { ...config, params: { changeVector } }), + getSource: (id: string, config?: ApiRequestConfig) => get(`media/${id}/source`, { ...config }), + getByQuery: (query: ApiRequestQuery, config?: ApiRequestConfig) => get('media', { ...config, params: { ...query } }), getHierarchy: (id: string, config?: ApiRequestConfig) => get(`media/${id}/hierarchy`, { ...config }), diff --git a/zero.Backoffice.UI/app/modules/media/pages/detail/detail.vue b/zero.Backoffice.UI/app/modules/media/pages/detail/detail.vue index 5f744f27..01758f10 100644 --- a/zero.Backoffice.UI/app/modules/media/pages/detail/detail.vue +++ b/zero.Backoffice.UI/app/modules/media/pages/detail/detail.vue @@ -2,7 +2,7 @@ @@ -50,6 +50,20 @@ { opts.hide(); this.$refs.form.onDelete(api.delete.bind(this, this.id)); + }, + + async openFile(val, { dropdown, hide, loading }) + { + loading(true); + const result = await api.getSource(this.id); + let path = result.success ? result.data.path : null; + loading(false); + hide(); + + if (path) + { + window.open(window.location.origin + path, 'blank'); + } } } }