import crypto from 'crypto' ; import { URLSearchParams } from 'url' ; function export function _getDS ( this , { query , body } ) { switch ( this . serverType ) { case 'os' : return getOsDS ( '6s25p5ox5y14umn1p61aqyyvbvvl3lrt' ) ; case 'cn' : default : return getCnDS ( { query , body } ) ; } } function randomString ( e ) { const s = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ; const res = [ ] ; for ( let i = 0 ; i < e ; ++ i ) { res . push ( s [ Math . floor ( Math . random ( ) * s . length ) ] ) ; } return res . join ( '' ) ; } function sortKeys ( obj ) { const copy = { } as Record < string , any > ; const allKeys = Object . keys ( obj ) . sort ( ) ; allKeys . forEach ( ( key ) => { copy [ key ] = obj [ key ] ; } ) ; return copy ; } function getOsDS ( salt ) { const time = Math . floor ( Date . now ( ) / 1000 ) ; const random = randomString ( 6 ) ; const c = crypto . createHash ( 'md5' ) . update ( `salt=${ salt }&t=${ time }&r=${ random }` ) . digest ( 'hex' ) ; return `${ time },${ random },${ c }` ; } function getCnDS ( { query , body , } ) { const salt = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs' ; const time = Math . floor ( Date . now ( ) / 1000 ) ; const random = Math . floor ( Math . random ( ) * ( 200000 - 100000 + 1 ) ) + 100000 ; const b = body ? JSON . stringify ( sortKeys ( body ) ) : '' ; const q = query ? new URLSearchParams ( sortKeys ( query ) ) : '' ; const check = crypto . createHash ( 'md5' ) . update ( `salt=${ salt }&t=${ time }&r=${ random }&b=${ b }&q=${ q }` ) . digest ( 'hex' ) ; const dynamic = `${ time },${ random },${ check }` ; return dynamic ; }