This commit is contained in:
Lizandro Guarnizo
2026-06-03 22:39:58 -05:00
parent 35a384eeba
commit ff72bd0269
2 changed files with 51 additions and 7 deletions
+47 -6
View File
@@ -143,6 +143,18 @@
<!-- ─── TAB: Explorador de archivos ──────────────────────────────────── -->
<div x-show="activeTab === 'browser'">
<!-- Selector de configuración OSS -->
<div class="flex items-center gap-3 mb-4 p-3 bg-gray-50 rounded-lg border border-gray-200">
<label class="text-xs font-medium text-gray-600">Configuración OSS:</label>
<select x-model="browserConfigId" @change="switchConfig()"
class="flex-1 border border-gray-300 rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-[#8eb02f]">
<option value="">Seleccionar...</option>
<template x-for="cfg in activeConfigs" :key="cfg.ID">
<option :value="cfg.ID" x-text="`${cfg.name} (${cfg.provider === 's3' ? 'S3' : 'Alibaba'})`"></option>
</template>
</select>
</div>
<!-- Breadcrumb / ruta actual -->
<div class="flex items-center gap-1 text-sm mb-3 flex-wrap">
<button @click="navigateTo('')" class="text-[#8eb02f] hover:underline font-medium">Raíz</button>
@@ -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');
+4 -1
View File
@@ -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"`