This commit is contained in:
parent
82189e1bc5
commit
d65da600e5
1 changed files with 7 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Any, Literal, Union
|
from typing import Any, Literal, Union
|
||||||
|
|
||||||
|
|
@ -38,7 +39,12 @@ class FileService:
|
||||||
source_url: str = "",
|
source_url: str = "",
|
||||||
) -> UploadFile:
|
) -> UploadFile:
|
||||||
# get file extension
|
# get file extension
|
||||||
extension = filename.split(".")[-1].lower()
|
extension = os.path.splitext(filename)[1].lstrip(".").lower()
|
||||||
|
|
||||||
|
# check if filename contains invalid characters
|
||||||
|
if any(c in filename for c in ["/", "\\", ":", "*", "?", '"', "<", ">", "|"]):
|
||||||
|
raise ValueError("Filename contains invalid characters")
|
||||||
|
|
||||||
if len(filename) > 200:
|
if len(filename) > 200:
|
||||||
filename = filename.split(".")[0][:200] + "." + extension
|
filename = filename.split(".")[0][:200] + "." + extension
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue