mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-15 02:43:17 +02:00
Initial commit
This commit is contained in:
commit
8aa223bc7b
40 files changed
+4320
No files matched your search
@@ -0,0 +1,44 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
TextFileTypes = {"markdown", "text", "config", "html"}
|
||||
|
||||
MimeTypeMap = {
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".gif": "image/gif",
|
||||
".webp": "image/webp",
|
||||
".svg": "image/svg+xml",
|
||||
".mp4": "video/mp4",
|
||||
".webm": "video/webm",
|
||||
".mov": "video/quicktime",
|
||||
".mkv": "video/x-matroska",
|
||||
}
|
||||
|
||||
|
||||
def ReadTextFile(FilePath: Path) -> str:
|
||||
"""Read a text-classified file as UTF-8."""
|
||||
return FilePath.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def GetFileSize(FilePath: Path) -> int:
|
||||
return FilePath.stat().st_size
|
||||
|
||||
|
||||
def GetMimeType(FilePath: Path) -> str:
|
||||
return MimeTypeMap.get(FilePath.suffix.lower(), "application/octet-stream")
|
||||
|
||||
|
||||
def ParseRangeHeader(RangeHeader: str, FileSize: int) -> tuple[int, int]:
|
||||
"""Parse a single-range HTTP Range header into an inclusive (Start, End)."""
|
||||
RangeValue = RangeHeader.replace("bytes=", "").strip()
|
||||
StartText, _, EndText = RangeValue.partition("-")
|
||||
|
||||
Start = int(StartText) if StartText else 0
|
||||
End = int(EndText) if EndText else FileSize - 1
|
||||
End = min(End, FileSize - 1)
|
||||
|
||||
return Start, End
|
||||
Reference in new issue
Block a user