def dl_for_articles(items: List[Any]) -> Dict[str, Any]: """Gets the download links for an article.""" dl_pref = request.cookies.get('xxx-ps-defaults') return { item['article'].arxiv_id_v: metadata.get_dissemination_formats(item['article'], dl_pref) for item in items }
def get_abs_page(arxiv_id: str) -> Response: """Get abs page data from the document metadata service. Parameters ---------- arxiv_id : str The arXiv identifier as provided in the request. download_format_pref: str Download format preference. Returns ------- dict Search result response data. int HTTP status code. dict Headers to add to the response. Raises ------ :class:`.InternalServerError` Raised when there was an unexpected problem executing the query. """ response_data: Dict[str, Any] = {} response_headers: Dict[str, Any] = {} try: arxiv_id = _check_legacy_id_params(arxiv_id) arxiv_identifier = Identifier(arxiv_id=arxiv_id) redirect = check_supplied_identifier(arxiv_identifier, 'browse.abstract') if redirect: return redirect abs_meta = metadata.get_abs(arxiv_id) response_data['requested_id'] = arxiv_identifier.idv \ if arxiv_identifier.has_version else arxiv_identifier.id response_data['abs_meta'] = abs_meta response_data['meta_tags'] = meta_tag_metadata(abs_meta) response_data['author_links'] = \ split_long_author_list(queries_for_authors( abs_meta.authors.raw), truncate_author_list_size) response_data['url_for_author_search'] = \ lambda author_query: url_for('search_archive', searchtype='author', archive=abs_meta.primary_archive.id, query=author_query) # Dissemination formats for download links download_format_pref = request.cookies.get('xxx-ps-defaults') add_sciencewise_ping = _check_sciencewise_ping(abs_meta.arxiv_id_v) response_data['formats'] = metadata.get_dissemination_formats( abs_meta, download_format_pref, add_sciencewise_ping) # Following are less critical and template must display without them # try: _non_critical_abs_data(abs_meta, arxiv_identifier, response_data) # except Exception: # logger.warning("Error getting non-critical abs page data", # exc_info=app.debug) except AbsNotFoundException: if arxiv_identifier.is_old_id and arxiv_identifier.archive \ in taxonomy.definitions.ARCHIVES: archive_name = taxonomy.definitions.ARCHIVES[ arxiv_identifier.archive]['name'] raise AbsNotFound( data={ 'reason': 'old_id_not_found', 'arxiv_id': arxiv_id, 'archive_id': arxiv_identifier.archive, 'archive_name': archive_name }) raise AbsNotFound(data={'reason': 'not_found', 'arxiv_id': arxiv_id}) except AbsVersionNotFoundException: raise AbsNotFound( data={ 'reason': 'version_not_found', 'arxiv_id': arxiv_identifier.idv, 'arxiv_id_latest': arxiv_identifier.id }) except AbsDeletedException as e: raise AbsNotFound( data={ 'reason': 'deleted', 'arxiv_id_latest': arxiv_identifier.id, 'message': e }) except IdentifierIsArchiveException as e: raise AbsNotFound(data={ 'reason': 'is_archive', 'arxiv_id': arxiv_id, 'archive_name': e }) except IdentifierException: raise AbsNotFound(data={'arxiv_id': arxiv_id}) except AbsException as e: raise InternalServerError( 'There was a problem. If this problem persists, please contact ' '[email protected].') from e response_status = status.HTTP_200_OK not_modified = _check_request_headers(abs_meta, response_data, response_headers) if not_modified: return {}, status.HTTP_304_NOT_MODIFIED, response_headers return response_data, response_status, response_headers