Skip to content

Commit

Permalink
feat: formatted using black & prettier (in frontend) and moved to crlf
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushSehrawat committed Dec 17, 2023
1 parent ffec1c4 commit 453d391
Show file tree
Hide file tree
Showing 35 changed files with 2,425 additions and 2,349 deletions.
44 changes: 22 additions & 22 deletions backend/controllers/default.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from fastapi import APIRouter, Request
from utils.settings import settings_manager
import requests
from program.debrid.realdebrid import get_user


router = APIRouter(
responses={404: {"description": "Not found"}},
)


@router.get("/")
async def root(request: Request):
return {
"success": True,
"message": "Iceburg is running!",
}


@router.get("/user")
async def get_rd_user():
return get_user()
from fastapi import APIRouter, Request
from utils.settings import settings_manager
import requests
from program.debrid.realdebrid import get_user


router = APIRouter(
responses={404: {"description": "Not found"}},
)


@router.get("/")
async def root(request: Request):
return {
"success": True,
"message": "Iceburg is running!",
}


@router.get("/user")
async def get_rd_user():
return get_user()
91 changes: 46 additions & 45 deletions backend/controllers/items.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
from fastapi import APIRouter, HTTPException, Request
from program.media import MediaItemState
from utils.logger import logger


router = APIRouter(
prefix="/items",
tags=["items"],
responses={404: {"description": "Not found"}},
)

@router.get("/states")
async def get_states(request: Request):
return {
"success": True,
"states": [state.name for state in MediaItemState],
}


@router.get("/")
async def get_items(request: Request):
return {
"success": True,
"items": [item.to_dict() for item in request.app.program.media_items.items],
}


@router.get("/{state}")
async def get_item(request: Request, state: str):
state = MediaItemState[state]
items = request.app.program.media_items.get_items_with_state(state).items

return {
"success": True,
"items": [item.to_dict() for item in items],
}


@router.delete("/remove/{item}")
async def remove_item(request: Request, item: str):
request.app.program.media_items.remove(item)
return {
"success": True,
"message": f"Removed {item}",
}
from fastapi import APIRouter, HTTPException, Request
from program.media import MediaItemState
from utils.logger import logger


router = APIRouter(
prefix="/items",
tags=["items"],
responses={404: {"description": "Not found"}},
)


@router.get("/states")
async def get_states(request: Request):
return {
"success": True,
"states": [state.name for state in MediaItemState],
}


@router.get("/")
async def get_items(request: Request):
return {
"success": True,
"items": [item.to_dict() for item in request.app.program.media_items.items],
}


@router.get("/{state}")
async def get_item(request: Request, state: str):
state = MediaItemState[state]
items = request.app.program.media_items.get_items_with_state(state).items

return {
"success": True,
"items": [item.to_dict() for item in items],
}


@router.delete("/remove/{item}")
async def remove_item(request: Request, item: str):
request.app.program.media_items.remove(item)
return {
"success": True,
"message": f"Removed {item}",
}
108 changes: 54 additions & 54 deletions backend/controllers/settings.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
from copy import copy
from fastapi import APIRouter
from utils.settings import settings_manager
from pydantic import BaseModel


class SetSettings(BaseModel):
key: str
value: str


router = APIRouter(
prefix="/settings",
tags=["settings"],
responses={404: {"description": "Not found"}},
)


@router.get("/load")
async def load_settings():
settings_manager.load()
return {
"success": True,
"message": "Settings loaded!",
}


@router.post("/save")
async def save_settings():
settings_manager.save()
return {
"success": True,
"message": "Settings saved!",
}


@router.get("/get/{key}")
async def get_settings(key: str):
return {
"success": True,
"data": settings_manager.get(key),
}


@router.post("/set")
async def set_settings(settings: SetSettings):
settings_manager.set(
settings.key,
settings.value,
)
return {
"success": True,
"message": "Settings saved!",
}
from copy import copy
from fastapi import APIRouter
from utils.settings import settings_manager
from pydantic import BaseModel


class SetSettings(BaseModel):
key: str
value: str


router = APIRouter(
prefix="/settings",
tags=["settings"],
responses={404: {"description": "Not found"}},
)


@router.get("/load")
async def load_settings():
settings_manager.load()
return {
"success": True,
"message": "Settings loaded!",
}


@router.post("/save")
async def save_settings():
settings_manager.save()
return {
"success": True,
"message": "Settings saved!",
}


@router.get("/get/{key}")
async def get_settings(key: str):
return {
"success": True,
"data": settings_manager.get(key),
}


@router.post("/set")
async def set_settings(settings: SetSettings):
settings_manager.set(
settings.key,
settings.value,
)
return {
"success": True,
"message": "Settings saved!",
}
86 changes: 44 additions & 42 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
import sys
import os
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from program.program import Program
from utils.thread import ThreadRunner
from controllers.settings import router as settings_router
from controllers.items import router as items_router
from controllers.default import router as default_router


sys.path.append(os.getcwd())
program = Program()
runner = ThreadRunner(program.run, 5)

def lifespan(app: FastAPI):
runner.start()
yield
runner.stop()

app = FastAPI(lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.program = program

app.include_router(default_router)
app.include_router(settings_router)
app.include_router(items_router)

if __name__ == "__main__":
try:
uvicorn.run("main:app", host="0.0.0.0", port=8080, reload=False)
except KeyboardInterrupt:
print("Exiting...")
sys.exit(0)
import sys
import os
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from program.program import Program
from utils.thread import ThreadRunner
from controllers.settings import router as settings_router
from controllers.items import router as items_router
from controllers.default import router as default_router


sys.path.append(os.getcwd())
program = Program()
runner = ThreadRunner(program.run, 5)


def lifespan(app: FastAPI):
runner.start()
yield
runner.stop()


app = FastAPI(lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.program = program

app.include_router(default_router)
app.include_router(settings_router)
app.include_router(items_router)

if __name__ == "__main__":
try:
uvicorn.run("main:app", host="0.0.0.0", port=8080, reload=False)
except KeyboardInterrupt:
print("Exiting...")
sys.exit(0)
Loading

0 comments on commit 453d391

Please sign in to comment.