fixed expenses workflow
This commit is contained in:
parent
a173fab15f
commit
09c6d33dec
2 changed files with 27 additions and 21 deletions
|
|
@ -327,9 +327,7 @@ class SharepointService:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def uploadFile(self, siteId: str, folderPath: str, fileName: str, content: bytes) -> Dict[str, Any]:
|
async def uploadFile(self, siteId: str, folderPath: str, fileName: str, content: bytes) -> Dict[str, Any]:
|
||||||
"""Upload a file to SharePoint."""
|
"""Upload a file to SharePoint. Raises on failure."""
|
||||||
try:
|
|
||||||
# Clean the path
|
|
||||||
cleanPath = folderPath.lstrip('/')
|
cleanPath = folderPath.lstrip('/')
|
||||||
uploadPath = f"{cleanPath.rstrip('/')}/{fileName}"
|
uploadPath = f"{cleanPath.rstrip('/')}/{fileName}"
|
||||||
endpoint = f"sites/{siteId}/drive/root:/{uploadPath}:/content"
|
endpoint = f"sites/{siteId}/drive/root:/{uploadPath}:/content"
|
||||||
|
|
@ -339,16 +337,11 @@ class SharepointService:
|
||||||
result = await self._makeGraphApiCall(endpoint, method="PUT", data=content)
|
result = await self._makeGraphApiCall(endpoint, method="PUT", data=content)
|
||||||
|
|
||||||
if "error" in result:
|
if "error" in result:
|
||||||
logger.error(f"Upload failed: {result['error']}")
|
raise Exception(f"Upload failed: {result['error']}")
|
||||||
return result
|
|
||||||
|
|
||||||
logger.info(f"File uploaded successfully: {fileName}")
|
logger.info(f"File uploaded successfully: {fileName}")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error uploading file: {str(e)}")
|
|
||||||
return {"error": f"Error uploading file: {str(e)}"}
|
|
||||||
|
|
||||||
async def downloadFile(self, siteId: str, fileId: str) -> Optional[bytes]:
|
async def downloadFile(self, siteId: str, fileId: str) -> Optional[bytes]:
|
||||||
"""Download a file from SharePoint."""
|
"""Download a file from SharePoint."""
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -247,16 +247,29 @@ def _resolveDocumentList(documentListParam, services) -> List[tuple]:
|
||||||
if isinstance(first, dict) and ("documentData" in first or "documentName" in first):
|
if isinstance(first, dict) and ("documentData" in first or "documentName" in first):
|
||||||
for doc in documentListParam:
|
for doc in documentListParam:
|
||||||
rawData = doc.get("documentData")
|
rawData = doc.get("documentData")
|
||||||
logger.debug("_resolveDocumentList: doc keys=%s documentData type=%s documentData truthy=%s", list(doc.keys()), type(rawData).__name__, bool(rawData))
|
fileId = (doc.get("validationMetadata") or {}).get("fileId") or doc.get("fileId", "")
|
||||||
|
fileName = doc.get("documentName") or doc.get("fileName") or "document"
|
||||||
|
mimeType = doc.get("mimeType") or doc.get("documentMimeType") or "application/json"
|
||||||
|
|
||||||
|
# When documentData was persisted as binary (_hasBinaryData), read it
|
||||||
|
# back from file storage via the chat service.
|
||||||
|
if not rawData and doc.get("_hasBinaryData") and fileId:
|
||||||
|
chatService = getattr(services, "chat", None)
|
||||||
|
if chatService:
|
||||||
|
try:
|
||||||
|
rawBytes = chatService.getFileData(fileId)
|
||||||
|
if rawBytes:
|
||||||
|
rawData = rawBytes.decode("utf-8") if isinstance(rawBytes, bytes) else rawBytes
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug("_resolveDocumentList: failed to read binary for fileId=%s: %s", fileId, e)
|
||||||
|
|
||||||
|
logger.debug("_resolveDocumentList: doc keys=%s documentData type=%s documentData truthy=%s", list(doc.keys()), type(rawData).__name__ if rawData else "NoneType", bool(rawData))
|
||||||
if not rawData:
|
if not rawData:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
data = json.loads(rawData) if isinstance(rawData, str) else rawData
|
data = json.loads(rawData) if isinstance(rawData, str) else rawData
|
||||||
except (json.JSONDecodeError, TypeError):
|
except (json.JSONDecodeError, TypeError):
|
||||||
continue
|
continue
|
||||||
fileId = (doc.get("validationMetadata") or {}).get("fileId") or doc.get("fileId", "")
|
|
||||||
fileName = doc.get("documentName") or doc.get("fileName") or "document"
|
|
||||||
mimeType = doc.get("mimeType") or doc.get("documentMimeType") or "application/json"
|
|
||||||
results.append((data, fileId, fileName, mimeType))
|
results.append((data, fileId, fileName, mimeType))
|
||||||
if results:
|
if results:
|
||||||
return results
|
return results
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue