##// END OF EJS Templates
Attach synced file as link if it exceeds local filesize limit
bodqhrohro -
r2142:ee12465d default
parent child Browse files
Show More
@@ -6,6 +6,7 b' from boards.models import KeyPair, Globa'
6 from boards.models.attachment.downloaders import download
6 from boards.models.attachment.downloaders import download
7 from boards.utils import get_file_mimetype, get_file_hash
7 from boards.utils import get_file_mimetype, get_file_hash
8 from django.db import transaction
8 from django.db import transaction
9 from django import forms
9
10
10 EXCEPTION_NODE = 'Sync node returned an error: {}.'
11 EXCEPTION_NODE = 'Sync node returned an error: {}.'
11 EXCEPTION_DOWNLOAD = 'File was not downloaded.'
12 EXCEPTION_DOWNLOAD = 'File was not downloaded.'
@@ -236,15 +237,20 b' class SyncManager:'
236 tag_ref = tag_refs.find("{}[@ref='{}']".format(
237 tag_ref = tag_refs.find("{}[@ref='{}']".format(
237 TAG_ATTACHMENT_REF, attachment.text))
238 TAG_ATTACHMENT_REF, attachment.text))
238 url = tag_ref.get(ATTR_URL)
239 url = tag_ref.get(ATTR_URL)
239 attached_file = download(hostname + url)
240 try:
240 if attached_file is None:
241 attached_file = download(hostname + url)
241 raise SyncException(EXCEPTION_DOWNLOAD)
242
243 if attached_file is None:
244 raise SyncException(EXCEPTION_DOWNLOAD)
242
245
243 hash = get_file_hash(attached_file)
246 hash = get_file_hash(attached_file)
244 if hash != attachment.text:
247 if hash != attachment.text:
245 raise SyncException(EXCEPTION_HASH)
248 raise SyncException(EXCEPTION_HASH)
246
249
247 files.append(attached_file)
250 files.append(attached_file)
251 except forms.ValidationError:
252 urls.append(hostname+url)
253
248
254
249 if is_old:
255 if is_old:
250 post = global_id.post
256 post = global_id.post
General Comments 0
You need to be logged in to leave comments. Login now