diff --git a/resources/views/oss_api.html b/resources/views/oss_api.html index 76b6379..fd6adde 100644 --- a/resources/views/oss_api.html +++ b/resources/views/oss_api.html @@ -143,6 +143,18 @@
+ +
+ + +
+
@@ -382,6 +394,8 @@ function ossApiApp() { markerHistory: [], browserResult: { objects: [], prefixes: [], is_truncated: false, next_marker: '' }, browserDeleteKey: null, + browserConfigId: '', + activeConfigs: [], async init() { await this.load(); @@ -467,18 +481,42 @@ function ossApiApp() { nextPage() { if (this.page < this.totalPages) { this.page++; this.load(); } }, // ─ Explorador ────────────────────────────────────────────── - switchToBrowser() { + async switchToBrowser() { this.activeTab = 'browser'; - if ((this.browserResult.objects || []).length === 0 && (this.browserResult.prefixes || []).length === 0) { - this.browserLoad(); + try { + const res = await fetch('/app/oss-api/active'); + const data = await res.json(); + this.activeConfigs = data.data || []; + if (this.activeConfigs.length > 0 && !this.browserConfigId) { + this.browserConfigId = this.activeConfigs[0].ID; + } + if ((this.browserResult.objects || []).length === 0 && (this.browserResult.prefixes || []).length === 0) { + this.browserLoad(); + } + } catch (e) { + this.browserError = e.message; } }, + switchConfig() { + this.browserPrefix = ''; + this.browserMarker = ''; + this.markerHistory = []; + this.browserResult = { objects: [], prefixes: [], is_truncated: false, next_marker: '' }; + this.browserLoad(); + }, + + ossApiParams(extra) { + const p = new URLSearchParams(extra || {}); + if (this.browserConfigId) p.set('oss_api_id', this.browserConfigId); + return p; + }, + async browserLoad() { this.browserLoading = true; this.browserError = ''; try { - const params = new URLSearchParams({ prefix: this.browserPrefix, marker: this.browserMarker, max_keys: 100 }); + const params = this.ossApiParams({ prefix: this.browserPrefix, marker: this.browserMarker, max_keys: 100 }); const res = await fetch(`/app/oss-api/browser?${params}`); const data = await res.json(); if (!res.ok) throw new Error(data.error || 'Error al listar objetos'); @@ -518,7 +556,8 @@ function ossApiApp() { async previewOrDownload(key) { try { - const res = await fetch(`/app/oss-api/browser/url?key=${encodeURIComponent(key)}`); + const params = this.ossApiParams({ key }); + const res = await fetch(`/app/oss-api/browser/url?${params}`); const data = await res.json(); if (!res.ok) throw new Error(data.error || 'Error generando URL'); window.open(data.url, '_blank'); @@ -535,7 +574,8 @@ function ossApiApp() { try { if (String(this.deleteId).startsWith('browser:')) { const key = this.browserDeleteKey; - const res = await fetch('/app/oss-api/browser/object', { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key }) }); + const params = this.ossApiParams({}); + const res = await fetch(`/app/oss-api/browser/object?${params}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ key }) }); const data = await res.json(); if (!res.ok) throw new Error(data.error || 'Error al eliminar'); this.deleteId = null; @@ -565,6 +605,7 @@ function ossApiApp() { const fd = new FormData(); fd.append('file', file); fd.append('prefix', this.browserPrefix); + if (this.browserConfigId) fd.append('oss_api_id', this.browserConfigId); const res = await fetch('/app/oss-api/browser/upload', { method: 'POST', body: fd }); const data = await res.json(); if (!res.ok) throw new Error(data.error || 'Error al subir archivo'); diff --git a/rest/controllers/oss_api_controller.go b/rest/controllers/oss_api_controller.go index 27e7dd6..ecabb55 100644 --- a/rest/controllers/oss_api_controller.go +++ b/rest/controllers/oss_api_controller.go @@ -15,6 +15,9 @@ import ( // helper: obtiene el provider OSS por ID o el activo por defecto func getOSSProvider(c *fiber.Ctx) (services.OSSProvider, error) { idStr := c.Query("oss_api_id", "") + if idStr == "" { + idStr = c.FormValue("oss_api_id", "") + } if idStr != "" { id, err := strconv.ParseUint(idStr, 10, 32) if err == nil && id > 0 { @@ -224,7 +227,7 @@ func OssBrowserSignedURL(c *fiber.Ctx) error { } // OssBrowserDelete elimina un objeto del bucket activo. -// Body JSON: { "key": "ruta/al/archivo.jpg" } +// Body JSON: { "key": "ruta/al/archivo.jpg", "oss_api_id": 1 } func OssBrowserDelete(c *fiber.Ctx) error { type Req struct { Key string `json:"key"`