def get(service: str, artist_id: str): # cursor = get_cursor() base = request.args.to_dict() base.pop('o', None) base["service"] = service base["artist_id"] = artist_id offset = parse_int(request.args.get('o'), 0) query = request.args.get('q') limit = limit_int(int(request.args.get('limit') or 25), 50) favorited = False account = load_account() if account is not None: favorited = is_artist_favorited(account['id'], service, artist_id) (posts, total_count) = ([], 0) if not query or len(query) < 3: (posts, total_count) = get_artist_post_page(artist_id, service, offset, limit) else: (posts, total_count) = do_artist_post_search(artist_id, service, query, offset, limit) artist = get_artist(service, artist_id) if artist is None: return redirect(url_for('artists.list')) display_data = make_artist_display_data(artist) dm_count = count_user_dms(service, artist_id) (result_previews, result_attachments, result_flagged, result_after_kitsune, result_is_image) = get_render_data_for_posts(posts) props = ArtistPageProps(id=artist_id, service=service, session=session, name=artist['name'], count=total_count, limit=limit, favorited=favorited, artist=artist, display_data=display_data, dm_count=dm_count) response = make_response( render_template('user.html', props=props, base=base, results=posts, result_previews=result_previews, result_attachments=result_attachments, result_flagged=result_flagged, result_after_kitsune=result_after_kitsune, result_is_image=result_is_image), 200) response.headers['Cache-Control'] = 's-maxage=60' return response
def get_account_details(): account: TDAccount = load_account() data = TDAccountInfo( role=account['role'] ) api_response = TDAPIResponseSuccess( is_successful=True, data=data ) response = make_response(jsonify(api_response), 200) return response
def get_account_creds(): if load_account(): return errors = ["Not Authorized"] api_response = TDAPIResponseFailure( is_successful=False, errors=errors ) response = make_response(jsonify(api_response), 401) return response
def list_account_favorites(): account = load_account() favorites = [] fave_type = get_value(request.args, 'type', 'artist') if fave_type == 'post': favorites = get_favorite_posts(account['id']) else: favorites = get_favorite_artists(account['id']) results = favorites response = make_response(jsonify(results), 200) response.headers['Cache-Control'] = 's-maxage=60' return response
def get_account_creds(): account: TDAccount = load_account() if (is_administrator(account)): return log_message = f"Account with ID of \"{account['id']}\" and role \"{account['role']}\" tried to access administrator API." logging.warn(log_message) errors = ["Not Found"] api_response = TDAPIResponseFailure(is_successful=False, errors=errors) response = make_response(jsonify(api_response), 404) return response
def do_init_stuff(): g.page_data = {} g.request_start_time = datetime.datetime.now() g.freesites = freesites g.paysite_list = paysite_list g.paysites = paysites g.paysite_options = paysite_options g.origin = getenv("KEMONO_SITE") g.canonical_url = urljoin(getenv("KEMONO_SITE"), request.path) session.permanent = True app.permanent_session_lifetime = timedelta(days=30) session.modified = False account = load_account() if account: g.account = Account.from_dict(account) g.new_notifications_count = count_new_notifications(g.account.id)
def get_register(): props = { 'currentPage': 'login', 'query_string': '' } account = load_account() if account is not None: return redirect(url_for('artists.list')) query = request.query_string.decode('utf-8') if len(query) > 0: props['query_string'] = '?' + query return make_response(render_template( 'account/register.html', props = props ), 200)
def list(): account = load_account() if account is None: flash( 'We now support accounts! Register for an account and your current favorites will automatically be added to your account.' ) return redirect(url_for('account.get_login')) props = {'currentPage': 'favorites'} base = request.args.to_dict() base.pop('o', None) favorites = [] fave_type = get_value(request.args, 'type', 'artist') if fave_type == 'post': favorites = get_favorite_posts(account['id']) sort_field = restrict_value(get_value(request.args, 'sort'), ['faved_seq', 'published'], 'faved_seq') else: favorites = get_favorite_artists(account['id']) sort_field = restrict_value(get_value(request.args, 'sort'), ['faved_seq', 'updated'], 'updated') offset = parse_int(request.args.get('o'), 0) sort_asc = True if get_value(request.args, 'order') == 'asc' else False results = sort_and_filter_favorites(favorites, offset, sort_field, sort_asc) props['fave_type'] = fave_type props['sort_field'] = sort_field props['sort_asc'] = sort_asc props['count'] = len(favorites) props['limit'] = 25 response = make_response( render_template( 'favorites.html', props=props, base=base, source='account', results=results, ), 200) response.headers['Cache-Control'] = 's-maxage=60' return response
def post_login(): account = load_account() if account is not None: return redirect(set_query_parameter(url_for('artists.list'), 'logged_in', 'yes')) query = request.query_string.decode('utf-8') if len(query) > 0: query = '?' + query username = get_value(request.form, 'username') password = get_value(request.form, 'password') success = attempt_login(username, password) if not success: return redirect(url_for('account.get_login') + query) redir = get_value(request.args, 'redir') if redir is not None: return redirect(set_query_parameter(redir, 'logged_in', 'yes')) return redirect(set_query_parameter(url_for('artists.list'), 'logged_in', 'yes'))
def get_login(): props = { 'currentPage': 'login', 'query_string': '' } account = load_account() if account is not None: return redirect(set_query_parameter(url_for('artists.list'), 'logged_in', 'yes')) query = request.query_string.decode('utf-8') if len(query) > 0: props['query_string'] = '?' + query response = make_response(render_template( 'account/login.html', props = props ), 200) response.headers['Cache-Control'] = 's-maxage=60' return response
def check_credentials(): account = load_account() if (not account or account['role'] != 'moderator'): return abort(404)
def get(service, artist_id, post_id): # cursor = get_cursor() props = { 'currentPage': 'posts', 'service': service if service else 'patreon' } post = get_post(post_id, artist_id, service) if post is None: response = redirect( url_for('artists.get', service=service, artist_id=artist_id)) return response comments = get_post_comments(post_id, service) favorited = False account = load_account() if account is not None: favorited = is_post_favorited(account['id'], service, artist_id, post_id) artist = get_artist(service, artist_id) previews = [] attachments = [] if len(post['file']): if re.search("\.(gif|jpe?g|jpe|png|webp)$", post['file']['path'], re.IGNORECASE): # noqa w605 previews.append({ 'type': 'thumbnail', 'name': post['file'].get('name'), 'path': post['file']['path'].replace('https://kemono.party', '') }) else: attachments.append({ 'path': post['file']['path'].replace('https://kemono.party', ''), 'name': post['file'].get('name') }) if len(post['embed']): previews.append({ 'type': 'embed', 'url': post['embed']['url'], 'subject': post['embed']['subject'], 'description': post['embed']['description'] }) for attachment in post['attachments']: if re.search("\.(gif|jpe?g|jpe|png|webp)$", attachment['path'], re.IGNORECASE): # noqa w605 previews.append({ 'type': 'thumbnail', 'name': attachment['name'], 'path': attachment['path'].replace('https://kemono.party', '') }) else: file_extension = PurePath(attachment['path']).suffix # filename without extension stem = PurePath(attachment['path']).stem attachments.append({ 'path': attachment['path'], 'name': attachment.get('name'), 'extension': file_extension, 'stem': stem }) scrub = Cleaner(tags=[ 'a', 'abbr', 'acronym', 'b', 'blockquote', 'code', 'em', 'i', 'li', 'ol', 'strong', 'ul', 'img', 'br', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div', 'span', 'ul', 'ol', 'li' ], attributes={ 'a': ['href', 'title'], 'abbr': ['title'], 'acronym': ['title'], 'img': ['src'] }, strip=True) post['content'] = scrub.clean(post['content']) props['artist'] = artist props['flagged'] = is_post_flagged(service, artist_id, post_id) props['favorited'] = favorited props['after_kitsune'] = post['added'] > datetime.datetime( 2020, 12, 22, 0, 0, 0, 0) response = make_response( render_template( 'post.html', props=props, post=post, comments=comments, result_previews=previews, result_attachments=attachments, ), 200) response.headers['Cache-Control'] = 's-maxage=60' return response
def delete_favorite_artist(service, artist_id): account = load_account() if account is None: return redirect(url_for('account.get_login')) remove_favorite_artist(account['id'], service, artist_id) return '', 200
def post_favorite_post(service, artist_id, post_id): account = load_account() if account is None: return redirect(url_for('account.get_login')) add_favorite_post(account['id'], service, artist_id, post_id) return '', 200