- finished add_document on Zapier interface
This commit is contained in:
@@ -69,7 +69,7 @@ class AddDocument(Resource):
|
||||
@document_ns.response(500, 'Internal Server Error')
|
||||
def post(self):
|
||||
"""
|
||||
Add a new document
|
||||
Add a new document by providing the content of a file (Multipart/form-data).
|
||||
"""
|
||||
tenant_id = get_jwt_identity()
|
||||
current_app.logger.info(f'Adding document for tenant {tenant_id}')
|
||||
@@ -120,7 +120,7 @@ class AddDocument(Resource):
|
||||
add_document_through_url = document_ns.model('AddDocumentThroughURL', {
|
||||
'catalog_id': fields.Integer(required=True, description='ID of the catalog the URL needs to be added to'),
|
||||
'temp_url': fields.String(required=True, description='Temporary URL of the document to add'),
|
||||
'name': fields.String(required=False, description='Name of the document'),
|
||||
'name': fields.String(required=True, description='Name of the document'),
|
||||
'language': fields.String(required=True, description='Language of the document'),
|
||||
'user_context': fields.String(required=False, description='User context for the document'),
|
||||
'valid_from': fields.String(required=False, description='Valid from date for the document'),
|
||||
@@ -163,18 +163,26 @@ class AddDocumentThroughURL(Resource):
|
||||
current_app.logger.error(f"Exception type: {type(e)}")
|
||||
raise
|
||||
|
||||
file_url = args['temp_url']
|
||||
current_app.logger.info(f"Downloading file from URL: {file_url}")
|
||||
try:
|
||||
response = requests.get(file_url, stream=True)
|
||||
# Step 1: Download from stashed URL
|
||||
stashed_url = args['temp_url']
|
||||
current_app.logger.info(f"Downloading stashed file from URL: {stashed_url}")
|
||||
response = requests.get(stashed_url, stream=True)
|
||||
response.raise_for_status()
|
||||
|
||||
hydration_url = response.text.strip()
|
||||
current_app.logger.info(f"Downloading actual file from URL: {hydration_url}")
|
||||
# Step 2: Download from hydration URL
|
||||
actual_file_response = requests.get(hydration_url, stream=True)
|
||||
actual_file_response.raise_for_status()
|
||||
hydrated_file_content = actual_file_response.content
|
||||
|
||||
# Get filename from URL or use provided name
|
||||
filename = secure_filename(args.get('name') or file_url.split('/')[-1])
|
||||
filename = secure_filename(args.get('name'))
|
||||
extension = filename.rsplit('.', 1)[1].lower() if '.' in filename else ''
|
||||
|
||||
# Create FileStorage object from downloaded content
|
||||
file_content = io.BytesIO(response.content)
|
||||
file_content = io.BytesIO(hydrated_file_content)
|
||||
file = FileStorage(
|
||||
stream=file_content,
|
||||
filename=filename,
|
||||
@@ -249,7 +257,8 @@ class AddURL(Resource):
|
||||
@document_ns.response(500, 'Internal Server Error')
|
||||
def post(self):
|
||||
"""
|
||||
Add a new document from URL
|
||||
Add a new document from URL. The URL in this case is stored and can be used to refresh the document.
|
||||
As a consequence, this must be a permanent and accessible URL.
|
||||
"""
|
||||
tenant_id = get_jwt_identity()
|
||||
current_app.logger.info(f'Adding document from URL for tenant {tenant_id}')
|
||||
@@ -328,7 +337,7 @@ class DocumentResource(Resource):
|
||||
@document_ns.response(404, 'Document not found')
|
||||
@document_ns.response(500, 'Internal Server Error')
|
||||
def put(self, document_id):
|
||||
"""Edit a document"""
|
||||
"""Edit a document. The content of the document will not be refreshed!"""
|
||||
try:
|
||||
current_app.logger.debug(f'Editing document {document_id}')
|
||||
data = request.json
|
||||
@@ -347,7 +356,8 @@ class DocumentResource(Resource):
|
||||
@document_ns.doc('refresh_document')
|
||||
@document_ns.response(200, 'Document refreshed successfully')
|
||||
def post(self, document_id):
|
||||
"""Refresh a document"""
|
||||
"""Refresh a document. In this case, the content of the document will be refreshed! This requires the document
|
||||
version to have a permanent and accessible URL!"""
|
||||
tenant_id = get_jwt_identity()
|
||||
new_version, result = refresh_document(document_id, tenant_id)
|
||||
if new_version:
|
||||
@@ -398,7 +408,8 @@ class RefreshDocument(Resource):
|
||||
@document_ns.response(404, 'Document not found')
|
||||
def post(self, document_id):
|
||||
"""
|
||||
Refresh a document without additional information
|
||||
Refresh a document without additional information. In this case, the content of the document will be refreshed!
|
||||
This requires the document version to have a permanent and accessible URL!
|
||||
"""
|
||||
tenant_id = get_jwt_identity()
|
||||
current_app.logger.info(f'Refreshing document {document_id} for tenant {tenant_id}')
|
||||
@@ -431,7 +442,7 @@ class RefreshDocumentWithInfo(Resource):
|
||||
@document_ns.response(404, 'Document not found')
|
||||
def post(self, document_id):
|
||||
"""
|
||||
Refresh a document with new information
|
||||
Refresh a document with new version information.
|
||||
"""
|
||||
tenant_id = get_jwt_identity()
|
||||
current_app.logger.info(f'Refreshing document {document_id} with info for tenant {tenant_id}')
|
||||
|
||||
@@ -35,7 +35,7 @@ module.exports = {
|
||||
label: 'Document Name',
|
||||
type: 'string',
|
||||
helpText: 'The name you want to give the Document.',
|
||||
required: false,
|
||||
required: true,
|
||||
list: false,
|
||||
altersDynamicFields: false,
|
||||
},
|
||||
@@ -136,16 +136,16 @@ module.exports = {
|
||||
Object.assign(baseMetadata, bundle.inputData.additional_metadata);
|
||||
}
|
||||
|
||||
// Get the file content
|
||||
const filePromise = z.stashFile(bundle.inputData.file);
|
||||
const file = await filePromise;
|
||||
// const temp_url = z.stashFile(bundle.inputData.file);
|
||||
// Get the file URL from Zapier
|
||||
const tempFileUrl = await z.stashFile(bundle.inputData.file);
|
||||
// Log the temporary URL for debugging
|
||||
z.console.log('Temporary URL created:', tempFileUrl);
|
||||
|
||||
// Create request data as an object
|
||||
const requestData = {
|
||||
catalog_id: bundle.inputData.catalog_id,
|
||||
language: bundle.inputData.language,
|
||||
temp_url: file, // This will be handled by z.request automatically
|
||||
temp_url: tempFileUrl,
|
||||
user_metadata: JSON.stringify(baseMetadata),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user