25 lines
814 B
Python
25 lines
814 B
Python
from pathlib import PurePosixPath
|
|
|
|
from src.schemas.messages import PDFWorkerCommand, PDFWorkerResult
|
|
|
|
|
|
def relative_path(value: str) -> str:
|
|
value = value.replace("\\", "/")
|
|
if (not value or value.startswith("/") or
|
|
any(part in ("", ".", "..") for part in value.split("/")) or
|
|
any(char in value for char in ':*?"<>|\x00')):
|
|
raise ValueError("Expected a relative SMB path without traversal or wildcards")
|
|
if any(part.endswith((".", " ")) for part in value.split("/")):
|
|
raise ValueError("Trailing dots/spaces are not allowed")
|
|
return value
|
|
|
|
|
|
class PrepareTask(PDFWorkerCommand):
|
|
@property
|
|
def smb_input_name(self) -> str:
|
|
return f"{self.task_id}{PurePosixPath(self.source_s3_key).suffix.lower()}"
|
|
|
|
|
|
class TaskResult(PDFWorkerResult):
|
|
pass
|