async def fix_entry(data): if data is None: return original_data = dict(data) if data.get('image') and isinstance(data['image'], str): data['image'] = data['image'].replace('imag.cf', 'i.matdoes.dev') if data.get('image') and isinstance(data.get('image'), str): data['image'] = await images.get_data(data['image']) elif data.get('image') and not data['image'].get('thumbnail_b64'): data['image'] = await images.get_data(data['image']['src']) if data != original_data: # print('updated', data['_id']) await entries_coll.update_one({'_id': data['_id']}, {'$set': data}) data['content'] = utils.fix_html(data['content']) if 'nohtml_content' not in data: data['nohtml_content'] = utils.remove_html(data['content']) return data
async def edit_entry(title, content, editor=None, unlisted=False, entry_id=None, image=None): t = datetime.now() title = title.strip() content = utils.fix_html(content) nohtml_content = utils.remove_html(content) new_data = { 'title': title, 'content': content, 'last_edited': t, 'nohtml_content': nohtml_content } if unlisted is not None: new_data['unlisted'] = unlisted if image is not None: new_data['image'] = { 'src': image } if not entry_id: entry_id = str(uuid.uuid4()) new_history_data = { 'author': editor, 'content': content, 'title': title, 'time': t, 'unlisted': unlisted, } if image is not None: new_history_data['image'] = { 'src': image } await entries_coll.update_one( {'_id': entry_id}, { '$set': new_data, '$push': { 'history': new_history_data } }, upsert=True ) return entry_id