support multiple instances of same document, extend url from api url
This commit is contained in:
parent
41bb911859
commit
db3c235e15
1 changed files with 32 additions and 18 deletions
|
@ -812,23 +812,33 @@ class Client(object):
|
||||||
if f['id'] not in available and f['extension'] in DOCUMENT_FORMATS]
|
if f['id'] not in available and f['extension'] in DOCUMENT_FORMATS]
|
||||||
return missing
|
return missing
|
||||||
|
|
||||||
|
def find_document(self, oshash):
|
||||||
|
r = self.api.findDocuments({
|
||||||
|
'keys': ['id'],
|
||||||
|
'query': {
|
||||||
|
'conditions': [
|
||||||
|
{'key': 'oshash', 'value': oshash, 'operator': '=='}
|
||||||
|
],
|
||||||
|
'operator': '&'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if r['data']['items']:
|
||||||
|
return r['data']['items'][0]['id']
|
||||||
|
return None
|
||||||
|
|
||||||
def _add_document(self, f, item=None):
|
def _add_document(self, f, item=None):
|
||||||
if f.split('.')[-1] not in DOCUMENT_FORMATS:
|
if f.split('.')[-1] not in DOCUMENT_FORMATS:
|
||||||
return False
|
return False
|
||||||
url = '%supload/document/' % self._config['url']
|
oshash = ox.oshash(f)
|
||||||
r = self.api.upload_chunks(url, f, {
|
did = self.find_document(oshash)
|
||||||
'filename': os.path.basename(f)
|
if not did:
|
||||||
})
|
url = '%supload/document/' % self._config['url']
|
||||||
if r and item:
|
r = self.api.upload_chunks(url, f, {
|
||||||
oshash = ox.oshash(f)
|
'filename': os.path.basename(f)
|
||||||
r = self.api.findDocuments({
|
|
||||||
"keys": ['id'],
|
|
||||||
"query": {
|
|
||||||
"conditions": [{"key": 'oshash', "value": oshash, "operator": '=='}],
|
|
||||||
"operator": '&'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
did = r['data']['items'][0]['id']
|
if r and item:
|
||||||
|
did = self.find_document(oshash)
|
||||||
|
if item:
|
||||||
r = self.api.addDocument({
|
r = self.api.addDocument({
|
||||||
'id': did,
|
'id': did,
|
||||||
'item': item
|
'item': item
|
||||||
|
@ -1061,12 +1071,16 @@ class API(ox.API):
|
||||||
|
|
||||||
print(filename)
|
print(filename)
|
||||||
hide_cursor()
|
hide_cursor()
|
||||||
result_url = data.get('url')
|
|
||||||
if 'uploadUrl' in data:
|
def full_url(path):
|
||||||
uploadUrl = data['uploadUrl']
|
if path.startswith('/'):
|
||||||
if uploadUrl.startswith('/'):
|
|
||||||
u = urlparse(url)
|
u = urlparse(url)
|
||||||
uploadUrl = '%s://%s%s' % (u.scheme, u.netloc, uploadUrl)
|
path = '%s://%s%s' % (u.scheme, u.netloc, path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
result_url = full_url(data.get('url'))
|
||||||
|
if 'uploadUrl' in data:
|
||||||
|
uploadUrl = full_url(data['uploadUrl'])
|
||||||
f = open(filename, 'rb')
|
f = open(filename, 'rb')
|
||||||
fsize = os.stat(filename).st_size
|
fsize = os.stat(filename).st_size
|
||||||
done = 0
|
done = 0
|
||||||
|
|
Loading…
Reference in a new issue