Пример #1
0
async def create_response(entry_data, preview=False):
	if entry_data:
		entry_id = entry_data['_id']
		title = entry_data['title']
		content = entry_data.get('content', '[no content]')
		unlisted = entry_data.get('unlisted', False)
		image = entry_data.get('image')
		markdown = entry_data.get('markdown')
		no_html = entry_data.get('nohtml_content')
		content = await utils.before_show_text(content)
		markdown = utils.html_to_markdown(content)
		owner_id = entry_data.get('owner_id')
	else:
		return web.HTTPNotFound()

	url_title = utils.url_title(title)

	if preview:
		return {'title': title, 'preview': utils.remove_html(content), 'html': content, 'id': entry_id, 'image': image}
	else:
		return {
			'slug': url_title,
			'id': entry_id,
			'title': title,
			'html': content,
			'unlisted': unlisted,
			'image': image,
			'markdown': markdown,
			'no_html': no_html,
			'owner_id': owner_id,
		}
Пример #2
0
async def edit_entry(
	title, content, editor=None, unlisted=False, entry_id=None, image=None, editor_real=None, impersonate=None
):
	t = datetime.now()
	title = title.strip()
	await discordbot.log_edit(editor, title, t)
	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}
	
	new_data['edited_by_minx'] = editor == 359017688867012628
	
	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
Пример #3
0
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:
		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
Пример #4
0
async def edit_entry(
	title: str,
	content: str,
	editor_id: int,
	unlisted: bool = False,
	entry_id: str = None,
	image: str = None
):
	t = datetime.now()
	title = title.strip()
	await discordbot.log_edit(editor_id, title)
	content = utils.fix_html(content)
	nohtml_content = utils.remove_html(content)
	new_data: PartialDatabaseEntry = {
		'title': title,
		'content': content,
		'last_edited': t,
		'nohtml_content': nohtml_content,
		'unlisted': unlisted or False
	}
	if image is not None:
		new_data['image'] = await images.get_data(image)

	if not entry_id:
		entry_id = str(uuid.uuid4())
	new_history_data: DatabaseHistoryItem = {
		'author': editor_id,
		'content': content,
		'title': title,
		'time': t,
		'unlisted': unlisted,
		'image': None
	}
	if image is not None:
		new_history_data['image'] = {
			'src': image,
			'thumbnail_b64': None,
			'thumbnail_content_type': None
		}

	await entries_coll.update_one({'_id': entry_id}, {'$set': new_data, '$push': {'history': new_history_data}}, upsert=True)
	return entry_id