
    ZjE                        d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ  e	d      Zedz  dfed	z  d	fd
Zd Z G d de      Zedk(  r: e j"                  e        ee ee            Z ede      j)                          yy)    N)
formatdate)partial)SimpleHTTPRequestHandlerThreadingHTTPServer)Path)urlsplitz+/home/ubuntu/cobbleverse/resource-pack-hostzKern-Launcher-Setup-1.0.3.exez(Grand-Mage-Duel-Launcher-Setup-1.0.1.exe)z/download/kerncobblez/download/duelmagicc                 R    t        |       j                  j                  d      xs dS )N/)r   pathrstrip)raw_paths    E/home/ubuntu/cobbleverse/resource-pack-host/download_server.py.uploadnormalize_download_pathr      s#    H""))#.5#5    c                   2     e Zd ZdZ fdZ fdZd Z xZS )DownloadHandlerzHTTP/1.1c                     t         j                  t        | j                              }|r | j                  |ddi y t
        |           y )N	send_bodyF)	DOWNLOADSgetr   r   _send_downloadsuperdo_HEADselfdownload	__class__s     r   r   zDownloadHandler.do_HEAD   s@    ==!8!CDD;U;r   c                     t         j                  t        | j                              }|r | j                  |ddi y t
        |           y )Nr   T)r   r   r   r   r   r   do_GETr   s     r   r   zDownloadHandler.do_GET&   s@    ==!8!CDD:T:r   c           	         	 |j                         }d}|j                  dz
  }d}| j                  j                  d      }|r|j                  d      r	 |j                  d      j                  dd      d   }	|	j                  d	d      \  }
}|
rt        |
      }|rt        |      n|}n$t        |      }t        d|j                  |z
        }t        ||j                  dz
        }|dk  s||kD  rt        d
}||z
  dz   }| j                  |       | j                  dd       | j                  dd| d       | j                  dt!        |             | j                  dt#        |j$                  d             | j                  dd       |d
k(  r%| j                  dd| d	| d|j                          | j                          |sy 	 |j'                  d      5 }|j)                  |       |}|rJ|j+                  t        d|            }|sn,| j,                  j/                  |       |t1        |      z  }|rJd d d        y # t        $ r | j                  dd       Y y w xY w# t        $ rC | j                  d       | j                  dd|j                          | j                          Y y w xY w# 1 sw Y   y xY w# t2        t4        f$ r Y y w xY w)Ni  zLauncher installer not foundr         Rangezbytes=,-   i  zContent-Rangezbytes */zContent-Typez-application/vnd.microsoft.portable-executablezContent-Dispositionzattachment; filename=""zContent-LengthzLast-ModifiedT)usegmtzAccept-Rangesbyteszbytes r
   rbi   )statFileNotFoundError
send_errorst_sizeheadersr   
startswithremoveprefixsplitintmaxmin
ValueErrorsend_responsesend_headerend_headersstrr   st_mtimeopenseekreadwfilewritelenBrokenPipeErrorConnectionResetError)r   download_filedownload_namer   r+   startendstatusrange_header	requestedfirstlastsuffix_lengthlengthsource	remainingchunks                    r   r   zDownloadHandler._send_download-   s   	 %%'D
 llQ||''0L33H=(55h?EEc1MaP	'ooc15tJE'+#d)C$'IM4<<-#?@E#t||a/019$$ uq6")XY.2HWX0YZ)3v;7*T]]4*PQ'2S=_ugQse1T\\N.ST	##D) ,VE""	"KKK(CDE JJ$$U+U+I  , ,Y ! 	OOC!?@	.  ""3'  HT\\N2KL  "	*, ,  !56 		sV   I B%I' K AJ6=K I$#I$'A	J32J36J?;K ?K KK)__name__
__module____qualname__protocol_versionr   r   r   __classcell__)r   s   @r   r   r      s    !9r   r   __main__)	directory)z0.0.0.0ic  )osemail.utilsr   	functoolsr   http.serverr   r   pathlibr   urllib.parser   ROOTr   r   r   rR   chdirr:   handlerserve_forever r   r   <module>rd      s    
 "  E  ! 9: 	..'
 	992		6J. JZ zBHHTNoT;G*G4BBD r   