mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-15 02:43:17 +02:00
Added guests.
This commit is contained in:
1 parent
6743dd7626
commit
9736a55e00
10 files changed
+200
-84
No files matched your search
+27
-13
@@ -13,7 +13,14 @@ from fastapi import Depends, FastAPI, File, HTTPException, Request, Response, Up
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse, HTMLResponse, PlainTextResponse, StreamingResponse
|
||||
|
||||
from Auth import CreateSession, DeleteSession, GetCurrentUser, RequireAdmin, SessionCookieName
|
||||
from Auth import (
|
||||
CreateSession,
|
||||
DeleteSession,
|
||||
GetCurrentUser,
|
||||
GetCurrentUserOrGuest,
|
||||
RequireAdmin,
|
||||
SessionCookieName,
|
||||
)
|
||||
from BookReader import ReadBookForFile
|
||||
from Blame import LoadBlame, RenameUserInBlame, UpdateBlameOnSave
|
||||
from Core import ResolvePath
|
||||
@@ -31,6 +38,7 @@ from Explorer import (
|
||||
from Groups import (
|
||||
CreateGroup,
|
||||
DeleteGroup,
|
||||
GuestGroupName,
|
||||
ListGroups,
|
||||
RenameUserInGroups,
|
||||
SetGroupMembers,
|
||||
@@ -46,6 +54,7 @@ from Locks import (
|
||||
from Portals import ResolvePortals
|
||||
from Preview import GetMimeType, ReadTextFile, StreamBinaryFile, TextFileTypes
|
||||
from Settings import (
|
||||
DefaultSettings,
|
||||
DeleteTheme,
|
||||
ListThemeNames,
|
||||
LoadSettings,
|
||||
@@ -196,7 +205,7 @@ async def PostProfileAvatarEndpoint(
|
||||
|
||||
|
||||
@Application.get("/api/profile/avatar")
|
||||
def GetProfileAvatarEndpoint(Username: str, CurrentUser: dict = Depends(GetCurrentUser)):
|
||||
def GetProfileAvatarEndpoint(Username: str, CurrentUser: dict = Depends(GetCurrentUserOrGuest)):
|
||||
AvatarPath = GetAvatarPath(Username)
|
||||
|
||||
if AvatarPath is None:
|
||||
@@ -347,18 +356,20 @@ def GetLocksEndpoint(CurrentUser: dict = Depends(RequireAdmin)) -> list[dict]:
|
||||
|
||||
|
||||
@Application.get("/api/roots")
|
||||
def GetRootsEndpoint(CurrentUser: dict = Depends(GetCurrentUser)) -> list[dict]:
|
||||
def GetRootsEndpoint(CurrentUser: dict = Depends(GetCurrentUserOrGuest)) -> list[dict]:
|
||||
return ListRoots()
|
||||
|
||||
|
||||
@Application.get("/api/tree")
|
||||
def GetTreeEndpoint(
|
||||
Root: str, Path: str = "", CurrentUser: dict = Depends(GetCurrentUser)
|
||||
Root: str, Path: str = "", CurrentUser: dict = Depends(GetCurrentUserOrGuest)
|
||||
) -> list[dict]:
|
||||
RequirePathAccessible(Root, Path, CurrentUser)
|
||||
|
||||
try:
|
||||
UserSettings = LoadSettings(CurrentUser["Username"])
|
||||
UserSettings = (
|
||||
DefaultSettings if CurrentUser["Username"] is None else LoadSettings(CurrentUser["Username"])
|
||||
)
|
||||
ShowHidden = UserSettings.get("ShowHiddenFolders", False)
|
||||
ShowSvFiles = UserSettings.get("ShowSvFiles", False)
|
||||
Entries = ListDirectory(Root, Path, ShowHidden, ShowSvFiles)
|
||||
@@ -471,7 +482,7 @@ def DeleteTreeEndpoint(Root: str, Path: str, CurrentUser: dict = Depends(GetCurr
|
||||
|
||||
@Application.get("/api/file")
|
||||
def GetFileEndpoint(
|
||||
Root: str, Path: str, request: Request, CurrentUser: dict = Depends(GetCurrentUser)
|
||||
Root: str, Path: str, request: Request, CurrentUser: dict = Depends(GetCurrentUserOrGuest)
|
||||
):
|
||||
RequirePathAccessible(Root, Path, CurrentUser)
|
||||
|
||||
@@ -493,7 +504,7 @@ def GetFileEndpoint(
|
||||
|
||||
@Application.get("/api/file/resolved")
|
||||
def GetResolvedFileEndpoint(
|
||||
Root: str, Path: str, CurrentUser: dict = Depends(GetCurrentUser)
|
||||
Root: str, Path: str, CurrentUser: dict = Depends(GetCurrentUserOrGuest)
|
||||
) -> dict:
|
||||
RequirePathAccessible(Root, Path, CurrentUser)
|
||||
|
||||
@@ -548,7 +559,7 @@ async def PutFileEndpoint(
|
||||
|
||||
|
||||
@Application.get("/api/blame")
|
||||
def GetBlameEndpoint(Root: str, Path: str, CurrentUser: dict = Depends(GetCurrentUser)) -> dict:
|
||||
def GetBlameEndpoint(Root: str, Path: str, CurrentUser: dict = Depends(GetCurrentUserOrGuest)) -> dict:
|
||||
RequirePathAccessible(Root, Path, CurrentUser)
|
||||
|
||||
try:
|
||||
@@ -588,7 +599,7 @@ def GetBlameEndpoint(Root: str, Path: str, CurrentUser: dict = Depends(GetCurren
|
||||
|
||||
@Application.get("/api/raw/{RootName}/{FilePath:path}")
|
||||
def GetRawFileEndpoint(
|
||||
RootName: str, FilePath: str, CurrentUser: dict = Depends(GetCurrentUser)
|
||||
RootName: str, FilePath: str, CurrentUser: dict = Depends(GetCurrentUserOrGuest)
|
||||
):
|
||||
RequirePathAccessible(RootName, FilePath, CurrentUser)
|
||||
|
||||
@@ -611,7 +622,7 @@ def GetRawFileEndpoint(
|
||||
|
||||
|
||||
@Application.get("/api/book")
|
||||
def GetBookEndpoint(Root: str, Path: str, CurrentUser: dict = Depends(GetCurrentUser)) -> dict:
|
||||
def GetBookEndpoint(Root: str, Path: str, CurrentUser: dict = Depends(GetCurrentUserOrGuest)) -> dict:
|
||||
RequirePathAccessible(Root, Path, CurrentUser)
|
||||
|
||||
try:
|
||||
@@ -624,7 +635,10 @@ def GetBookEndpoint(Root: str, Path: str, CurrentUser: dict = Depends(GetCurrent
|
||||
|
||||
|
||||
@Application.get("/api/settings")
|
||||
def GetSettingsEndpoint(CurrentUser: dict = Depends(GetCurrentUser)) -> dict:
|
||||
def GetSettingsEndpoint(CurrentUser: dict = Depends(GetCurrentUserOrGuest)) -> dict:
|
||||
if CurrentUser["Username"] is None:
|
||||
return dict(DefaultSettings)
|
||||
|
||||
return LoadSettings(CurrentUser["Username"])
|
||||
|
||||
|
||||
@@ -639,7 +653,7 @@ def GetThemesEndpoint(CurrentUser: dict = Depends(GetCurrentUser)) -> list[str]:
|
||||
|
||||
|
||||
@Application.get("/api/theme")
|
||||
def GetThemeEndpoint(Name: str, CurrentUser: dict = Depends(GetCurrentUser)) -> dict:
|
||||
def GetThemeEndpoint(Name: str, CurrentUser: dict = Depends(GetCurrentUserOrGuest)) -> dict:
|
||||
try:
|
||||
return LoadTheme(Name)
|
||||
except FileNotFoundError as Error:
|
||||
@@ -678,7 +692,7 @@ def DeleteThemeEndpoint(Name: str, CurrentUser: dict = Depends(GetCurrentUser))
|
||||
|
||||
@Application.get("/public/media/{RootName}/{FilePath:path}")
|
||||
def GetPublicMediaEndpoint(RootName: str, FilePath: str, request: Request):
|
||||
if not IsPathAccessible(RootName, FilePath, "", []):
|
||||
if not IsPathAccessible(RootName, FilePath, "", [GuestGroupName]):
|
||||
raise HTTPException(status_code=404, detail="Not found.")
|
||||
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user