import _get from 'lodash/get' ; import _isString from 'lodash/isString' ; import { getDefaultImage } from './assets' ; import type { MsgStyleType } from './types/chat' ; import url from 'url' ; import { generateShorterUrl } from './utils/url-helper' ; const environment = process . env . NODE_ENV || 'development' ; const platform = process . env . PLATFORM || 'web' ; let currentHost = '127.0.0.1' ; let isSSL = false ; const localHost = _get ( window , 'location.host' ) ; if ( localHost ) { currentHost = localHost . split ( ':' ) [ 0 ] ; isSSL = _get ( window , 'location.protocol' ) === 'https:' ; } if ( environment === 'production' ) { currentHost = 'trpgapi.moonrailgun.com' ; if ( platform === 'app' ) { isSSL = true ; } } else if ( environment === 'development' ) { isSSL = false ; } const trpgHost = process . env . TRPG_HOST ; let trpgPort ; if ( trpgHost ) { const _tmp = trpgHost . split ( ':' ) ; currentHost = _tmp [ 0 ] ; trpgPort = _tmp [ 1 ] ; } if ( trpgPort ! === '443' ) { isSSL = true ; } /**
 * portal 服务的地址
 */ const portalUrl = process . env . TRPG_PORTAL || 'https://trpg.moonrailgun.com/portal' ; const standardPort = isSSL ? '443' : '80' ; let apiPort = environment === 'production' ? standardPort : '23256' ; if ( _isString ( trpgPort ! ) ) { apiPort = trpgPort ! ; } const rtc = process . env . RTC_HOST || 'wss://rtc.moonrailgun.com:4443' ; interface ProjectConfig { version : string ; environment : string ; platform : string ; isSSL : boolean ; devSW : boolean ; io : { protocol : 'wss' | 'ws' ; host : string ; port : string ; } ; chat : { maxLength : number ; isWriting : { throttle : number ; timeout : number ; } ; } ; file : { protocol : 'https' | 'http' ; host : string ; port : string ; url ? : string ; getFileImage : ( ext : string ) => string ; getAbsolutePath ? : ( path ? : string ) => string ; getRelativePath ? : ( path : string ) => string ; getUploadsImagePath ? : ( filename : string , isTemporary : boolean ) => string ; } ; defaultImg : { user : string ; getUser : ( name : string ) => string ; group : string ; getGroup : ( name : string ) => string ; trpgsystem : string ; robot : string ; actor : string ; chatimg_fail : string ; file : { default : string ; pdf : string ; excel : string ; ppt : string ; word : string ; txt : string ; pic : string ; } ; color : string [ ] ; } ; github : { projectUrl : string ; projectPackageUrl : string ; projectAppPackageUrl : string ; } ; url : { api ? : string ; rtc : string ; homepage : string ; docs : string ; goddessfantasy : string ; loginUrl : string ; blog : string ; versionBlog : string ; portal : string ; rsshub : string ; getInviteUrl : ( inviteCode : string ) => string ; rssNews : { name : string ; url : string ; } [ ] ; txcUrl : string ; } ; defaultSettings : DefaultSettings ; } /**
 * 默认设置
 */ const defaultSettings = { user : { favoriteDice : [ ] as { title : string ; value : string ; } [ ] , msgStyleType : 'bubble' as MsgStyleType , msgStyleCombine : false , /**
         * 聊天输入框上下键快速切换历史消息
         */ msgInputHistorySwitch : true , } , system : { /**
         * 是否进行通知
         */ notification : true , /**
         * 不发送消息输入状态
         */ disableSendWritingState : false , /**
         * 在输入状态中显示自己
         */ showSelfInWritingState : false , /**
         * 聊天框类型 有auto, compatible
         */ chatBoxType : 'auto' as 'auto' | 'compatible' , /**
         * 音频设置
         */ audioConstraints : { /**
             * 噪音抑制
             */ noiseSuppression : false , /**
             * 自动增益
             */ autoGainControl : false , /**
             * 回声消除
             */ echoCancellation : false , } , } , } ; const rsshub = 'https://rss.moonrailgun.com/' ; /**
 * 用于portal的新闻功能
 */ const rssNews = [ { name : '贴吧' , url : url . resolve ( rsshub , '/tieba/forum/跑团?code=42bacec52565b92308da5f98ec1509c9' ) , } , ] ; export type DefaultSettings = typeof defaultSettings ; const file = { protocol : isSSL ? 'https' : 'http' , host : currentHost , port : apiPort , getFileImage ( ext ) { if ( ext === 'jpg' || ext === 'png' || ext === 'gif' ) { return config . defaultImg . file . pic ; } if ( ext === 'doc' || ext === 'docx' ) { return config . defaultImg . file . word ; } if ( ext === 'xls' || ext === 'xlsx' ) { return config . defaultImg . file . excel ; } if ( ext === 'ppt' || ext === 'pptx' ) { return config . defaultImg . file . ppt ; } if ( ext === 'pdf' ) { return config . defaultImg . file . pdf ; } if ( ext === 'txt' ) { return config . defaultImg . file . txt ; } return config . defaultImg . file . default ; } , } ; file . url = generateShorterUrl ( file ) ; file . getAbsolutePath = function getAbsolutePath ( path ? ) { if ( ! path ) { path = '' ; } if ( path && path [ 0 ] === '/' ) { return file . url + path ; } return path ; } ; file . getRelativePath = function getAbsolutePath ( path ) { if ( ! path ) { path = '' ; } return path . replace ( file . url ! , '' ) ; } ; file . getUploadsImagePath = function getUploadsImagePath ( filename , isTemporary = false ) { let relativePath = '' ; if ( isTemporary ) { relativePath = `/uploads/temporary/${ filename }` ; } else { relativePath = `/uploads/persistence/${ filename }` ; } return file . url + relativePath ; } ; const config = { version : require ( '../../package.json' ) . version , environment , platform , isSSL , devSW : process . env . DEV_SW === 'true' || false , io : { protocol : isSSL ? 'wss' : 'ws' , host : currentHost , port : apiPort , } , chat : { maxLength : 800 , isWriting : { throttle : 800 , timeout : 5000 , } , } , file , defaultImg : { ... getDefaultImage ( { fileUrl : file . url , } ) , color : [ '#333333' , '#2c3e50' , '#8e44ad' , '#2980b9' , '#27ae60' , '#16a085' , '#f39c12' , '#d35400' , '#c0392b' , '#3498db' , '#9b59b6' , '#2ecc71' , '#1abc9c' , '#f1c40f' , '#e74c3c' , '#e67e22' , ] , } , github : { projectUrl : 'https://github.com/TRPGEngine/Client' , projectPackageUrl : 'https://raw.githubusercontent.com/TRPGEngine/Client/master/package.json' , projectAppPackageUrl : 'https://raw.githubusercontent.com/TRPGEngine/Client/master/src/app/package.json' , } , url : { rtc , homepage : 'https://trpgdoc.moonrailgun.com/' , docs : 'https://trpgdoc.moonrailgun.com/' , goddessfantasy : 'http://www.goddessfantasy.net/' , loginUrl : environment === 'production' ? 'https://trpgdoc.moonrailgun.com/features' : '' , blog : 'https://trpgdoc.moonrailgun.com/blog/' , versionBlog : 'https://trpgdoc.moonrailgun.com/blog/tags/%E7%89%88%E6%9C%AC%E5%8F%91%E5%B8%83' , portal : portalUrl , rsshub , getInviteUrl ( inviteCode ) { return `${ portalUrl }/group/invite/${ inviteCode }` ; } , /**
         *
         */ rssNews , txcUrl : 'https://support.qq.com/products/308023' , } , defaultSettings , } ; config . url . api = config . file . url ; export default config ;