Compare commits
No commits in common. "396060041fa2c93f6344361361e6eafd0ca1fa70" and "eb875186576285cf122eeda4840865a6b50bf692" have entirely different histories.
396060041f
...
eb87518657
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,5 +8,3 @@ wheels/
|
||||
|
||||
# Virtual environments
|
||||
.venv
|
||||
|
||||
.nanocoder
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
cursor: pointer;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
background: #1a1a1a;
|
||||
}
|
||||
.chevron {
|
||||
position: absolute;
|
||||
|
||||
39
main.py
39
main.py
@ -6,35 +6,16 @@ import random
|
||||
import secrets
|
||||
import string
|
||||
import zipfile
|
||||
from base64 import b64encode
|
||||
from glob import glob
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, HTTPException, Depends
|
||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse, StreamingResponse
|
||||
|
||||
|
||||
AUTH_SCHEME = HTTPBasic()
|
||||
expected_password: str | None = None
|
||||
|
||||
|
||||
async def get_current_username(credentials: HTTPBasicCredentials = Depends(AUTH_SCHEME)) -> str:
|
||||
"""Verify Basic Authentication credentials"""
|
||||
if expected_password is not None and credentials.password != expected_password:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="Incorrect password",
|
||||
headers={"WWW-Authenticate": AUTH_SCHEME.getobfuscation_header()},
|
||||
)
|
||||
return credentials.username
|
||||
|
||||
|
||||
def set_auth_password(password: str | None):
|
||||
"""Set the expected password for authentication"""
|
||||
global expected_password
|
||||
expected_password = password
|
||||
app = FastAPI()
|
||||
file_mapping = {}
|
||||
indexers = []
|
||||
|
||||
|
||||
class FileIndexer:
|
||||
@ -147,7 +128,7 @@ async def health_check():
|
||||
|
||||
|
||||
@app.get("/api/{file_hash}/data")
|
||||
async def get_file_data(file_hash: str, username: str = Depends(get_current_username)):
|
||||
async def get_file_data(file_hash: str):
|
||||
"""Serve a specific file by its hash"""
|
||||
if file_hash not in file_mapping:
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
@ -171,14 +152,14 @@ async def get_file_data(file_hash: str, username: str = Depends(get_current_user
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def root(username: str = Depends(get_current_username)):
|
||||
async def root():
|
||||
"""Redirect to a random file hash"""
|
||||
random_hash = _get_random_hash()
|
||||
return RedirectResponse(url="/{hash}".format(hash=random_hash))
|
||||
|
||||
|
||||
@app.get("/{order}/{delay}")
|
||||
async def order_delay(order: str, delay: int, username: str = Depends(get_current_username)):
|
||||
async def order_delay(order: str, delay: int):
|
||||
"""Redirect to random file with order and delay"""
|
||||
random_hash = _get_random_hash()
|
||||
return RedirectResponse(
|
||||
@ -228,7 +209,7 @@ def _render_page(
|
||||
|
||||
|
||||
@app.get("/{file_hash}")
|
||||
async def hash_page(file_hash: str, username: str = Depends(get_current_username)):
|
||||
async def hash_page(file_hash: str):
|
||||
"""Serve a page for a specific file hash with navigation"""
|
||||
if file_hash not in file_mapping:
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
@ -241,7 +222,7 @@ async def hash_page(file_hash: str, username: str = Depends(get_current_username
|
||||
|
||||
|
||||
@app.get("/{order}/{delay}/{file_hash}")
|
||||
async def hash_page_with_refresh(order: str, delay: int, file_hash: str, username: str = Depends(get_current_username)):
|
||||
async def hash_page_with_refresh(order: str, delay: int, file_hash: str):
|
||||
"""Serve a page for a specific file hash with auto-refresh navigation"""
|
||||
if file_hash not in file_mapping:
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
@ -297,11 +278,9 @@ if __name__ == "__main__":
|
||||
parser.add_argument("--host", type=str, default="0.0.0.0", help="Host to bind to")
|
||||
parser.add_argument("--port", type=int, default=8000, help="Port to bind to")
|
||||
parser.add_argument("--salt", type=str, default=None, help="Salt for hashing file paths")
|
||||
parser.add_argument("--password", type=str, default=None, help="Password for Basic Authentication")
|
||||
args = parser.parse_args()
|
||||
|
||||
initialize_server(args)
|
||||
set_auth_password(args.password)
|
||||
|
||||
import uvicorn
|
||||
|
||||
|
||||
25
opencode.json
Normal file
25
opencode.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
|
||||
"provider": {
|
||||
"ollama": {
|
||||
"npm": "@ai-sdk/openai-compatible",
|
||||
"name": "Local Llama-server",
|
||||
"options": {
|
||||
"baseURL": "http://llamaserver:8080/v1"
|
||||
},
|
||||
"models": {
|
||||
"Qwen3.5-35B-A3B": {
|
||||
"name": "Qwen3.5 35B-A3B"
|
||||
}
|
||||
}
|
||||
},
|
||||
"aws": {
|
||||
"options": {
|
||||
"accessKeyId": "{env:AWS_ACCESS_KEY_ID}",
|
||||
"secretAccessKey": "{env:AWS_SECRET_ACCESS_KEY}",
|
||||
"region": "us-east-1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user