Added support for downloading binary
This commit is contained in:
@@ -14,6 +14,11 @@ http://localhost:4502/crx/de/nodetypes.jsp?_dc=1549392939958
|
|||||||
http://localhost:4502/crx/server/crx.default/jcr%3aroot/libs.1.json?_dc=1549392123434&node=xnode-265
|
http://localhost:4502/crx/server/crx.default/jcr%3aroot/libs.1.json?_dc=1549392123434&node=xnode-265
|
||||||
http://localhost:4502/crx/de/query.jsp?_dc=1549392245191&_charset_=utf-8&type=xpath&stmt=%2Fjcr%3Aroot%2Fbin%2F%2F*%5Bjcr%3Acontains(.%2C%20%27asdf%27)%5D%20order%20by%20%40jcr%3Ascore&showResults=true
|
http://localhost:4502/crx/de/query.jsp?_dc=1549392245191&_charset_=utf-8&type=xpath&stmt=%2Fjcr%3Aroot%2Fbin%2F%2F*%5Bjcr%3Acontains(.%2C%20%27asdf%27)%5D%20order%20by%20%40jcr%3Ascore&showResults=true
|
||||||
http://app30-prd-asd.sbnl.vancis.nl:4502/bin/wcm/references.json?path=%2Fcontent%2Fdam%2Fbeeldbank%2F_0005_home_algemeen.png&predicate=wcmcontent&_charset_=utf-8
|
http://app30-prd-asd.sbnl.vancis.nl:4502/bin/wcm/references.json?path=%2Fcontent%2Fdam%2Fbeeldbank%2F_0005_home_algemeen.png&predicate=wcmcontent&_charset_=utf-8
|
||||||
|
|
||||||
|
Download:
|
||||||
|
http://app30-prd-asd.sbnl.vancis.nl:4502/crx/server/crx.default/jcr:root/content/dam/beeldbank/vrouw-direct-naar.jpg/jcr:content/renditions/original/jcr:content/jcr:data
|
||||||
|
OR
|
||||||
|
download.jsp?path=%2Fcontent%2Fdam%2Fbeeldbank%2Fvrouw-direct-naar.jpg%2Fjcr%3Acontent%2Frenditions%2Foriginal%2Fjcr%3Acontent%2Fjcr%3Adata&index=0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
CRX_SERVER_ROOT = '/crx/server/crx.default/jcr:root/'
|
CRX_SERVER_ROOT = '/crx/server/crx.default/jcr:root/'
|
||||||
@@ -85,6 +90,13 @@ class Connection:
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def download_binary(self, path: str) -> bytes:
|
||||||
|
# TODO verify if it is not b64 encoded. for some reason it is in FireFox
|
||||||
|
resp = self.session.get(
|
||||||
|
urljoin(self.data_root, '.' + path)
|
||||||
|
)
|
||||||
|
return resp.content
|
||||||
|
|
||||||
def get_simple_node(self, path: str) -> SimpleNode:
|
def get_simple_node(self, path: str) -> SimpleNode:
|
||||||
return SimpleNode(path, self.get_node_raw(path), self)
|
return SimpleNode(path, self.get_node_raw(path), self)
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,25 @@
|
|||||||
|
from logging import Logger
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from .connection import Connection
|
from .connection import Connection
|
||||||
|
|
||||||
|
|
||||||
|
LOGGER = Logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class SimpleNode:
|
class SimpleNode:
|
||||||
def __init__(self, path: str, data: dict, connection: 'Connection'):
|
def __init__(self, path: str, data: dict, connection: 'Connection'):
|
||||||
self.path = path
|
self.path = path
|
||||||
self._data = data
|
self._data = data
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
|
|
||||||
|
def download(self, key: str = 'jcr:data') -> bytes:
|
||||||
|
if ':' + key not in self._data:
|
||||||
|
LOGGER.warning(f"Key :{key} is not present, binary probably not available")
|
||||||
|
# TODO value of the :{key} must be an int
|
||||||
|
# TODO value denotes file size, warn/deny large files?
|
||||||
|
return self._connection.download_binary(self.path + '/' + key)
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
return getattr(self, item)
|
return getattr(self, item)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user