frontend, etc.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security
|
||||
from app.models import Genre, Song, GoogleFile
|
||||
from app.dependencies import get_token_header, dbEngine
|
||||
from app.routers.user import get_current_user, User
|
||||
from typing import Annotated
|
||||
from fastapi import APIRouter, HTTPException, Security, File, UploadFile
|
||||
from app.models import GoogleFile
|
||||
from app.dependencies import dbEngine
|
||||
from app.routers.user import get_current_user
|
||||
import gspread
|
||||
from gspread.urls import DRIVE_FILES_API_V3_URL
|
||||
import pandas as pd
|
||||
@@ -93,3 +92,8 @@ def process_worksheets():
|
||||
song_list.to_sql(name='songs', con=dbEngine,
|
||||
index=False, if_exists='append')
|
||||
# song_list.to_csv("song-list.csv")
|
||||
|
||||
|
||||
@router.post("/process_file")
|
||||
async def create_upload_file(file: UploadFile):
|
||||
return {"filename": file.filename}
|
||||
16
app/routers/songs.py
Normal file
16
app/routers/songs.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from fastapi import APIRouter, HTTPException, Security
|
||||
from app.models import Song
|
||||
from app.dependencies import dbEngine, Base, dbSession
|
||||
from app.routers.user import get_current_user, User
|
||||
from typing import Annotated
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/songs",
|
||||
#dependencies=[Security(get_current_user, scopes=["public"])],
|
||||
responses={404: {"description": "Not found"}},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/")
|
||||
async def get_songs() -> list[dict]:
|
||||
return dbSession.query(Base.songs).all()
|
||||
@@ -12,7 +12,7 @@ from app.secrets import SECRET_KEY, fake_users_db
|
||||
# openssl rand -hex 32
|
||||
|
||||
ALGORITHM = "HS256"
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 24 * 31
|
||||
|
||||
|
||||
class Token(BaseModel):
|
||||
@@ -42,7 +42,8 @@ pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
oauth2_scheme = OAuth2PasswordBearer(
|
||||
tokenUrl="user/token",
|
||||
scopes={
|
||||
"admin": "Perform admin actions."
|
||||
"admin": "Perform admin actions.",
|
||||
"public": "Perform public actions."
|
||||
}
|
||||
)
|
||||
|
||||
@@ -65,6 +66,7 @@ def get_user(db, username: str):
|
||||
return UserInDB(**user_dict)
|
||||
|
||||
|
||||
|
||||
def authenticate_user(fake_db, username: str, password: str):
|
||||
user = get_user(fake_db, username)
|
||||
if not user:
|
||||
@@ -84,7 +86,6 @@ def create_access_token(data: dict, expires_delta: timedelta | None = None):
|
||||
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
|
||||
return encoded_jwt
|
||||
|
||||
|
||||
async def get_current_user(
|
||||
security_scopes: SecurityScopes, token: Annotated[str, Depends(oauth2_scheme)]
|
||||
):
|
||||
@@ -144,3 +145,11 @@ async def login_for_access_token(
|
||||
data={"sub": user.username, "scopes": user.scopes}, expires_delta=access_token_expires
|
||||
)
|
||||
return Token(access_token=access_token, token_type="bearer")
|
||||
|
||||
# @router.get("/public_token")
|
||||
# async def get_public_access_token(secret_identity : str) -> Token:
|
||||
# access_token_expires = timedelta(minutes=60*24*365)
|
||||
# access_token = create_access_token(
|
||||
# data={"sub": "public", "secret_identity" : secret_identity, "scopes": ["public"]}, expires_delta=access_token_expires
|
||||
# )
|
||||
# return Token(access_token=access_token, token_type="bearer")
|
||||
Reference in New Issue
Block a user