server/posts: use SHA1 checksums

This changes the checksums to ones that are compatible with 1.x, which
relieves the migration script from recalculating the checksums for all
the posts.
This commit is contained in:
rr- 2016-08-20 13:04:49 +02:00
parent 9014baab92
commit 28bcbd33b9
3 changed files with 11 additions and 3 deletions
server/szurubooru

@ -263,7 +263,7 @@ def update_post_content(post, content):
raise InvalidPostContentError(
'Unhandled file type: %r' % post.mime_type)
post.checksum = util.get_md5(content)
post.checksum = util.get_sha1(content)
other_post = db.session \
.query(db.Post) \
.filter(db.Post.checksum == post.checksum) \

@ -73,6 +73,14 @@ def get_md5(source):
return md5.hexdigest()
def get_sha1(source):
if not isinstance(source, bytes):
source = source.encode('utf-8')
sha1 = hashlib.sha1()
sha1.update(source)
return sha1.hexdigest()
def flip(source):
return {v: k for k, v in source.items()}

@ -288,8 +288,8 @@ def test_update_post_content(
expected_mime_type,
expected_type,
output_file_name):
with patch('szurubooru.func.util.get_md5'):
util.get_md5.return_value = 'crc'
with patch('szurubooru.func.util.get_sha1'):
util.get_sha1.return_value = 'crc'
config_injector({
'data_dir': str(tmpdir.mkdir('data')),
'thumbnails': {