import { getHash } from "../redis/redis" ; import { logSocket } from "../sockets/socket" ; import { _pushError } from "../app" ; const cryPto = require ( 'crypto' ) ; desc edu const _encryptedPWD = ( password ) : string => { return cryPto . createHmac ( 'sha1' , password ) . update ( 'edu' ) . digest ( 'hex' ) ; } ; desc param password const _md5 = ( password ) : string => { return cryPto . createHash ( 'md5' ) . update ( password ) . digest ( 'hex' ) ; } ; desc eg const _sid_obj = ( str_sid ) => { const [ channel , sid ] = ( str_sid || '' ) . trim ( ) . split ( '#' ) ; return { channel , sid } ; } ; desc const _authSuccess = ( ) => { return Buffer . from ( `
                      <html lang="zh">
                        <head>
                            <meta charset="UTF-8">
                            <title>恭喜，你已授权成功！Github OAuth to 2019-nCoV Success!</title>
                            <style>
                                .auth{
                                    margin: 200px auto 0 ;
                                    width: 460px;
                                    height: 300px;
                                }
                                a{
                                    font-weight: 500;
                                }
                                a:visited{
                                    color: #0366d6;
                                }
                            </style>
                        </head>
                        <body>
                            <div class="main-auth">
                                <div class="auth">
                                    <h2>授权成功，有问题联系 <a href="http://github.com/veaba/ncov/">社区项目</h2>
                                    
                                    <p>此窗口即将关闭</p>
                                </div>
                            </div>
                            <script>
                                setTimeout(()=>{
                                    window.close();
                                },3000)
                            </script>
                        </body>
                       </html>
        ` ) ; } ; desc const _authFail = ( ) => { return Buffer . from ( `
          <html lang="zh">
            <head>
                <meta charset="UTF-8">
                <title>授权失败！Github OAuth to 2019-nCoV Fail!</title>
                <style>
                    .auth{
                        margin: 200px auto 0 ;
                        width: 460px;
                        height: 300px;
                    }
                    a{
                        font-weight: 500;
                    }
                    a:visited{
                        color: #0366d6;
                    }
                </style>
            </head>
            <body>
                <div class="main-auth">
                    <div class="auth">
                        <h2>授权失败,请联系 <a href="http://github.com/veaba/ncov/">社区项目</h2>
                    </div>
                </div>
            </body>
           </html>
        ` ) ; } ; desc todo const _authUser = async ( socket , sid , data , channel , eventName , logType ) => { if ( ! await getHash ( sid ) ) { await logSocket ( socket , data , channel , eventName , logType ) ; return await _pushError ( channel , eventName , data , '非法用户，即将断开连接' ) ; } } ; export { _encryptedPWD , _md5 , _sid_obj , _authSuccess , _authFail , _authUser } ;