Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Fix: multi image preview sign (#5376)

fishisnowe785cbb81d8c
diff --git a/api/models/dataset.py b/api/models/dataset.py
index 9f8b15be1a4..09e18ab53a2 100644
--- a/api/models/dataset.py
+++ b/api/models/dataset.py
@@ -425,9 +425,9 @@ class DocumentSegment(db.Model):
def get_sign_content(self):
pattern = r"/files/([a-f0-9\-]+)/image-preview"
text = self.content
- match = re.search(pattern, text)
-
- if match:
+ matches = re.finditer(pattern, text)
+ signed_urls = []
+ for match in matches:
upload_file_id = match.group(1)
nonce = os.urandom(16).hex()
timestamp = str(int(time.time()))
@@ -437,8 +437,15 @@ class DocumentSegment(db.Model):
encoded_sign = base64.urlsafe_b64encode(sign).decode()
params = f"timestamp={timestamp}&nonce={nonce}&sign={encoded_sign}"
- replacement = r"\g<0>?{params}".format(params=params)
- text = re.sub(pattern, replacement, text)
+ signed_url = f"{match.group(0)}?{params}"
+ signed_urls.append((match.start(), match.end(), signed_url))
+
+ # Reconstruct the text with signed URLs
+ offset = 0
+ for start, end, signed_url in signed_urls:
+ text = text[:start + offset] + signed_url + text[end + offset:]
+ offset += len(signed_url) - (end - start)
+
return text