mirror of
https://git.srhtnin.garden/sarah/SaraView.git
synced 2026-10-14 02:38:11 +02:00
Add file upload and download (zip for directories)
This commit is contained in:
1 parent
0d564982dc
commit
da4e02472f
7 files changed
+383
-42
No files matched your search
@@ -124,6 +124,28 @@ def MoveEntry(RootName: str, SourceRelativePath: str, DestinationRelativePath: s
|
||||
RenameDirectoryNote(DestinationPath, OldName)
|
||||
|
||||
|
||||
def SaveUploadedFile(
|
||||
RootName: str, DirectoryRelativePath: str, FileName: str, FileBytes: bytes
|
||||
) -> str:
|
||||
DirectoryPath = ResolvePath(RootName, DirectoryRelativePath)
|
||||
|
||||
if not DirectoryPath.is_dir():
|
||||
raise NotADirectoryError(f"{DirectoryPath} is not a directory.")
|
||||
|
||||
SafeName = Path(FileName).name
|
||||
|
||||
if not SafeName or SafeName in (".", ".."):
|
||||
raise ValueError("Invalid file name.")
|
||||
|
||||
TargetPath = DirectoryPath / SafeName
|
||||
|
||||
if TargetPath.exists():
|
||||
raise FileExistsError(f"{SafeName} already exists.")
|
||||
|
||||
TargetPath.write_bytes(FileBytes)
|
||||
return SafeName
|
||||
|
||||
|
||||
def DeleteEntry(RootName: str, RelativePath: str) -> None:
|
||||
EntryPath = ResolvePath(RootName, RelativePath)
|
||||
|
||||
|
||||
Reference in new issue
Block a user