o
    ooj&                     @  sT   d dl mZ d dlZd dlmZ dZdZdd	d
ZdddZdddZ	dddZ
dS )    )annotationsN)Path)idsourceurltextkind)headingstatutebodypayloaddictreturnc                   sT   g }| d D ]  fddt D }| fddtD  || q| d |dS )zFDrop the training-time vectors: the browser recomputes them from text.chunksc                      i | ]}| v r| | qS  r   .0keychunkr   ,/root/openrights-assistant/openrights/web.py
<dictcomp>       z#payload_for_web.<locals>.<dictcomp>c                   r   r   r   r   r   r   r   r      r   idf)r   r   )WEB_KEYSupdateWEB_OPTIONAL_KEYSappend)r   r   itemr   r   r   payload_for_web   s   r    rootr   c                 C  s*   | d }|  stdt|jddS )Nzdata/processed/index.jsonz1Index not found. Run: python -m openrights ingestutf-8encoding)exists
SystemExitjsonloads	read_text)r!   
index_pathr   r   r   load_index_payload   s   r+   strc                 C  s   t jt| dd}d| dS )a7  A script assignment, not JSON.

    A WebView opened at file:///android_asset/ cannot fetch() a sibling file:
    that request is a cross-origin request to the opaque file origin and is
    blocked. A <script> tag has no such restriction, so the offline archive is
    shipped as an assignment to a global.
    ),:)
separatorszwindow.OPENRIGHTS_INDEX=z;
)r'   dumpsr    )r   datar   r   r   index_script   s   r2   tuple[int, int]c                 C  sh   t | }| d }|jjddd t|}|j|dd | d }| r'|  t|d t|dfS )Nzapp/data/index.jsT)parentsexist_okr"   r#   zapp/data/index.jsonr   )	r+   parentmkdirr2   
write_textr%   unlinklenencode)r!   r   targetscriptstaler   r   r   
export_web(   s   r?   )r   r   r   r   )r!   r   r   r   )r   r   r   r,   )r!   r   r   r3   )
__future__r   r'   pathlibr   r   r   r    r+   r2   r?   r   r   r   r   <module>   s    



