Add minio connection
This commit is contained in:
parent
129f1f9152
commit
fee9d2cce5
@ -23,5 +23,3 @@ sections:
|
|||||||
name: Woodpecker
|
name: Woodpecker
|
||||||
url: https://woodpecker.dvirlabs.com
|
url: https://woodpecker.dvirlabs.com
|
||||||
name: Dev-tools
|
name: Dev-tools
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,8 @@ from fastapi.middleware.cors import CORSMiddleware
|
|||||||
import yaml
|
import yaml
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from minio import Minio
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
@ -15,6 +17,16 @@ app.add_middleware(
|
|||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# MinIO connection with access and secret keys
|
||||||
|
minio_client = Minio(
|
||||||
|
"minio.dvirlabs.com",
|
||||||
|
access_key="YOUR_MINIO_ACCESS_KEY",
|
||||||
|
secret_key="YOUR_MINIO_SECRET_KEY",
|
||||||
|
secure=True # Set to False if using HTTP
|
||||||
|
)
|
||||||
|
|
||||||
|
BUCKET = "navix-icons"
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root():
|
||||||
return {"message": "Welcome to the FastAPI application!"}
|
return {"message": "Welcome to the FastAPI application!"}
|
||||||
@ -63,6 +75,18 @@ def add_app(entry: AppEntry):
|
|||||||
|
|
||||||
return {"status": "added"}
|
return {"status": "added"}
|
||||||
|
|
||||||
|
@app.get("/icon/{filename}")
|
||||||
|
def get_presigned_icon_url(filename: str):
|
||||||
|
try:
|
||||||
|
url = minio_client.presigned_get_object(
|
||||||
|
bucket_name=BUCKET,
|
||||||
|
object_name=filename,
|
||||||
|
expires=timedelta(hours=1)
|
||||||
|
)
|
||||||
|
return {"url": url}
|
||||||
|
except Exception as e:
|
||||||
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|||||||
@ -1,10 +1,21 @@
|
|||||||
import '../style/AppCard.css';
|
import { useEffect, useState } from 'react';
|
||||||
|
import { getIconUrl } from '../services/api';
|
||||||
|
|
||||||
function AppCard({ app }) {
|
function AppCard({ app }) {
|
||||||
|
const [iconUrl, setIconUrl] = useState('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (app.icon) {
|
||||||
|
getIconUrl(app.icon)
|
||||||
|
.then(setIconUrl)
|
||||||
|
.catch(() => setIconUrl('fallback-icon.svg'));
|
||||||
|
}
|
||||||
|
}, [app.icon]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a href={app.url} className="app-card" target="_blank" rel="noreferrer">
|
<a href={app.url} className="app-card" target="_blank" rel="noreferrer">
|
||||||
<div className="app-icon-wrapper">
|
<div className="app-icon-wrapper">
|
||||||
<img src={app.icon} alt={app.name} className="app-icon" />
|
<img src={iconUrl} alt={app.name} className="app-icon" />
|
||||||
</div>
|
</div>
|
||||||
<h3>{app.name}</h3>
|
<h3>{app.name}</h3>
|
||||||
<p>{app.description}</p>
|
<p>{app.description}</p>
|
||||||
|
|||||||
@ -13,3 +13,10 @@ export async function addAppToSection({ section, app }) {
|
|||||||
if (!res.ok) throw new Error(await res.text());
|
if (!res.ok) throw new Error(await res.text());
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getIconUrl(filename) {
|
||||||
|
const res = await fetch(`/icon/${filename}`);
|
||||||
|
if (!res.ok) throw new Error(`Failed to fetch icon for ${filename}`);
|
||||||
|
const data = await res.json();
|
||||||
|
return data.url;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user